From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by sourceware.org (Postfix) with ESMTPS id 933CA3851C32 for ; Tue, 28 Apr 2020 22:13:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 933CA3851C32 IronPort-SDR: f65qYBuqGdcda6WLcUTPy+3xrj/iIDAJg1KqQkl/vc3/0JuNbUWTJMU1n6B+FxvN3J/u1KIcHL rdUUHNbklrr1VFgvAPF0yAp7iXcNcb7KEBveWAvPkohnLJG1YqKLiheToThn+iVHZWqaOThxe2 361VXksnSo79JRnhXEfuR99GAhB8WOpgv8SwcM24R+VCnX5Q9IxZECtZ0WE80IqWR0zlq0U8ZE fuyY1ApqOTfJIZP/NqA/B2LUZCw+BgVL/Sjg6NTvnMsHAG5UslU9bm6wGE3kJOHnLxatKGyVjT 6ZU= X-IronPort-AV: E=Sophos;i="5.73,328,1583164800"; d="scan'208";a="140766187" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 Apr 2020 06:13:28 +0800 IronPort-SDR: Oi+mjrRzzUW27RLlPGy75ReazrpFJt2QIjMLBEX292IllUOmMNzRm1SK1hFea0hoPlEX7P7lI+ 1xG59q9yynxFFHpKOih+YHAUG/0sAkliA= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2020 15:04:06 -0700 IronPort-SDR: R5VcLlgm5+ZY/h5gQX8hq5OifTZvIZuoMVBQGbj99V9JSn59x8UNkHHuNFpvhgMfr5EWwLAAIt SgAoLXz8SxRg== WDCIronportException: Internal Received: from cnf009918.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.56.6]) by uls-op-cesaip01.wdc.com with ESMTP; 28 Apr 2020 15:13:27 -0700 From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v6 3/3] sysv: linux: Pass 64-bit version of semctl syscall Date: Tue, 28 Apr 2020 15:05:07 -0700 Message-Id: <20200428220507.3409362-4-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200428220507.3409362-1-alistair.francis@wdc.com> References: <20200428220507.3409362-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-24.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, 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-List-Received-Date: Tue, 28 Apr 2020 22:13:34 -0000 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. --- .../unix/sysv/linux/hppa/struct__semid_ds32.h | 32 +++++++++++++ .../unix/sysv/linux/mips/struct__semid_ds32.h | 30 ++++++++++++ .../sysv/linux/powerpc/struct__semid_ds32.h | 32 +++++++++++++ sysdeps/unix/sysv/linux/semctl.c | 47 +++++++++++++++++-- .../sysv/linux/sparc/struct__semid_ds32.h | 32 +++++++++++++ sysdeps/unix/sysv/linux/struct__semid_ds32.h | 32 +++++++++++++ .../unix/sysv/linux/x86/struct__semid_ds32.h | 32 +++++++++++++ 7 files changed, 233 insertions(+), 4 deletions(-) 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..9eceaaff2d --- /dev/null +++ b/sysdeps/unix/sysv/linux/hppa/struct__semid_ds32.h @@ -0,0 +1,32 @@ +/* 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 + . */ + +#if __WORDSIZE == 32 +/* 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; +}; +#endif 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..2e3e2fc562 --- /dev/null +++ b/sysdeps/unix/sysv/linux/mips/struct__semid_ds32.h @@ -0,0 +1,30 @@ +/* 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 + . */ + +#if __WORDSIZE == 32 +/* 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; +}; +#endif 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..f509db5a02 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/struct__semid_ds32.h @@ -0,0 +1,32 @@ +/* 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 + . */ + +#if __WORDSIZE == 32 +/* 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; +}; +#endif diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c index 30571af49f..0634cc1abe 100644 --- a/sysdeps/unix/sysv/linux/semctl.c +++ b/sysdeps/unix/sysv/linux/semctl.c @@ -22,8 +22,13 @@ #include #include #include +#include #include /* For __kernel_mode_t. */ +#define IPC_TIME64 \ + (__WORDSIZE == 32 && __TIMESIZE == 64 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) + /* Define a `union semun' suitable for Linux here. */ union semun { @@ -44,13 +49,47 @@ union semun static int semctl_syscall (int semid, int semnum, int cmd, union semun arg) { + int ret; +#if IPC_TIME64 + 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_ctime = arg.buf->sem_ctime, + .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 + | ((time_t) tmp.sem_otime_high << 32); + arg.buf->sem_ctime = tmp.sem_ctime + | ((time_t) tmp.sem_ctime_high << 32); + arg.buf->sem_nsems = tmp.sem_nsems; + } +#endif + + return ret; } int 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..f641825d37 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/struct__semid_ds32.h @@ -0,0 +1,32 @@ +/* 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 + . */ + +#if __WORDSIZE == 32 +/* 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; +}; +#endif 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..51ff83206d --- /dev/null +++ b/sysdeps/unix/sysv/linux/struct__semid_ds32.h @@ -0,0 +1,32 @@ +/* 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 + . */ + +#if __WORDSIZE == 32 +/* 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; +}; +#endif 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..f65c9fc877 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/struct__semid_ds32.h @@ -0,0 +1,32 @@ +/* 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 + . */ + +#ifdef __i386__ +/* 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; +}; +#endif -- 2.26.2