From patchwork Mon Aug 4 16:45:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Musta X-Patchwork-Id: 376390 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0A88D140086 for ; Tue, 5 Aug 2014 02:51:05 +1000 (EST) Received: from localhost ([::1]:53616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XELTT-0005Ji-89 for incoming@patchwork.ozlabs.org; Mon, 04 Aug 2014 12:51:03 -0400 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 Received: from mail-qa0-x22e.google.com ([2607:f8b0:400d:c00::22e]:34926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XELPO-000824-9Q; Mon, 04 Aug 2014 12:46:50 -0400 Received: by mail-qa0-f46.google.com with SMTP id v10so7095607qac.33 for ; Mon, 04 Aug 2014 09:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Noel1lMDcVxcjKv1M9E4FQQv0GMsUVR9P6cYhrXJGM0=; b=guQVamV7xoZYdUhzGVPKZBbl8x1Kwdy6/CsqgXt1eKc9cjR2LM0CCw+2nEQEOnee6I IyMRUlwRh/vYAmPPoAhDy7clHR1+t46HKJiqgiq81uRDrH9/IFK4+2U0u3pB1q3/yMPj WXpKesI/JG4rewoZGM0+YAYi+PlJi8rXzDa8aBLCeBAUHF+QCKYls501xQOq+34kWHNK n7M32PkBRFGaofU1JYiPIsfQOO//yxFeHkDe3py5J1qvydVClE5MtGC0NUkfJhTjio5Y 5x6dHeQ2qzaGpRoDEzqJmSPYvvIC+Xw7gDdXNbp7Pk12lRb6KEyOJW5p11xXSgvyG28R akrg== X-Received: by 10.140.30.73 with SMTP id c67mr36049557qgc.16.1407170809659; Mon, 04 Aug 2014 09:46:49 -0700 (PDT) Received: from tmusta-sc.rchland.ibm.com (rchp4.rochester.ibm.com. [129.42.161.36]) by mx.google.com with ESMTPSA id n20sm32153844qar.38.2014.08.04.09.46.46 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 09:46:48 -0700 (PDT) From: Tom Musta To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org Date: Mon, 4 Aug 2014 11:45:30 -0500 Message-Id: <1407170739-12237-4-git-send-email-tommusta@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1407170739-12237-1-git-send-email-tommusta@gmail.com> References: <1407170739-12237-1-git-send-email-tommusta@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c00::22e Cc: Tom Musta , riku.voipio@linaro.org, agraf@suse.de Subject: [Qemu-devel] [PATCH 03/12] linux-user: Properly Handle semun Structure In Cross-Endian Situations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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: