From patchwork Fri Aug 15 11:01:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 35436 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D7C72203C5 for ; Fri, 15 Aug 2014 11:07:23 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wn1sf14167544obc.10 for ; Fri, 15 Aug 2014 04:07:23 -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=j3BJlWYvwLPdRCnCfRVEjz/WdhZEKYW2HtDGq1VEGQU=; b=aiiXj5fmYM2pjXhNbluzvkU5FiXW+Dr5Nsqd/bNIgubxF4pe9IWoENSZmrR+no1Kx6 CSuYzzf5tZCTdTkctD5C0GTWT3DNWFf3Cgxb764X4W2KKEiHvWJ6zLr9fL0r+Jv79RSL fS1zRMn5/zr3Cu3A5ZhQJss1/XKcazjF3ob5Ha7CXk6A25GKJ0Y42watuFRclogO7XgI Pm2iPCV1LPMAidEQkFRT5F4dd8Bu4f+lVHgRpNGH+UEcu3Z8ldfPi42liPtRxVQ+MF9A JDtrXSx87VZ5SrToEnQKAEtFdWcodW8jxGtU8VYdl1111E5FS7nIJ3y0RwdEJSfA+6aM Z+ZA== X-Gm-Message-State: ALoCoQmCivhzE1HAPm1LCHVr67kzgSzfwuiwaIXxJC6z+Fm16iZpPcOWUqRMMERnSBfg3DqlNccN X-Received: by 10.182.186.4 with SMTP id fg4mr9227318obc.9.1408100843511; Fri, 15 Aug 2014 04:07:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.176 with SMTP id l45ls1321485qgd.81.gmail; Fri, 15 Aug 2014 04:07:23 -0700 (PDT) X-Received: by 10.224.38.10 with SMTP id z10mr26691690qad.52.1408100843417; Fri, 15 Aug 2014 04:07:23 -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 l34si3921546qgd.77.2014.08.15.04.07.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Aug 2014 04:07:23 -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 hq11so2799303vcb.10 for ; Fri, 15 Aug 2014 04:07:23 -0700 (PDT) X-Received: by 10.220.7.131 with SMTP id d3mr374060vcd.49.1408100843202; Fri, 15 Aug 2014 04:07:23 -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.37.5 with SMTP id tc5csp104277vcb; Fri, 15 Aug 2014 04:07:22 -0700 (PDT) X-Received: by 10.224.88.198 with SMTP id b6mr26156699qam.97.1408100842646; Fri, 15 Aug 2014 04:07:22 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o17si11363032qge.25.2014.08.15.04.07.22 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 15 Aug 2014 04:07:22 -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]:58580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIFLu-0004yc-0f for patch@linaro.org; Fri, 15 Aug 2014 07:07:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIFGc-0004x7-HC for qemu-devel@nongnu.org; Fri, 15 Aug 2014 07:02:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIFGU-00072N-R4 for qemu-devel@nongnu.org; Fri, 15 Aug 2014 07:01:54 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=44490 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIFGU-00071G-Kr for qemu-devel@nongnu.org; Fri, 15 Aug 2014 07:01:46 -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 EED782661E; Fri, 15 Aug 2014 13:01:44 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 15 Aug 2014 14:01:31 +0300 Message-Id: <05945bb57d1c51a305b40de7d68c1a6b4a00b56d.1408100160.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: Peter Maydell , Tom Musta Subject: [Qemu-devel] [PULL 13/24] 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 0113250..ba9dfc5 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: