From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XELPX-0006h4-LI for qemu-devel@nongnu.org; Mon, 04 Aug 2014 12:47:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XELPO-00082L-DM for qemu-devel@nongnu.org; Mon, 04 Aug 2014 12:46:59 -0400 From: Tom Musta Date: Mon, 4 Aug 2014 11:45:30 -0500 Message-Id: <1407170739-12237-4-git-send-email-tommusta@gmail.com> In-Reply-To: <1407170739-12237-1-git-send-email-tommusta@gmail.com> References: <1407170739-12237-1-git-send-email-tommusta@gmail.com> Subject: [Qemu-devel] [PATCH 03/12] linux-user: Properly Handle semun Structure In Cross-Endian Situations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Cc: Tom Musta , riku.voipio@linaro.org, agraf@suse.de 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 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