qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 03/12] linux-user: Properly Handle semun Structure I


From: Tom Musta
Subject: [Qemu-devel] [PATCH 03/12] linux-user: Properly Handle semun Structure In Cross-Endian Situations
Date: Mon, 4 Aug 2014 11:45:30 -0500

The semun union used in the semctl system call contains both an int (val) and
pointers.  In cross-endian situations on 64 bit targets, the target memory
must be byte swapped, otherwise the wrong 32 bits are used for the val
field.

Signed-off-by: Tom Musta <address@hidden>

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 229c482..fb03e96 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2647,9 +2647,14 @@ static inline abi_long do_semctl(int semid, int semnum, 
int cmd,
     switch( cmd ) {
        case GETVAL:
        case SETVAL:
+#if TARGET_ABI_BITS == 64
+            /* In 64 bit cross endian situations, we will erroneously pick up
+             * the wrong half of the union for the "val" element.  To rectify
+             * this, the entire structure is byteswaped. */
+            target_su.buf = tswapal(target_su.buf);
+#endif
             arg.val = tswap32(target_su.val);
             ret = get_errno(semctl(semid, semnum, cmd, arg));
-            target_su.val = tswap32(arg.val);
             break;
        case GETALL:
        case SETALL:
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]