From patchwork Tue Jun 2 20:41:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 39423 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E19C383F85D; Tue, 2 Jun 2020 20:50:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E19C383F85D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591131015; bh=xdRGfdziMAfTPdPfu3txBpjYTej+foZwbFjl/poHimI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=OS1jG2kTU0zMkFu8EB9oURSWS2oE06lBC55gVT9ln3s932HuKHtqYdUcQAYmVwg5V p3VhQIAMVJrj25ns34C3ulc6TwtQGoUjTjEIjiVRAVg4GTbLOdPkH1ju7nQYXAl120 P00C8yaMi5TUf2Khrh/LVQkjAQyxtzSh5A1c4yXc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by sourceware.org (Postfix) with ESMTPS id AAB90383F846 for ; Tue, 2 Jun 2020 20:50:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AAB90383F846 IronPort-SDR: mU+jnpUlTwdQgqOuyrQWOcoCnDQAVSdbIjPafwNjRrR7S7Qd0HehecEHKKPX3EYcmMm9b/m53H fHgQ67J1fTFOnPydd+TgT3sJRBgnlq5PIyq8ULesVEpYZPJbK34KKt3asl4aicyNkva22ZaO1x T9M9MVLJEXenlQqeMOW/FsMSDCdhD2K0acAUn17uI2TWFC0s5OV3HqqRYXVdArNBx/0XdWq6iC xztQ/3qWG6z+2LHHsoFKOk/xyMpttzgIJzMOuFw8j0AENInDNEGx0OvgVgDU00IIii2nBEMF2/ kqo= X-IronPort-AV: E=Sophos;i="5.73,465,1583164800"; d="scan'208";a="140480633" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jun 2020 04:49:52 +0800 IronPort-SDR: HJf7056q1wMU0aFoAvS+pHY6nr+aUjwRIi/5aSO+LsSAhH2eP/m5HW06vKOpBTL0Pzkh7PeNvV 935OZOvFG1jc1+V4C5TpHpDcnDnrZi7dY= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2020 13:38:58 -0700 IronPort-SDR: rdtRKmSGRYc/HAlHEskDbvebnz2YB7SQblTRy4fsIS+VZmeWIHWcvQufPY9cEmlS96KO11RiZG w40ekB75l3Bg== WDCIronportException: Internal Received: from cne220230.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.144]) by uls-op-cesaip01.wdc.com with ESMTP; 02 Jun 2020 13:49:50 -0700 To: libc-alpha@sourceware.org Subject: [PATCH v9 1/2] sysv: linux: Define the __semid_ds32 struct Date: Tue, 2 Jun 2020 13:41:04 -0700 Message-Id: <20200602204105.43866-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602204105.43866-1-alistair.francis@wdc.com> References: <20200602204105.43866-1-alistair.francis@wdc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-16.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alistair Francis via Libc-alpha From: Alistair Francis Reply-To: Alistair Francis Cc: stepan@golosunov.pp.ru, Alistair Francis Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Define a struct for 32-bit systems for the semctl command. --- .../unix/sysv/linux/hppa/struct__semid_ds32.h | 30 +++++++++++++++++++ .../unix/sysv/linux/mips/struct__semid_ds32.h | 28 +++++++++++++++++ .../sysv/linux/powerpc/struct__semid_ds32.h | 30 +++++++++++++++++++ .../sysv/linux/sparc/struct__semid_ds32.h | 30 +++++++++++++++++++ sysdeps/unix/sysv/linux/struct__semid_ds32.h | 30 +++++++++++++++++++ .../unix/sysv/linux/x86/struct__semid_ds32.h | 30 +++++++++++++++++++ 6 files changed, 178 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/hppa/struct__semid_ds32.h create mode 100644 sysdeps/unix/sysv/linux/mips/struct__semid_ds32.h create mode 100644 sysdeps/unix/sysv/linux/powerpc/struct__semid_ds32.h create mode 100644 sysdeps/unix/sysv/linux/sparc/struct__semid_ds32.h create mode 100644 sysdeps/unix/sysv/linux/struct__semid_ds32.h create mode 100644 sysdeps/unix/sysv/linux/x86/struct__semid_ds32.h diff --git a/sysdeps/unix/sysv/linux/hppa/struct__semid_ds32.h b/sysdeps/unix/sysv/linux/hppa/struct__semid_ds32.h new file mode 100644 index 0000000000..7a6b803cee --- /dev/null +++ b/sysdeps/unix/sysv/linux/hppa/struct__semid_ds32.h @@ -0,0 +1,30 @@ +/* HPPA implementation of the semaphore struct __semid_ds32. + Copyright (C) 1995-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This is the "new" y2038 types defined after the 5.1 kernel. It allows + the kernel to use {o,c}time{_high} values to support a 64-bit time_t. */ +struct __semid_ds32 { + struct ipc_perm sem_perm; /* operation permission struct */ + __syscall_ulong_t sem_otime_high; /* last semop() time high */ + __syscall_ulong_t sem_otime; /* last semop() time */ + __syscall_ulong_t sem_ctime_high; /* last time changed by semctl() high */ + __syscall_ulong_t sem_ctime; /* last time changed by semctl() */ + __syscall_ulong_t sem_nsems; /* number of semaphores in set */ + __syscall_ulong_t __glibc_reserved3; + __syscall_ulong_t __glibc_reserved4; +}; diff --git a/sysdeps/unix/sysv/linux/mips/struct__semid_ds32.h b/sysdeps/unix/sysv/linux/mips/struct__semid_ds32.h new file mode 100644 index 0000000000..3a1d7c6885 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/struct__semid_ds32.h @@ -0,0 +1,28 @@ +/* MIPS implementation of the semaphore struct __semid_ds32. + Copyright (C) 1995-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This is the "new" y2038 types defined after the 5.1 kernel. It allows + the kernel to use {o,c}time{_high} values to support a 64-bit time_t. */ +struct __semid_ds32 { + struct ipc_perm sem_perm; /* operation permission struct */ + __syscall_ulong_t sem_otime; /* last semop time */ + __syscall_ulong_t sem_ctime; /* last change time */ + __syscall_ulong_t sem_nsems; /* number of semaphores in set */ + __syscall_ulong_t sem_otime_high; + __syscall_ulong_t sem_ctime_high; +}; diff --git a/sysdeps/unix/sysv/linux/powerpc/struct__semid_ds32.h b/sysdeps/unix/sysv/linux/powerpc/struct__semid_ds32.h new file mode 100644 index 0000000000..880c0a3c04 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/struct__semid_ds32.h @@ -0,0 +1,30 @@ +/* PowerPC implementation of the semaphore struct __semid_ds32. + Copyright (C) 1995-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This is the "new" y2038 types defined after the 5.1 kernel. It allows + the kernel to use {o,c}time{_high} values to support a 64-bit time_t. */ +struct __semid_ds32 { + struct ipc_perm sem_perm; /* operation permission struct */ + __syscall_ulong_t sem_otime_high; /* last semop() time high */ + __syscall_ulong_t sem_otime; /* last semop() time */ + __syscall_ulong_t sem_ctime_high; /* last time changed by semctl() high */ + __syscall_ulong_t sem_ctime; /* last time changed by semctl() */ + __syscall_ulong_t sem_nsems; /* number of semaphores in set */ + __syscall_ulong_t __glibc_reserved3; + __syscall_ulong_t __glibc_reserved4; +}; diff --git a/sysdeps/unix/sysv/linux/sparc/struct__semid_ds32.h b/sysdeps/unix/sysv/linux/sparc/struct__semid_ds32.h new file mode 100644 index 0000000000..0be263ccd0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/struct__semid_ds32.h @@ -0,0 +1,30 @@ +/* Sparc implementation of the semaphore struct __semid_ds32. + Copyright (C) 1995-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This is the "new" y2038 types defined after the 5.1 kernel. It allows + the kernel to use {o,c}time{_high} values to support a 64-bit time_t. */ +struct __semid_ds32 { + struct ipc_perm sem_perm; /* operation permission struct */ + __syscall_ulong_t sem_otime_high; /* last semop() time high */ + __syscall_ulong_t sem_otime; /* last semop() time */ + __syscall_ulong_t sem_ctime_high; /* last time changed by semctl() high */ + __syscall_ulong_t sem_ctime; /* last time changed by semctl() */ + __syscall_ulong_t sem_nsems; /* number of semaphores in set */ + __syscall_ulong_t __glibc_reserved3; + __syscall_ulong_t __glibc_reserved4; +}; diff --git a/sysdeps/unix/sysv/linux/struct__semid_ds32.h b/sysdeps/unix/sysv/linux/struct__semid_ds32.h new file mode 100644 index 0000000000..c5242f4096 --- /dev/null +++ b/sysdeps/unix/sysv/linux/struct__semid_ds32.h @@ -0,0 +1,30 @@ +/* Generic implementation of the semaphore struct __semid_ds32. + Copyright (C) 1995-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This is the "new" y2038 types defined after the 5.1 kernel. It allows + the kernel to use {o,c}time{_high} values to support a 64-bit time_t. */ +struct __semid_ds32 { + struct ipc_perm sem_perm; /* operation permission struct */ + __syscall_ulong_t sem_otime; /* last semop() time */ + __syscall_ulong_t sem_otime_high; /* last semop() time high */ + __syscall_ulong_t sem_ctime; /* last time changed by semctl() */ + __syscall_ulong_t sem_ctime_high; /* last time changed by semctl() high */ + __syscall_ulong_t sem_nsems; /* number of semaphores in set */ + __syscall_ulong_t __glibc_reserved3; + __syscall_ulong_t __glibc_reserved4; +}; diff --git a/sysdeps/unix/sysv/linux/x86/struct__semid_ds32.h b/sysdeps/unix/sysv/linux/x86/struct__semid_ds32.h new file mode 100644 index 0000000000..1155f5f93a --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/struct__semid_ds32.h @@ -0,0 +1,30 @@ +/* x86 implementation of the semaphore struct __semid_ds32. + Copyright (C) 1995-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This is the "new" y2038 types defined after the 5.1 kernel. It allows + the kernel to use {o,c}time{_high} values to support a 64-bit time_t. */ +struct __semid_ds32 { + struct ipc_perm sem_perm; /* operation permission struct */ + __syscall_ulong_t sem_otime; /* last semop() time */ + __syscall_ulong_t sem_otime_high; /* last semop() time high */ + __syscall_ulong_t sem_ctime; /* last time changed by semctl() */ + __syscall_ulong_t sem_ctime_high; /* last time changed by semctl() high */ + __syscall_ulong_t sem_nsems; /* number of semaphores in set */ + __syscall_ulong_t __glibc_reserved3; + __syscall_ulong_t __glibc_reserved4; +}; From patchwork Tue Jun 2 20:41:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 39421 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AAA4A383F842; Tue, 2 Jun 2020 20:50:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAA4A383F842 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1591131011; bh=/+eerEroqscLU4noAZb9qEqbDkDUZNEVmtJmvHzB44c=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GRlQuqmMVAUbL2hlevq+tRU7Cb1lsYu0hZpPcyRaVjQ28waWYSzu/LvU5MSumcfjN kcTtT8e3jODdFIi3LzCOC86kkCs40kabFR7ETlmrRT4ipsiS0dSDGzVFwVo5kJ2cO9 eTQdIUAVRyQU2EFpfbrUXZPbL6HvxYQlBcGNnrLo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by sourceware.org (Postfix) with ESMTPS id 60A03385DC00 for ; Tue, 2 Jun 2020 20:50:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 60A03385DC00 IronPort-SDR: 0hX1xrCOk2YcMZjW2PJfZJeOKDEPcjjwx7c0P61dlhfUWaM8mn7IczuJ1thbs5CR8UHw/pTQL/ McAFqhqNwr9E8mBADO0zgNHV9QoPgWEHVPUJLYexxDwnobQZo7aU51DhPOMJ5Z7EIWRsY+V50t 89t44h0PLxs7Qe4hKaU3ikWkvbCWyj1hHY6niNabHe0AJlmQ+enjwYtMrilpBfD0kGV66ZCIpl 2q4GwY8xVP9GDk6l1X/JA9V1xGfZEupEol2RS3YGFCUO3D+b5Z7flSYv6G5v3zMD4hpOoMQaOG Mog= X-IronPort-AV: E=Sophos;i="5.73,465,1583164800"; d="scan'208";a="140480634" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 03 Jun 2020 04:49:52 +0800 IronPort-SDR: trHDnDZwavngqiv6uLO9KCaqWzeh1Rze0bKzx5/hBQUH3BgEpHZO1Ua1HdkSn50yHsr+Dy/ouV E6naQ4gwagmNsQqHOu0UKpmfq8YdJbtV0= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2020 13:38:58 -0700 IronPort-SDR: MYulpC39Jjz9gkq334cquJg6u6EE0aRFyN4x3uP868EpBHc+mE+9d7C2r31+QQs3evMA56+Swz rNcIeJNczE3w== WDCIronportException: Internal Received: from cne220230.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.144]) by uls-op-cesaip01.wdc.com with ESMTP; 02 Jun 2020 13:49:51 -0700 To: libc-alpha@sourceware.org Subject: [PATCH v9 2/2] sysv: linux: Pass 64-bit version of semctl syscall Date: Tue, 2 Jun 2020 13:41:05 -0700 Message-Id: <20200602204105.43866-3-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602204105.43866-1-alistair.francis@wdc.com> References: <20200602204105.43866-1-alistair.francis@wdc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-17.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alistair Francis via Libc-alpha From: Alistair Francis Reply-To: Alistair Francis Cc: stepan@golosunov.pp.ru, Alistair Francis Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The semctl_syscall() function passes a union semun to the kernel. The union includes struct semid_ds as a member. On 32-bit architectures the Linux kernel provides a *_high version of the 32-bit sem_otime and sem_ctime values. These can be combined to get a 64-bit version of the time. This patch adjusts the struct semid_ds to support the *_high versions of sem_otime and sem_ctime. For 32-bit systems with a 64-bit time_t this can be used to get a 64-bit time from the two 32-bit values. Due to alignment differences between 64-bit and 32-bit variables we also need to set nsems to ensure it's correct. --- sysdeps/unix/sysv/linux/ipc_priv.h | 7 +++++ sysdeps/unix/sysv/linux/semctl.c | 50 +++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/sysdeps/unix/sysv/linux/ipc_priv.h b/sysdeps/unix/sysv/linux/ipc_priv.h index 15a6e683a4..ff20323337 100644 --- a/sysdeps/unix/sysv/linux/ipc_priv.h +++ b/sysdeps/unix/sysv/linux/ipc_priv.h @@ -43,6 +43,13 @@ struct __old_ipc_perm unsigned short int __seq; /* Sequence number. */ }; +#if (__WORDSIZE == 32 && __TIMESIZE == 64 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) +# define __IPC_TIME64 1 +#else +# define __IPC_TIME64 0 +#endif + #define SEMCTL_ARG_ADDRESS(__arg) &__arg.array #define MSGRCV_ARGS(__msgp, __msgtyp) \ diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c index 30571af49f..3ed2af89d1 100644 --- a/sysdeps/unix/sysv/linux/semctl.c +++ b/sysdeps/unix/sysv/linux/semctl.c @@ -22,6 +22,7 @@ #include #include #include +#include #include /* For __kernel_mode_t. */ /* Define a `union semun' suitable for Linux here. */ @@ -44,13 +45,54 @@ union semun static int semctl_syscall (int semid, int semnum, int cmd, union semun arg) { + int ret; +#if __IPC_TIME64 + /* A temporary buffer is used to avoid both an issue where the export + semid_ds might not follow the kernel's expected layout (due +   to {o,c}time{_high} alignment in 64-bit time case) and the issue where +    some kernel versions might not clear the high bits when returning +    then {o,c}time{_high} information. */ + struct __semid_ds32 tmp; + struct semid_ds *orig; + bool restore = false; + if (cmd == IPC_STAT || cmd == SEM_STAT || cmd == SEM_STAT_ANY) + { + tmp = (struct __semid_ds32) { + .sem_perm = arg.buf->sem_perm, + .sem_otime = arg.buf->sem_otime, + .sem_otime_high = arg.buf->sem_otime >> 32, + .sem_ctime = arg.buf->sem_ctime, + .sem_ctime_high = arg.buf->sem_ctime >> 32, + .sem_nsems = arg.buf->sem_nsems, + }; + orig = arg.buf; + arg.buf = (struct semid_ds*) &tmp; + restore = true; + } +#endif + #ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS - return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64, - arg.array); + ret = INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64, + arg.array); #else - return INLINE_SYSCALL_CALL (ipc, IPCOP_semctl, semid, semnum, cmd | __IPC_64, - SEMCTL_ARG_ADDRESS (arg)); + ret = INLINE_SYSCALL_CALL (ipc, IPCOP_semctl, semid, semnum, cmd | __IPC_64, + SEMCTL_ARG_ADDRESS (arg)); #endif + +#if __IPC_TIME64 + if (ret >= 0 && restore) + { + arg.buf = orig; + arg.buf->sem_perm = tmp.sem_perm; + arg.buf->sem_otime = tmp.sem_otime + | ((__time64_t) tmp.sem_otime_high << 32); + arg.buf->sem_ctime = tmp.sem_ctime + | ((__time64_t) tmp.sem_ctime_high << 32); + arg.buf->sem_nsems = tmp.sem_nsems; + } +#endif + + return ret; } int