Skip to contentSkip to conversation

linux-user: correctly align target_epoll_event

PATCH Applied Laurent Vivier 2 participants 2 messages Oct 3, 2015 – Oct 6, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: correctly align target_epoll_event

According to comments in /usr/include/linux/eventpoll.h, poll_event is packed only on x86_64.

And to be sure fields are correctly aligned in epoll_data, use abi_XXX types for all of them.

Moreover, fd type is wrong: fd is int, not ulong.

This has been tested with a ppc guest on an x86_64 host:
without this patch, systemd crashes (core).

CC Alexander Graf <[email protected]>
CC Peter Maydell <[email protected]>

---
I cc' Alexander because it has added the padding and the packed attribute, Peter because it is the author of the original structure.

 linux-user/syscall_defs.h | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
linux-user/syscall_defs.h +11 -8
index 7ca33a6..f4e4122 100644
@@ -2503,20 +2503,23 @@ struct target_mq_attr {
 #define FUTEX_CMD_MASK          ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
 
 #ifdef CONFIG_EPOLL
+#if defined(TARGET_X86_64)
+#define TARGET_EPOLL_PACKED QEMU_PACKED
+#else
+#define TARGET_EPOLL_PACKED
+#endif
+
 typedef union target_epoll_data {
     abi_ulong ptr;
-    abi_ulong fd;
-    uint32_t u32;
-    uint64_t u64;
+    abi_int fd;
+    abi_uint u32;
+    abi_ullong u64;
 } target_epoll_data_t;
 
 struct target_epoll_event {
-    uint32_t events;
-#if defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_MIPS64)
-    uint32_t __pad;
-#endif
+    abi_uint events;
     target_epoll_data_t data;
-} QEMU_PACKED;
+} TARGET_EPOLL_PACKED;
 #endif
 struct target_rlimit64 {
     uint64_t rlim_cur;
Signature · 1 line
2.4.3
Applied
#1 lore raw
Quoted 10 lines · Laurent Vivier

According to comments in /usr/include/linux/eventpoll.h, poll_event is packed only on x86_64.

And to be sure fields are correctly aligned in epoll_data, use abi_XXX types for all of them.

Moreover, fd type is wrong: fd is int, not ulong.

This has been tested with a ppc guest on an x86_64 host:
without this patch, systemd crashes (core).

Applied to linux-user, thanks

Quoted 47 lines
CC Alexander Graf <[email protected]>
CC Peter Maydell <[email protected]>

---
I cc' Alexander because it has added the padding and the packed attribute, Peter because it is the author of the original structure.

 linux-user/syscall_defs.h | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
linux-user/syscall_defs.h +11 -8
index 7ca33a6..f4e4122 100644
@@ -2503,20 +2503,23 @@ struct target_mq_attr {
 #define FUTEX_CMD_MASK          ~(FUTEX_PRIVATE_FLAG | 
 FUTEX_CLOCK_REALTIME)
 
 #ifdef CONFIG_EPOLL
+#if defined(TARGET_X86_64)
+#define TARGET_EPOLL_PACKED QEMU_PACKED
+#else
+#define TARGET_EPOLL_PACKED
+#endif
+
 typedef union target_epoll_data {
     abi_ulong ptr;
-    abi_ulong fd;
-    uint32_t u32;
-    uint64_t u64;
+    abi_int fd;
+    abi_uint u32;
+    abi_ullong u64;
 } target_epoll_data_t;
 
 struct target_epoll_event {
-    uint32_t events;
-#if defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_MIPS64)
-    uint32_t __pad;
-#endif
+    abi_uint events;
     target_epoll_data_t data;
-} QEMU_PACKED;
+} TARGET_EPOLL_PACKED;
 #endif
 struct target_rlimit64 {
     uint64_t rlim_cur;