From patchwork Fri Aug 22 13:24:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 35816 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f199.google.com (mail-yk0-f199.google.com [209.85.160.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 01CC020540 for ; Fri, 22 Aug 2014 13:37:27 +0000 (UTC) Received: by mail-yk0-f199.google.com with SMTP id 79sf34099506ykr.10 for ; Fri, 22 Aug 2014 06:37:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=Tx2yoFajP8rrW8X4+46nNUHrZCJN+6nx7QQHkKLgkRc=; b=JHYHLDRErF0q+lydttZ2zepIv9aImQDW7UbfWpkF2aTNFBRSVuQEAyzcE6gzFTkRSZ gz6YPSE5Ucdk41wwD4n26mWyBYUTYgc3R7idQmSAnTlcIBLTB4DqCNZsfVLeKCb50q9T EC6kH+KVqRv7sjac71Z1gmZRGqkSv8erYkuC3JhVNpibJ560g5t8HD6+2AfQLc9jfgQc SwpleG5ZJ3lcPP5K4bvKnd0vydvLe3czLkl8Jt+Fn1moxJB9yn7isOVtBBSxG9L9pRrS lZMYmlhUmxnXPb9PBw7NXGRo3ts2uUw6SIpbVN20DAcUXE0qa6ffFDazprj6FmrL2M3L dHJQ== X-Gm-Message-State: ALoCoQkp7gZQX07smjbx9vVDA21InIRVSBo2r+dx1lsK0i5oxXvHKTFWIdgrLvB5p1m1a5hvLB8r X-Received: by 10.236.216.67 with SMTP id f63mr3379482yhp.10.1408714647844; Fri, 22 Aug 2014 06:37:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.92.228 with SMTP id b91ls1092263qge.88.gmail; Fri, 22 Aug 2014 06:37:27 -0700 (PDT) X-Received: by 10.220.130.131 with SMTP id t3mr847392vcs.30.1408714647731; Fri, 22 Aug 2014 06:37:27 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id wz7si13569824vdc.65.2014.08.22.06.37.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Aug 2014 06:37:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id hq11so12421767vcb.10 for ; Fri, 22 Aug 2014 06:37:27 -0700 (PDT) X-Received: by 10.52.127.5 with SMTP id nc5mr93290vdb.59.1408714647663; Fri, 22 Aug 2014 06:37:27 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp17571vcb; Fri, 22 Aug 2014 06:37:27 -0700 (PDT) X-Received: by 10.224.80.10 with SMTP id r10mr8425569qak.24.1408714647015; Fri, 22 Aug 2014 06:37:27 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z4si42267502qaj.72.2014.08.22.06.37.26 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 22 Aug 2014 06:37:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:37186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKp1y-00073J-IB for patch@linaro.org; Fri, 22 Aug 2014 09:37:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKops-0006cK-Bl for qemu-devel@nongnu.org; Fri, 22 Aug 2014 09:25:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKoph-0002DK-CO for qemu-devel@nongnu.org; Fri, 22 Aug 2014 09:24:56 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=54458 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKoph-0002BA-4v for qemu-devel@nongnu.org; Fri, 22 Aug 2014 09:24:45 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id E590F26581; Fri, 22 Aug 2014 15:24:42 +0200 (CEST) From: riku.voipio@linaro.org To: Peter Maydell , qemu-devel@nongnu.org Date: Fri, 22 Aug 2014 16:24:29 +0300 Message-Id: <5464baecf521d1ca8095604f5a7371443c94226a.1408712881.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2001:4b98:dc0:45:216:3eff:fe3d:166f Cc: Tom Musta Subject: [Qemu-devel] [PULL v3 11/22] 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Tom Musta 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 value passed to semctl is an 8 byte (abi_long) value and thus does not have the 4-byte val field in the correct location. In order to rectify this, the other half of the union must be accessed. This is achieved in code by performing a byte swap on the entire 8 byte union, followed by a 4-byte swap of the first half. Also, eliminate an extraneous (dead) line of code that sets target_su.val in the IPC_SET/IPC_GET case. Signed-off-by: Tom Musta Signed-off-by: Riku Voipio --- linux-user/syscall.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 08fdd94..39ab4c7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2652,9 +2652,18 @@ static inline abi_long do_semctl(int semid, int semnum, int cmd, switch( cmd ) { case GETVAL: case SETVAL: - arg.val = tswap32(target_su.val); + /* 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 8-byte structure is byteswapped, followed by + * a swap of the 4 byte val field. In other cases, the data is + * already in proper host byte order. */ + if (sizeof(target_su.val) != (sizeof(target_su.buf))) { + target_su.buf = tswapal(target_su.buf); + arg.val = tswap32(target_su.val); + } else { + arg.val = target_su.val; + } ret = get_errno(semctl(semid, semnum, cmd, arg)); - target_su.val = tswap32(arg.val); break; case GETALL: case SETALL: