From patchwork Fri Jul 15 15:50:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9232249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E177460868 for ; Fri, 15 Jul 2016 15:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D29BC2715B for ; Fri, 15 Jul 2016 15:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C78CC27F96; Fri, 15 Jul 2016 15:51:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4066C2715B for ; Fri, 15 Jul 2016 15:51:10 +0000 (UTC) Received: from localhost ([::1]:33333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bO5OP-0005Yg-Gu for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Jul 2016 11:51:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bO5O9-0005Wr-Ek for qemu-devel@nongnu.org; Fri, 15 Jul 2016 11:50:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bO5O7-00038w-Dl for qemu-devel@nongnu.org; Fri, 15 Jul 2016 11:50:52 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:58314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bO5O7-00038h-4c for qemu-devel@nongnu.org; Fri, 15 Jul 2016 11:50:51 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bO5O4-0000vB-9S; Fri, 15 Jul 2016 16:50:48 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 15 Jul 2016 16:50:47 +0100 Message-Id: <1468597847-20806-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] linux-user: Fix target_semid_ds structure definition X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , patches@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The target_semid_ds structure is not correct for all architectures: the padding fields should only exist for: * 32-bit ABIs * x86 It is also misnamed, since it is following the kernel semid64_ds structure (QEMU doesn't support the legacy semid_ds structure at all). Rename the struct, provide a correct generic definition and allow the oddball x86 architecture to provide its own version. This fixes broken SYSV semaphores for all our 64-bit architectures except x86 and ppc. Signed-off-by: Peter Maydell --- linux-user/syscall.c | 17 ++++++++++------- linux-user/x86_64/target_structs.h | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 33b5cb6..0e87157 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3406,27 +3406,30 @@ static struct shm_region { bool in_use; } shm_regions[N_SHM_REGIONS]; -struct target_semid_ds +#ifndef TARGET_SEMID64_DS +/* asm-generic version of this struct */ +struct target_semid64_ds { struct target_ipc_perm sem_perm; abi_ulong sem_otime; -#if !defined(TARGET_PPC64) +#if TARGET_ABI_BITS == 32 abi_ulong __unused1; #endif abi_ulong sem_ctime; -#if !defined(TARGET_PPC64) +#if TARGET_ABI_BITS == 32 abi_ulong __unused2; #endif abi_ulong sem_nsems; abi_ulong __unused3; abi_ulong __unused4; }; +#endif static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, abi_ulong target_addr) { struct target_ipc_perm *target_ip; - struct target_semid_ds *target_sd; + struct target_semid64_ds *target_sd; if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) return -TARGET_EFAULT; @@ -3454,7 +3457,7 @@ static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr, struct ipc_perm *host_ip) { struct target_ipc_perm *target_ip; - struct target_semid_ds *target_sd; + struct target_semid64_ds *target_sd; if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) return -TARGET_EFAULT; @@ -3481,7 +3484,7 @@ static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr, static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd, abi_ulong target_addr) { - struct target_semid_ds *target_sd; + struct target_semid64_ds *target_sd; if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) return -TARGET_EFAULT; @@ -3497,7 +3500,7 @@ static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd, static inline abi_long host_to_target_semid_ds(abi_ulong target_addr, struct semid_ds *host_sd) { - struct target_semid_ds *target_sd; + struct target_semid64_ds *target_sd; if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) return -TARGET_EFAULT; diff --git a/linux-user/x86_64/target_structs.h b/linux-user/x86_64/target_structs.h index 3489827..b6e82a8 100644 --- a/linux-user/x86_64/target_structs.h +++ b/linux-user/x86_64/target_structs.h @@ -55,4 +55,19 @@ struct target_shmid_ds { abi_ulong __unused5; }; +/* The x86 definition differs from the generic one in that the + * two padding fields exist whether the ABI is 32 bits or 64 bits. + */ +#define TARGET_SEMID64_DS +struct target_semid64_ds { + struct target_ipc_perm sem_perm; + abi_ulong sem_otime; + abi_ulong __unused1; + abi_ulong sem_ctime; + abi_ulong __unused2; + abi_ulong sem_nsems; + abi_ulong __unused3; + abi_ulong __unused4; +}; + #endif