[1/7] sysv: linux: Add 64-bit time_t variant for semctl
Commit Message
Different than others 64-bit time_t syscalls, the SysIPC interface
does not provide a new set of syscall for y2038 safeness. Instead it
uses ununsed fields in semid_ds structure the return the high bits for
the timestamps.
To provide a y2038 safe interface a new symbol __semctl64 is added
and __semctl is change to call it instead (it adds some extra buffer
copy for the 32 bit time_t implementation).
Two two new structures are added:
1. kernel_semid64_ds: used internally only on 32-bit architectures
to issue the syscall. A handful architectures (hppa, i386, mips,
powerpc32, sparc32) requires specific implementation due its
specific kernel ABI.
2. semid_ds64: this is only for __TIMESIZE != 64 to use along with
the 64-bit semctl. It is different than the kernel one because
the exported 64-bit time_t might require different alignment
depending of the architecture ABI.
So the resulting implementation does:
1. For 64-bit architectures it assumes semid_ds already contains
64-bit time_t fields it will result in just the __semctl symbol
using the __semctl64 code. The semid_ds argument is passed as-is
to the syscall.
2. For 32-bit architectures with default 64-bit time_t (newer ABIs
such riscv32 or arc), it will also result in only one exported
symbol but with the required high/low handling.
It might be possible to optimize it further to avoid the
kernel_semid64_ds to semun transformation if the exported ABI
for the architectures matches the expected kernel ABI, but the
implementation is already complex enough and don't think this
should be a hotspot in any case.
3. Finally for 32-bit architecture with both 32-bit and 64-bit time_t
support we follow the already set way to provide one symbol with
64-bit time_t support and implement the 32-bit time_t support on
basis of the 64-bit one.
The default 32-bit symbol will allocate and copy the semid_ds
over multiple buffers, but this should be deprecated in favor
of the __semctl64 anyway.
Checked on i686-linux-gnu and x86_64-linux-gnu. I also did some sniff
tests on powerpc, powerpc64, mips, mips64, armhf, sparcv9, and
sparc64.
---
include/sys/sem.h | 7 +
.../sysv/linux/bits/types/struct_semid64_ds.h | 33 +++
.../sysv/linux/bits/types/struct_semid_ds.h | 21 +-
.../linux/hppa/bits/types/struct_semid_ds.h | 6 +-
.../linux/hppa/struct_kernel_semid64_ds.h | 12 +
.../linux/i386/struct_kernel_semid64_ds.h | 12 +
sysdeps/unix/sysv/linux/ipc_priv.h | 10 +
.../linux/mips/bits/types/struct_semid_ds.h | 4 +-
.../linux/mips/struct_kernel_semid64_ds.h | 10 +
.../powerpc/bits/types/struct_semid_ds.h | 4 +-
.../powerpc32/struct_kernel_semid64_ds.h | 12 +
sysdeps/unix/sysv/linux/semctl.c | 261 +++++++++++++++---
.../linux/sparc/bits/types/struct_semid_ds.h | 4 +-
.../sparc/sparc32/struct_kernel_semid64_ds.h | 12 +
.../sysv/linux/struct_kernel_semid64_ds.h | 12 +
.../linux/x86/bits/types/struct_semid_ds.h | 4 +-
16 files changed, 359 insertions(+), 65 deletions(-)
create mode 100644 sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h
create mode 100644 sysdeps/unix/sysv/linux/hppa/struct_kernel_semid64_ds.h
create mode 100644 sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h
create mode 100644 sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h
create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h
create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h
create mode 100644 sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h
Comments
On Tue, Jun 30, 2020 at 12:26 PM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> Different than others 64-bit time_t syscalls, the SysIPC interface
> does not provide a new set of syscall for y2038 safeness. Instead it
> uses ununsed fields in semid_ds structure the return the high bits for
> the timestamps.
>
> To provide a y2038 safe interface a new symbol __semctl64 is added
> and __semctl is change to call it instead (it adds some extra buffer
> copy for the 32 bit time_t implementation).
>
> Two two new structures are added:
>
> 1. kernel_semid64_ds: used internally only on 32-bit architectures
> to issue the syscall. A handful architectures (hppa, i386, mips,
> powerpc32, sparc32) requires specific implementation due its
> specific kernel ABI.
>
> 2. semid_ds64: this is only for __TIMESIZE != 64 to use along with
> the 64-bit semctl. It is different than the kernel one because
> the exported 64-bit time_t might require different alignment
> depending of the architecture ABI.
>
> So the resulting implementation does:
>
> 1. For 64-bit architectures it assumes semid_ds already contains
> 64-bit time_t fields it will result in just the __semctl symbol
> using the __semctl64 code. The semid_ds argument is passed as-is
> to the syscall.
>
> 2. For 32-bit architectures with default 64-bit time_t (newer ABIs
> such riscv32 or arc), it will also result in only one exported
> symbol but with the required high/low handling.
>
> It might be possible to optimize it further to avoid the
> kernel_semid64_ds to semun transformation if the exported ABI
> for the architectures matches the expected kernel ABI, but the
> implementation is already complex enough and don't think this
> should be a hotspot in any case.
>
> 3. Finally for 32-bit architecture with both 32-bit and 64-bit time_t
> support we follow the already set way to provide one symbol with
> 64-bit time_t support and implement the 32-bit time_t support on
> basis of the 64-bit one.
>
> The default 32-bit symbol will allocate and copy the semid_ds
> over multiple buffers, but this should be deprecated in favor
> of the __semctl64 anyway.
>
> Checked on i686-linux-gnu and x86_64-linux-gnu. I also did some sniff
> tests on powerpc, powerpc64, mips, mips64, armhf, sparcv9, and
> sparc64.
This looks good.
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> include/sys/sem.h | 7 +
> .../sysv/linux/bits/types/struct_semid64_ds.h | 33 +++
> .../sysv/linux/bits/types/struct_semid_ds.h | 21 +-
> .../linux/hppa/bits/types/struct_semid_ds.h | 6 +-
> .../linux/hppa/struct_kernel_semid64_ds.h | 12 +
> .../linux/i386/struct_kernel_semid64_ds.h | 12 +
> sysdeps/unix/sysv/linux/ipc_priv.h | 10 +
> .../linux/mips/bits/types/struct_semid_ds.h | 4 +-
> .../linux/mips/struct_kernel_semid64_ds.h | 10 +
> .../powerpc/bits/types/struct_semid_ds.h | 4 +-
> .../powerpc32/struct_kernel_semid64_ds.h | 12 +
> sysdeps/unix/sysv/linux/semctl.c | 261 +++++++++++++++---
> .../linux/sparc/bits/types/struct_semid_ds.h | 4 +-
> .../sparc/sparc32/struct_kernel_semid64_ds.h | 12 +
> .../sysv/linux/struct_kernel_semid64_ds.h | 12 +
> .../linux/x86/bits/types/struct_semid_ds.h | 4 +-
> 16 files changed, 359 insertions(+), 65 deletions(-)
> create mode 100644 sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/hppa/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h
>
> diff --git a/include/sys/sem.h b/include/sys/sem.h
> index 69fdf1f752..a9151e057d 100644
> --- a/include/sys/sem.h
> +++ b/include/sys/sem.h
> @@ -5,5 +5,12 @@
>
> __typeof__ (semtimedop) __semtimedop attribute_hidden;
>
> +#if __TIMESIZE == 64
> +# define __semctl64 __semctl
> +#else
> +extern int __semctl64 (int semid, int semnum, int cmd, ...);
> +libc_hidden_proto (__semctl64);
> +#endif
> +
> # endif
> #endif
> diff --git a/sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h b/sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h
> new file mode 100644
> index 0000000000..bda9eb4469
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h
> @@ -0,0 +1,33 @@
> +/* Generic implementation of the semaphore struct semid64_ds.
> + Copyright (C) 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
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef _SYS_SEM_H
> +# error "Never include <bits/types/struct_semid_ds.h> directly; use <sys/sem.h> instead."
> +#endif
> +
> +#if __TIMESIZE == 64
> +# define __semid64_ds semid_ds
> +#else
> +struct __semid64_ds
> +{
> + struct ipc_perm sem_perm; /* operation permission struct */
> + __time64_t sem_otime; /* last semop() time */
> + __time64_t sem_ctime; /* last time changed by semctl() */
> + __syscall_ulong_t sem_nsems; /* number of semaphores in set */
> +};
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h
> index 4222e6a59f..bc26d8be08 100644
> --- a/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h
> @@ -21,26 +21,19 @@
> #endif
>
> /* Data structure describing a set of semaphores. */
> -#if __TIMESIZE == 32
> struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> +#if __TIMESIZE == 32
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_ctime; /* last time changed by semctl() */
> - __syscall_ulong_t __glibc_reserved2;
> - __syscall_ulong_t sem_nsems; /* number of semaphores in set */
> - __syscall_ulong_t __glibc_reserved3;
> - __syscall_ulong_t __glibc_reserved4;
> -};
> + __syscall_ulong_t __sem_ctime_high;
> #else
> -struct semid_ds
> -{
> - struct ipc_perm sem_perm; /* operation permission struct */
> - __time_t sem_otime; /* last semop() time */
> - __time_t sem_ctime; /* last time changed by semctl() */
> - __syscall_ulong_t sem_nsems; /* number of semaphores in set */
> + __time_t sem_otime;
> + __time_t sem_ctime;
> +#endif
> + __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/hppa/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/hppa/bits/types/struct_semid_ds.h
> index d4c50b5ef8..68f9eca24c 100644
> --- a/sysdeps/unix/sysv/linux/hppa/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/hppa/bits/types/struct_semid_ds.h
> @@ -21,16 +21,14 @@
> #endif
>
> /* Data structure describing a set of semaphores. */
> -#if __TIMESIZE == 32
> struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved2;
> + __syscall_ulong_t __sem_ctime_high;
> __time_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/hppa/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/hppa/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..2871030d0d
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/hppa/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime_high;
> + unsigned long sem_otime;
> + unsigned long sem_ctime_high;
> + unsigned long sem_ctime;
> + unsigned long sem_nsems;
> + unsigned long __ununsed1;
> + unsigned long __ununsed2;
> +};
> diff --git a/sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..bab9cf63ba
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime;
> + unsigned long sem_otime_high;
> + unsigned long sem_ctime;
> + unsigned long sem_ctime_high;
> + __syscall_ulong_t sem_nsems;
> + __syscall_ulong_t __unused3;
> + __syscall_ulong_t __unused4;
> +};
> diff --git a/sysdeps/unix/sysv/linux/ipc_priv.h b/sysdeps/unix/sysv/linux/ipc_priv.h
> index 15a6e683a4..93a6e5cb24 100644
> --- a/sysdeps/unix/sysv/linux/ipc_priv.h
> +++ b/sysdeps/unix/sysv/linux/ipc_priv.h
> @@ -53,4 +53,14 @@ struct __old_ipc_perm
> #define SEMTIMEDOP_IPC_ARGS(__nsops, __sops, __timeout) \
> (__nsops), 0, (__sops), (__timeout)
>
> +/* Linux SysV ipc does not provide new syscalls for 64-bit time support on
> + 32-bit architectures, but rather split the timestamps on previous unused
> + fields. */
> +#if (__WORDSIZE == 32 \
> + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32))
> +# define __IPC_TIME64 1
> +#else
> +# define __IPC_TIME64 0
> +#endif
> +
> #include <ipc_ops.h>
> diff --git a/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h
> index 8954209a29..eec4a18cae 100644
> --- a/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h
> @@ -27,6 +27,6 @@ struct semid_ds
> __time_t sem_otime; /* last semop() time */
> __time_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;
> + __syscall_ulong_t __sem_otime_high;
> + __syscall_ulong_t __sem_ctime_high;
> };
> diff --git a/sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..76a9d83ea5
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h
> @@ -0,0 +1,10 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime;
> + unsigned long sem_ctime;
> + unsigned long sem_nsems;
> + unsigned long sem_otime_high;
> + unsigned long sem_ctime_high;
> +};
> diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h
> index 300a9b98e9..d382d93c52 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h
> @@ -25,9 +25,9 @@ struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> #if __TIMESIZE == 32
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved2;
> + __syscall_ulong_t __sem_ctime_high;
> __time_t sem_ctime; /* last time changed by semctl() */
> #else
> __time_t sem_otime; /* last semop() time */
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..7fa4ef6424
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime_high;
> + unsigned long sem_otime;
> + unsigned long sem_ctime_high;
> + unsigned long sem_ctime;
> + unsigned long sem_nsems;
> + unsigned long __unused3;
> + unsigned long __unused4;
> +};
> diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c
> index 30571af49f..3a06270242 100644
> --- a/sysdeps/unix/sysv/linux/semctl.c
> +++ b/sysdeps/unix/sysv/linux/semctl.c
> @@ -21,10 +21,13 @@
> #include <ipc_priv.h>
> #include <sysdep.h>
> #include <shlib-compat.h>
> -#include <errno.h>
> -#include <linux/posix_types.h> /* For __kernel_mode_t. */
> +#include <bits/types/struct_semid64_ds.h> /* For __semid64_ds. */
> +#include <linux/posix_types.h> /* For __kernel_mode_t. */
>
> -/* Define a `union semun' suitable for Linux here. */
> +/* The struct used to issue the syscall. For architecture that assume
> + 64-bit time as default (!__ASSUME_TIME64_SYSCALLS) the syscall will
> + split the resulting 64-bit sem_{o,c}time in two fields (__sem_{o,c}time
> + and __sem_{o,c}time_hi). */
> union semun
> {
> int val; /* value for SETVAL */
> @@ -33,16 +36,89 @@ union semun
> struct seminfo *__buf; /* buffer for IPC_INFO */
> };
>
> -#ifndef DEFAULT_VERSION
> -# ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T
> -# define DEFAULT_VERSION GLIBC_2_2
> +#if __IPC_TIME64 == 0
> +# define semun64 semun
> +typedef union semun semctl_arg_t;
> +#else
> +# include <struct_kernel_semid64_ds.h>
> +
> +union ksemun64
> +{
> + int val;
> + struct kernel_semid64_ds *buf;
> + unsigned short int *array;
> + struct seminfo *__buf;
> +};
> +
> +# if __TIMESIZE == 64
> +# define semun64 semun
> # else
> -# define DEFAULT_VERSION GLIBC_2_31
> +/* The struct used when __semctl64 is called. */
> +union semun64
> +{
> + int val;
> + struct __semid64_ds *buf;
> + unsigned short int *array;
> + struct seminfo *__buf;
> +};
> # endif
> +
> +static void
> +semid64_to_ksemid64 (const struct __semid64_ds *semid64,
> + struct kernel_semid64_ds *ksemid)
> +{
> + ksemid->sem_perm = semid64->sem_perm;
> + ksemid->sem_otime = semid64->sem_otime;
> + ksemid->sem_otime_high = semid64->sem_otime >> 32;
> + ksemid->sem_ctime = semid64->sem_ctime;
> + ksemid->sem_ctime_high = semid64->sem_ctime >> 32;
> + ksemid->sem_nsems = semid64->sem_nsems;
> +}
> +
> +static void
> +ksemid64_to_semid64 (const struct kernel_semid64_ds *ksemid,
> + struct __semid64_ds *semid64)
> +{
> + semid64->sem_perm = ksemid->sem_perm;
> + semid64->sem_otime = ksemid->sem_otime
> + | ((__time64_t) ksemid->sem_otime_high << 32);
> + semid64->sem_ctime = ksemid->sem_ctime
> + | ((__time64_t) ksemid->sem_ctime_high << 32);
> + semid64->sem_nsems = ksemid->sem_nsems;
> +}
> +
> +static union ksemun64
> +semun64_to_ksemun64 (int cmd, union semun64 semun64,
> + struct kernel_semid64_ds *buf)
> +{
> + union ksemun64 r = { 0 };
> + switch (cmd)
> + {
> + case SETVAL:
> + r.val = semun64.val;
> + break;
> + case GETALL:
> + case SETALL:
> + r.array = semun64.array;
> + break;
> + case IPC_STAT:
> + case IPC_SET:
> + r.buf = buf;
> + semid64_to_ksemid64 (semun64.buf, r.buf);
> + break;
> + case IPC_INFO:
> + case SEM_INFO:
> + r.__buf = semun64.__buf;
> + break;
> + }
> + return r;
> +}
> +
> +typedef union ksemun64 semctl_arg_t;
> #endif
>
> static int
> -semctl_syscall (int semid, int semnum, int cmd, union semun arg)
> +semctl_syscall (int semid, int semnum, int cmd, semctl_arg_t arg)
> {
> #ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
> return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64,
> @@ -53,15 +129,15 @@ semctl_syscall (int semid, int semnum, int cmd, union semun arg)
> #endif
> }
>
> +/* POSIX states ipc_perm mode should have type of mode_t. */
> +_Static_assert (sizeof ((struct semid_ds){0}.sem_perm.mode)
> + == sizeof (mode_t),
> + "sizeof (msqid_ds.msg_perm.mode) != sizeof (mode_t)");
> +
> int
> -__new_semctl (int semid, int semnum, int cmd, ...)
> +__semctl64 (int semid, int semnum, int cmd, ...)
> {
> - /* POSIX states ipc_perm mode should have type of mode_t. */
> - _Static_assert (sizeof ((struct semid_ds){0}.sem_perm.mode)
> - == sizeof (mode_t),
> - "sizeof (msqid_ds.msg_perm.mode) != sizeof (mode_t)");
> -
> - union semun arg = { 0 };
> + union semun64 arg64 = { 0 };
> va_list ap;
>
> /* Get the argument only if required. */
> @@ -76,44 +152,151 @@ __new_semctl (int semid, int semnum, int cmd, ...)
> case IPC_INFO: /* arg.__buf */
> case SEM_INFO:
> va_start (ap, cmd);
> - arg = va_arg (ap, union semun);
> + arg64 = va_arg (ap, union semun64);
> va_end (ap);
> break;
> }
>
> -#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
> - struct semid_ds tmpds;
> - if (cmd == IPC_SET)
> - {
> - tmpds = *arg.buf;
> - tmpds.sem_perm.mode *= 0x10000U;
> - arg.buf = &tmpds;
> - }
> +#if __IPC_TIME64
> + struct kernel_semid64_ds ksemid;
> + union ksemun64 ksemun = semun64_to_ksemun64 (cmd, arg64, &ksemid);
> + union ksemun64 arg = ksemun;
> +#else
> + union semun arg = arg64;
> #endif
>
> int ret = semctl_syscall (semid, semnum, cmd, arg);
> + if (ret < 0)
> + return ret;
>
> - if (ret >= 0)
> + switch (cmd)
> {
> - switch (cmd)
> - {
> - case IPC_STAT:
> - case SEM_STAT:
> - case SEM_STAT_ANY:
> + case IPC_STAT:
> + case SEM_STAT:
> + case SEM_STAT_ANY:
> #ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
> - arg.buf->sem_perm.mode >>= 16;
> + arg.buf->sem_perm.mode >>= 16;
> #else
> - /* Old Linux kernel versions might not clear the mode padding. */
> - if (sizeof ((struct semid_ds){0}.sem_perm.mode)
> - != sizeof (__kernel_mode_t))
> - arg.buf->sem_perm.mode &= 0xFFFF;
> + /* Old Linux kernel versions might not clear the mode padding. */
> + if (sizeof ((struct semid_ds){0}.sem_perm.mode)
> + != sizeof (__kernel_mode_t))
> + arg.buf->sem_perm.mode &= 0xFFFF;
> #endif
> - }
> +
> +#if __IPC_TIME64
> + ksemid64_to_semid64 (arg.buf, arg64.buf);
> +#endif
> + }
> +
> + return ret;
> +}
> +#if __TIMESIZE != 64
> +libc_hidden_def (__semctl64)
> +
> +
> +/* The 64-bit time_t semid_ds version might have a different layout and
> + internal field alignment. */
> +static void
> +semid64_ds_to_semid_ds (struct semid_ds *ds, const struct __semid64_ds *ds64)
> +{
> + ds->sem_perm = ds64->sem_perm;
> + ds->sem_otime = ds64->sem_otime;
> + ds->sem_ctime = ds64->sem_ctime;
> + ds->sem_nsems = ds64->sem_nsems;
> +}
> +
> +static void
> +semid_ds_to_semid64_ds (struct __semid64_ds *ds64, const struct semid_ds *ds)
> +{
> + ds64->sem_perm = ds->sem_perm;
> + ds64->sem_otime = ds->sem_otime
> + | ((__time64_t) ds->__sem_otime_high << 32);
> + ds64->sem_ctime = ds->sem_ctime
> + | ((__time64_t) ds->__sem_ctime_high << 32);
> + ds64->sem_nsems = ds->sem_nsems;
> +}
> +
> +static union semun64
> +semun_to_semun64 (int cmd, union semun semun, struct __semid64_ds *semid64)
> +{
> + union semun64 r = { 0 };
> + switch (cmd)
> + {
> + case SETVAL:
> + r.val = semun.val;
> + break;
> + case GETALL:
> + case SETALL:
> + r.array = semun.array;
> + break;
> + case IPC_STAT:
> + case IPC_SET:
> + r.buf = semid64;
> + semid_ds_to_semid64_ds (r.buf, semun.buf);
> +# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
> + if (cmd == IPC_SET)
> + r.buf->sem_perm.mode *= 0x10000U;
> +# endif
> + break;
> + case IPC_INFO:
> + case SEM_INFO:
> + r.__buf = semun.__buf;
> + break;
> + }
> + return r;
> +}
> +
> +int
> +__semctl (int semid, int semnum, int cmd, ...)
> +{
> + union semun arg = { 0 };
> +
> + va_list ap;
> +
> + /* Get the argument only if required. */
> + switch (cmd)
> + {
> + case SETVAL: /* arg.val */
> + case GETALL: /* arg.array */
> + case SETALL:
> + case IPC_STAT: /* arg.buf */
> + case IPC_SET:
> + case SEM_STAT:
> + case IPC_INFO: /* arg.__buf */
> + case SEM_INFO:
> + va_start (ap, cmd);
> + arg = va_arg (ap, union semun);
> + va_end (ap);
> + break;
> + }
> +
> + struct __semid64_ds semid64;
> + union semun64 arg64 = semun_to_semun64 (cmd, arg, &semid64);
> +
> + int ret = __semctl64 (semid, semnum, cmd, arg64);
> + if (ret < 0)
> + return ret;
> +
> + switch (cmd)
> + {
> + case IPC_STAT:
> + case SEM_STAT:
> + case SEM_STAT_ANY:
> + semid64_ds_to_semid_ds (arg.buf, arg64.buf);
> }
>
> return ret;
> }
> -versioned_symbol (libc, __new_semctl, semctl, DEFAULT_VERSION);
> +#endif
> +
> +#ifndef DEFAULT_VERSION
> +# ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T
> +# define DEFAULT_VERSION GLIBC_2_2
> +# else
> +# define DEFAULT_VERSION GLIBC_2_31
> +# endif
> +#endif
> +versioned_symbol (libc, __semctl, semctl, DEFAULT_VERSION);
>
> #if defined __ASSUME_SYSVIPC_BROKEN_MODE_T \
> && SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_31)
> @@ -121,7 +304,7 @@ int
> attribute_compat_text_section
> __semctl_mode16 (int semid, int semnum, int cmd, ...)
> {
> - union semun arg = { 0 };
> + semctl_arg_t arg = { 0 };
> va_list ap;
>
> /* Get the argument only if required. */
> @@ -136,7 +319,7 @@ __semctl_mode16 (int semid, int semnum, int cmd, ...)
> case IPC_INFO: /* arg.__buf */
> case SEM_INFO:
> va_start (ap, cmd);
> - arg = va_arg (ap, union semun);
> + arg = va_arg (ap, semctl_arg_t);
> va_end (ap);
> break;
> }
> diff --git a/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h
> index 46fcd79fb6..0110c1a940 100644
> --- a/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h
> @@ -25,9 +25,9 @@ struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> #if __TIMESIZE == 32
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved2;
> + __syscall_ulong_t __sem_ctime_high;
> __time_t sem_ctime; /* last time changed by semctl() */
> #else
> __time_t sem_otime; /* last semop() time */
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..8c4697f9ab
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime_high;
> + unsigned long sem_otime;
> + unsigned long sem_ctime_high;
> + unsigned long sem_ctime;
> + unsigned long sem_nsems;
> + unsigned long __unused1;
> + unsigned long __unused2;
> +};
> diff --git a/sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..f9edf0f76f
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime;
> + unsigned long sem_otime_high;
> + unsigned long sem_ctime;
> + unsigned long sem_ctime_high;
> + unsigned long sem_nsems;
> + unsigned long __unused1;
> + unsigned long __unused2;
> +};
> diff --git a/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h
> index f7ec89d115..c3f2fde9fd 100644
> --- a/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h
> @@ -25,9 +25,9 @@ struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_ctime; /* last time changed by semctl() */
> - __syscall_ulong_t __glibc_reserved2;
> + __syscall_ulong_t __sem_ctime_high;
> __syscall_ulong_t sem_nsems; /* number of semaphores in set */
> __syscall_ulong_t __glibc_reserved3;
> __syscall_ulong_t __glibc_reserved4;
> --
> 2.25.1
>
On 6/30/20 3:24 PM, Adhemerval Zanella via Libc-alpha wrote:
OK for master with comment cleanups. Very clean, very easy to understand
patch. I should finish the other 6 patches tomorrow morning.
No regressions on x86_64 or i686 (I did see the new rseq regression
for posix/tst-affinity-static though).
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
> Different than others 64-bit time_t syscalls, the SysIPC interface
> does not provide a new set of syscall for y2038 safeness. Instead it
> uses ununsed fields in semid_ds structure the return the high bits for
s/ununsed/unused/g
s/the return/to return/g
> the timestamps.
>
> To provide a y2038 safe interface a new symbol __semctl64 is added
> and __semctl is change to call it instead (it adds some extra buffer
> copy for the 32 bit time_t implementation).
OK.
>
> Two two new structures are added:
s/Two two/Two/g
>
> 1. kernel_semid64_ds: used internally only on 32-bit architectures
> to issue the syscall. A handful architectures (hppa, i386, mips,
s/handful/handful of/g
> powerpc32, sparc32) requires specific implementation due its
> specific kernel ABI.
Suggest:
require specific implementations due to their kernel ABI.
>
> 2. semid_ds64: this is only for __TIMESIZE != 64 to use along with
> the 64-bit semctl. It is different than the kernel one because
s/one/struct/g
> the exported 64-bit time_t might require different alignment
> depending of the architecture ABI.
OK.
>
> So the resulting implementation does:
>
> 1. For 64-bit architectures it assumes semid_ds already contains
> 64-bit time_t fields it will result in just the __semctl symbol
s/it/and/g
> using the __semctl64 code. The semid_ds argument is passed as-is
> to the syscall.
>
> 2. For 32-bit architectures with default 64-bit time_t (newer ABIs
> such riscv32 or arc), it will also result in only one exported
> symbol but with the required high/low handling.
OK.
> It might be possible to optimize it further to avoid the
> kernel_semid64_ds to semun transformation if the exported ABI
> for the architectures matches the expected kernel ABI, but the
> implementation is already complex enough and don't think this
> should be a hotspot in any case.
OK. Agreed. If we see a hotspot here we can discuss.
> 3. Finally for 32-bit architecture with both 32-bit and 64-bit time_t
> support we follow the already set way to provide one symbol with
> 64-bit time_t support and implement the 32-bit time_t support on
> basis of the 64-bit one.
s/on basis of/using/g
s/one/time_t/g
> The default 32-bit symbol will allocate and copy the semid_ds
> over multiple buffers, but this should be deprecated in favor
> of the __semctl64 anyway.
OK.
>
> Checked on i686-linux-gnu and x86_64-linux-gnu. I also did some sniff
> tests on powerpc, powerpc64, mips, mips64, armhf, sparcv9, and
> sparc64.
OK.
> ---
> include/sys/sem.h | 7 +
> .../sysv/linux/bits/types/struct_semid64_ds.h | 33 +++
> .../sysv/linux/bits/types/struct_semid_ds.h | 21 +-
> .../linux/hppa/bits/types/struct_semid_ds.h | 6 +-
> .../linux/hppa/struct_kernel_semid64_ds.h | 12 +
> .../linux/i386/struct_kernel_semid64_ds.h | 12 +
> sysdeps/unix/sysv/linux/ipc_priv.h | 10 +
> .../linux/mips/bits/types/struct_semid_ds.h | 4 +-
> .../linux/mips/struct_kernel_semid64_ds.h | 10 +
> .../powerpc/bits/types/struct_semid_ds.h | 4 +-
> .../powerpc32/struct_kernel_semid64_ds.h | 12 +
> sysdeps/unix/sysv/linux/semctl.c | 261 +++++++++++++++---
> .../linux/sparc/bits/types/struct_semid_ds.h | 4 +-
> .../sparc/sparc32/struct_kernel_semid64_ds.h | 12 +
> .../sysv/linux/struct_kernel_semid64_ds.h | 12 +
> .../linux/x86/bits/types/struct_semid_ds.h | 4 +-
> 16 files changed, 359 insertions(+), 65 deletions(-)
> create mode 100644 sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/hppa/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h
> create mode 100644 sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h
>
> diff --git a/include/sys/sem.h b/include/sys/sem.h
> index 69fdf1f752..a9151e057d 100644
> --- a/include/sys/sem.h
> +++ b/include/sys/sem.h
> @@ -5,5 +5,12 @@
>
> __typeof__ (semtimedop) __semtimedop attribute_hidden;
>
> +#if __TIMESIZE == 64
> +# define __semctl64 __semctl
> +#else
> +extern int __semctl64 (int semid, int semnum, int cmd, ...);
> +libc_hidden_proto (__semctl64);
OK.
> +#endif
> +
> # endif
> #endif
> diff --git a/sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h b/sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h
> new file mode 100644
> index 0000000000..bda9eb4469
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds.h
> @@ -0,0 +1,33 @@
> +/* Generic implementation of the semaphore struct semid64_ds.
> + Copyright (C) 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
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef _SYS_SEM_H
> +# error "Never include <bits/types/struct_semid_ds.h> directly; use <sys/sem.h> instead."
> +#endif
> +
> +#if __TIMESIZE == 64
> +# define __semid64_ds semid_ds
> +#else
> +struct __semid64_ds
> +{
> + struct ipc_perm sem_perm; /* operation permission struct */
OK.
> + __time64_t sem_otime; /* last semop() time */
> + __time64_t sem_ctime; /* last time changed by semctl() */
> + __syscall_ulong_t sem_nsems; /* number of semaphores in set */
OK.
> +};
> +#endif
> diff --git a/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h
> index 4222e6a59f..bc26d8be08 100644
> --- a/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h
> @@ -21,26 +21,19 @@
> #endif
>
> /* Data structure describing a set of semaphores. */
> -#if __TIMESIZE == 32
> struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> +#if __TIMESIZE == 32
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
OK.
> __time_t sem_ctime; /* last time changed by semctl() */
> - __syscall_ulong_t __glibc_reserved2;
> - __syscall_ulong_t sem_nsems; /* number of semaphores in set */
> - __syscall_ulong_t __glibc_reserved3;
> - __syscall_ulong_t __glibc_reserved4;
> -};
> + __syscall_ulong_t __sem_ctime_high;
OK.
> #else
> -struct semid_ds
> -{
> - struct ipc_perm sem_perm; /* operation permission struct */
> - __time_t sem_otime; /* last semop() time */
> - __time_t sem_ctime; /* last time changed by semctl() */
> - __syscall_ulong_t sem_nsems; /* number of semaphores in set */
> + __time_t sem_otime;
> + __time_t sem_ctime;
OK.
> +#endif
> + __syscall_ulong_t sem_nsems; /* number of semaphores in set */
OK.
> __syscall_ulong_t __glibc_reserved3;
> __syscall_ulong_t __glibc_reserved4;
> };
> -#endif
> diff --git a/sysdeps/unix/sysv/linux/hppa/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/hppa/bits/types/struct_semid_ds.h
> index d4c50b5ef8..68f9eca24c 100644
> --- a/sysdeps/unix/sysv/linux/hppa/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/hppa/bits/types/struct_semid_ds.h
> @@ -21,16 +21,14 @@
> #endif
>
> /* Data structure describing a set of semaphores. */
> -#if __TIMESIZE == 32
> struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved2;
> + __syscall_ulong_t __sem_ctime_high;
OK.
> __time_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/hppa/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/hppa/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..2871030d0d
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/hppa/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime_high;
> + unsigned long sem_otime;
> + unsigned long sem_ctime_high;
> + unsigned long sem_ctime;
OK. Matches where the reserved entries were for hppa.
> + unsigned long sem_nsems;
> + unsigned long __ununsed1;
> + unsigned long __ununsed2;
> +};
> diff --git a/sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..bab9cf63ba
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/i386/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime;
> + unsigned long sem_otime_high;
> + unsigned long sem_ctime;
> + unsigned long sem_ctime_high;
OK.
> + __syscall_ulong_t sem_nsems;
> + __syscall_ulong_t __unused3;
> + __syscall_ulong_t __unused4;
> +};
> diff --git a/sysdeps/unix/sysv/linux/ipc_priv.h b/sysdeps/unix/sysv/linux/ipc_priv.h
> index 15a6e683a4..93a6e5cb24 100644
> --- a/sysdeps/unix/sysv/linux/ipc_priv.h
> +++ b/sysdeps/unix/sysv/linux/ipc_priv.h
> @@ -53,4 +53,14 @@ struct __old_ipc_perm
> #define SEMTIMEDOP_IPC_ARGS(__nsops, __sops, __timeout) \
> (__nsops), 0, (__sops), (__timeout)
>
> +/* Linux SysV ipc does not provide new syscalls for 64-bit time support on
> + 32-bit architectures, but rather split the timestamps on previous unused
> + fields. */
Suggest:
but rather split the timestamp into high and low; storing the high value in
previously unused fields.
> +#if (__WORDSIZE == 32 \
> + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32))
> +# define __IPC_TIME64 1
> +#else
> +# define __IPC_TIME64 0
> +#endif
OK.
> +
> #include <ipc_ops.h>
> diff --git a/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h
> index 8954209a29..eec4a18cae 100644
> --- a/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h
> @@ -27,6 +27,6 @@ struct semid_ds
> __time_t sem_otime; /* last semop() time */
> __time_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;
> + __syscall_ulong_t __sem_otime_high;
> + __syscall_ulong_t __sem_ctime_high;
OK.
> };
> diff --git a/sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..76a9d83ea5
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/mips/struct_kernel_semid64_ds.h
> @@ -0,0 +1,10 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime;
> + unsigned long sem_ctime;
> + unsigned long sem_nsems;
> + unsigned long sem_otime_high;
> + unsigned long sem_ctime_high;
OK. Matches mips.
> +};
> diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h
> index 300a9b98e9..d382d93c52 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h
> @@ -25,9 +25,9 @@ struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> #if __TIMESIZE == 32
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved2;
> + __syscall_ulong_t __sem_ctime_high;
OK.
> __time_t sem_ctime; /* last time changed by semctl() */
> #else
> __time_t sem_otime; /* last semop() time */
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..7fa4ef6424
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime_high;
> + unsigned long sem_otime;
> + unsigned long sem_ctime_high;
> + unsigned long sem_ctime;
> + unsigned long sem_nsems;
> + unsigned long __unused3;
> + unsigned long __unused4;
OK. Matches powerpc32.
> +};
> diff --git a/sysdeps/unix/sysv/linux/semctl.c b/sysdeps/unix/sysv/linux/semctl.c
> index 30571af49f..3a06270242 100644
> --- a/sysdeps/unix/sysv/linux/semctl.c
> +++ b/sysdeps/unix/sysv/linux/semctl.c
> @@ -21,10 +21,13 @@
> #include <ipc_priv.h>
> #include <sysdep.h>
> #include <shlib-compat.h>
> -#include <errno.h>
> -#include <linux/posix_types.h> /* For __kernel_mode_t. */
> +#include <bits/types/struct_semid64_ds.h> /* For __semid64_ds. */
> +#include <linux/posix_types.h> /* For __kernel_mode_t. */
OK.
>
> -/* Define a `union semun' suitable for Linux here. */
> +/* The struct used to issue the syscall. For architecture that assume
s/architecture/architectures/g
> + 64-bit time as default (!__ASSUME_TIME64_SYSCALLS) the syscall will
> + split the resulting 64-bit sem_{o,c}time in two fields (__sem_{o,c}time
s/__sem_{o,c}time/sem_{o,c}time/g
> + and __sem_{o,c}time_hi). */
s/__sem_{o,c}time_hi/__sem{o,c}time_high/g
> union semun
> {
> int val; /* value for SETVAL */
> @@ -33,16 +36,89 @@ union semun
> struct seminfo *__buf; /* buffer for IPC_INFO */
> };
>
> -#ifndef DEFAULT_VERSION
> -# ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T
> -# define DEFAULT_VERSION GLIBC_2_2
> +#if __IPC_TIME64 == 0
> +# define semun64 semun
> +typedef union semun semctl_arg_t;
> +#else
> +# include <struct_kernel_semid64_ds.h>
> +
> +union ksemun64
> +{
> + int val;
> + struct kernel_semid64_ds *buf;
> + unsigned short int *array;
> + struct seminfo *__buf;
> +};
OK. Kernel side.
> +
> +# if __TIMESIZE == 64
> +# define semun64 semun
> # else
> -# define DEFAULT_VERSION GLIBC_2_31
> +/* The struct used when __semctl64 is called. */
> +union semun64
> +{
> + int val;
> + struct __semid64_ds *buf;
> + unsigned short int *array;
> + struct seminfo *__buf;
> +};
OK. User side.
> # endif
> +
> +static void
> +semid64_to_ksemid64 (const struct __semid64_ds *semid64,
> + struct kernel_semid64_ds *ksemid)
> +{
> + ksemid->sem_perm = semid64->sem_perm;
> + ksemid->sem_otime = semid64->sem_otime;
> + ksemid->sem_otime_high = semid64->sem_otime >> 32;
> + ksemid->sem_ctime = semid64->sem_ctime;
> + ksemid->sem_ctime_high = semid64->sem_ctime >> 32;
> + ksemid->sem_nsems = semid64->sem_nsems;
> +}
OK. Copy to kernel.
> +
> +static void
> +ksemid64_to_semid64 (const struct kernel_semid64_ds *ksemid,
> + struct __semid64_ds *semid64)
> +{
> + semid64->sem_perm = ksemid->sem_perm;
> + semid64->sem_otime = ksemid->sem_otime
> + | ((__time64_t) ksemid->sem_otime_high << 32);
> + semid64->sem_ctime = ksemid->sem_ctime
> + | ((__time64_t) ksemid->sem_ctime_high << 32);
> + semid64->sem_nsems = ksemid->sem_nsems;
> +}
OK. Copy to user (full 64-bit wide).
> +
> +static union ksemun64
> +semun64_to_ksemun64 (int cmd, union semun64 semun64,
> + struct kernel_semid64_ds *buf)
> +{
> + union ksemun64 r = { 0 };
> + switch (cmd)
> + {
> + case SETVAL:
> + r.val = semun64.val;
> + break;
> + case GETALL:
> + case SETALL:
> + r.array = semun64.array;
> + break;
> + case IPC_STAT:
> + case IPC_SET:
> + r.buf = buf;
> + semid64_to_ksemid64 (semun64.buf, r.buf);
> + break;
> + case IPC_INFO:
> + case SEM_INFO:
> + r.__buf = semun64.__buf;
> + break;
> + }
> + return r;
> +}
OK. Union copy.
> +
> +typedef union ksemun64 semctl_arg_t;
> #endif
>
> static int
> -semctl_syscall (int semid, int semnum, int cmd, union semun arg)
> +semctl_syscall (int semid, int semnum, int cmd, semctl_arg_t arg)
> {
> #ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
> return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64,
> @@ -53,15 +129,15 @@ semctl_syscall (int semid, int semnum, int cmd, union semun arg)
> #endif
> }
>
> +/* POSIX states ipc_perm mode should have type of mode_t. */
> +_Static_assert (sizeof ((struct semid_ds){0}.sem_perm.mode)
> + == sizeof (mode_t),
> + "sizeof (msqid_ds.msg_perm.mode) != sizeof (mode_t)");
OK.
> +
> int
> -__new_semctl (int semid, int semnum, int cmd, ...)
> +__semctl64 (int semid, int semnum, int cmd, ...)
> {
> - /* POSIX states ipc_perm mode should have type of mode_t. */
> - _Static_assert (sizeof ((struct semid_ds){0}.sem_perm.mode)
> - == sizeof (mode_t),
> - "sizeof (msqid_ds.msg_perm.mode) != sizeof (mode_t)");
> -
> - union semun arg = { 0 };
> + union semun64 arg64 = { 0 };
> va_list ap;
>
> /* Get the argument only if required. */
> @@ -76,44 +152,151 @@ __new_semctl (int semid, int semnum, int cmd, ...)
> case IPC_INFO: /* arg.__buf */
> case SEM_INFO:
> va_start (ap, cmd);
> - arg = va_arg (ap, union semun);
> + arg64 = va_arg (ap, union semun64);
> va_end (ap);
> break;
> }
>
> -#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
> - struct semid_ds tmpds;
> - if (cmd == IPC_SET)
> - {
> - tmpds = *arg.buf;
> - tmpds.sem_perm.mode *= 0x10000U;
> - arg.buf = &tmpds;
> - }
> +#if __IPC_TIME64
> + struct kernel_semid64_ds ksemid;
> + union ksemun64 ksemun = semun64_to_ksemun64 (cmd, arg64, &ksemid);
> + union ksemun64 arg = ksemun;
> +#else
> + union semun arg = arg64;
> #endif
>
> int ret = semctl_syscall (semid, semnum, cmd, arg);
> + if (ret < 0)
> + return ret;
>
> - if (ret >= 0)
> + switch (cmd)
> {
> - switch (cmd)
> - {
> - case IPC_STAT:
> - case SEM_STAT:
> - case SEM_STAT_ANY:
> + case IPC_STAT:
> + case SEM_STAT:
> + case SEM_STAT_ANY:
> #ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
> - arg.buf->sem_perm.mode >>= 16;
> + arg.buf->sem_perm.mode >>= 16;
> #else
> - /* Old Linux kernel versions might not clear the mode padding. */
> - if (sizeof ((struct semid_ds){0}.sem_perm.mode)
> - != sizeof (__kernel_mode_t))
> - arg.buf->sem_perm.mode &= 0xFFFF;
> + /* Old Linux kernel versions might not clear the mode padding. */
> + if (sizeof ((struct semid_ds){0}.sem_perm.mode)
> + != sizeof (__kernel_mode_t))
> + arg.buf->sem_perm.mode &= 0xFFFF;
> #endif
> - }
> +
> +#if __IPC_TIME64
> + ksemid64_to_semid64 (arg.buf, arg64.buf);
> +#endif
> + }
> +
> + return ret;
> +}
OK.
> +#if __TIMESIZE != 64
> +libc_hidden_def (__semctl64)
> +
> +
> +/* The 64-bit time_t semid_ds version might have a different layout and
> + internal field alignment. */
> +static void
> +semid64_ds_to_semid_ds (struct semid_ds *ds, const struct __semid64_ds *ds64)
> +{
> + ds->sem_perm = ds64->sem_perm;
> + ds->sem_otime = ds64->sem_otime;
> + ds->sem_ctime = ds64->sem_ctime;
> + ds->sem_nsems = ds64->sem_nsems;
> +}
> +
> +static void
> +semid_ds_to_semid64_ds (struct __semid64_ds *ds64, const struct semid_ds *ds)
> +{
> + ds64->sem_perm = ds->sem_perm;
> + ds64->sem_otime = ds->sem_otime
> + | ((__time64_t) ds->__sem_otime_high << 32);
> + ds64->sem_ctime = ds->sem_ctime
> + | ((__time64_t) ds->__sem_ctime_high << 32);
> + ds64->sem_nsems = ds->sem_nsems;
> +}
> +
> +static union semun64
> +semun_to_semun64 (int cmd, union semun semun, struct __semid64_ds *semid64)
> +{
> + union semun64 r = { 0 };
> + switch (cmd)
> + {
> + case SETVAL:
> + r.val = semun.val;
> + break;
> + case GETALL:
> + case SETALL:
> + r.array = semun.array;
> + break;
> + case IPC_STAT:
> + case IPC_SET:
> + r.buf = semid64;
> + semid_ds_to_semid64_ds (r.buf, semun.buf);
> +# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
> + if (cmd == IPC_SET)
> + r.buf->sem_perm.mode *= 0x10000U;
> +# endif
> + break;
> + case IPC_INFO:
> + case SEM_INFO:
> + r.__buf = semun.__buf;
> + break;
> + }
> + return r;
> +}
OK.
> +
> +int
> +__semctl (int semid, int semnum, int cmd, ...)
> +{
> + union semun arg = { 0 };
> +
> + va_list ap;
> +
> + /* Get the argument only if required. */
> + switch (cmd)
> + {
> + case SETVAL: /* arg.val */
> + case GETALL: /* arg.array */
> + case SETALL:
> + case IPC_STAT: /* arg.buf */
> + case IPC_SET:
> + case SEM_STAT:
> + case IPC_INFO: /* arg.__buf */
> + case SEM_INFO:
> + va_start (ap, cmd);
> + arg = va_arg (ap, union semun);
> + va_end (ap);
> + break;
> + }
> +
> + struct __semid64_ds semid64;
> + union semun64 arg64 = semun_to_semun64 (cmd, arg, &semid64);
> +
> + int ret = __semctl64 (semid, semnum, cmd, arg64);
OK. Implement with __semctl64.
> + if (ret < 0)
> + return ret;
> +
> + switch (cmd)
> + {
> + case IPC_STAT:
> + case SEM_STAT:
> + case SEM_STAT_ANY:
> + semid64_ds_to_semid_ds (arg.buf, arg64.buf);
> }
>
> return ret;
> }
> -versioned_symbol (libc, __new_semctl, semctl, DEFAULT_VERSION);
> +#endif
> +
> +#ifndef DEFAULT_VERSION
> +# ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T
> +# define DEFAULT_VERSION GLIBC_2_2
> +# else
> +# define DEFAULT_VERSION GLIBC_2_31
> +# endif
> +#endif
> +versioned_symbol (libc, __semctl, semctl, DEFAULT_VERSION);
>
> #if defined __ASSUME_SYSVIPC_BROKEN_MODE_T \
> && SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_31)
> @@ -121,7 +304,7 @@ int
> attribute_compat_text_section
> __semctl_mode16 (int semid, int semnum, int cmd, ...)
> {
> - union semun arg = { 0 };
> + semctl_arg_t arg = { 0 };
> va_list ap;
>
> /* Get the argument only if required. */
> @@ -136,7 +319,7 @@ __semctl_mode16 (int semid, int semnum, int cmd, ...)
> case IPC_INFO: /* arg.__buf */
> case SEM_INFO:
> va_start (ap, cmd);
> - arg = va_arg (ap, union semun);
> + arg = va_arg (ap, semctl_arg_t);
> va_end (ap);
> break;
> }
> diff --git a/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h
> index 46fcd79fb6..0110c1a940 100644
> --- a/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h
> @@ -25,9 +25,9 @@ struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> #if __TIMESIZE == 32
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved2;
> + __syscall_ulong_t __sem_ctime_high;
OK.
> __time_t sem_ctime; /* last time changed by semctl() */
> #else
> __time_t sem_otime; /* last semop() time */
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..8c4697f9ab
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime_high;
> + unsigned long sem_otime;
> + unsigned long sem_ctime_high;
> + unsigned long sem_ctime;
OK. Matches sparc32.
> + unsigned long sem_nsems;
> + unsigned long __unused1;
> + unsigned long __unused2;
> +};
> diff --git a/sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h b/sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h
> new file mode 100644
> index 0000000000..f9edf0f76f
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/struct_kernel_semid64_ds.h
> @@ -0,0 +1,12 @@
> +/* Analogous to kernel struct semid64_ds used on semctl. */
> +struct kernel_semid64_ds
> +{
> + struct ipc_perm sem_perm;
> + unsigned long sem_otime;
> + unsigned long sem_otime_high;
> + unsigned long sem_ctime;
> + unsigned long sem_ctime_high;
> + unsigned long sem_nsems;
> + unsigned long __unused1;
> + unsigned long __unused2;
> +};
> diff --git a/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h b/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h
> index f7ec89d115..c3f2fde9fd 100644
> --- a/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h
> +++ b/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h
> @@ -25,9 +25,9 @@ struct semid_ds
> {
> struct ipc_perm sem_perm; /* operation permission struct */
> __time_t sem_otime; /* last semop() time */
> - __syscall_ulong_t __glibc_reserved1;
> + __syscall_ulong_t __sem_otime_high;
> __time_t sem_ctime; /* last time changed by semctl() */
> - __syscall_ulong_t __glibc_reserved2;
> + __syscall_ulong_t __sem_ctime_high;
> __syscall_ulong_t sem_nsems; /* number of semaphores in set */
> __syscall_ulong_t __glibc_reserved3;
> __syscall_ulong_t __glibc_reserved4;
>
OK.
On Tue, Jul 7, 2020 at 12:32 AM Carlos O'Donell <carlos@redhat.com> wrote:
>
> On 6/30/20 3:24 PM, Adhemerval Zanella via Libc-alpha wrote:
>
> OK for master with comment cleanups. Very clean, very easy to understand
> patch. I should finish the other 6 patches tomorrow morning.
Ack, I have included all your comment suggestions changes.
>
> No regressions on x86_64 or i686 (I did see the new rseq regression
> for posix/tst-affinity-static though).
>
> Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> Tested-by: Carlos O'Donell <carlos@redhat.com>
Thanks!
@@ -5,5 +5,12 @@
__typeof__ (semtimedop) __semtimedop attribute_hidden;
+#if __TIMESIZE == 64
+# define __semctl64 __semctl
+#else
+extern int __semctl64 (int semid, int semnum, int cmd, ...);
+libc_hidden_proto (__semctl64);
+#endif
+
# endif
#endif
new file mode 100644
@@ -0,0 +1,33 @@
+/* Generic implementation of the semaphore struct semid64_ds.
+ Copyright (C) 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
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef _SYS_SEM_H
+# error "Never include <bits/types/struct_semid_ds.h> directly; use <sys/sem.h> instead."
+#endif
+
+#if __TIMESIZE == 64
+# define __semid64_ds semid_ds
+#else
+struct __semid64_ds
+{
+ struct ipc_perm sem_perm; /* operation permission struct */
+ __time64_t sem_otime; /* last semop() time */
+ __time64_t sem_ctime; /* last time changed by semctl() */
+ __syscall_ulong_t sem_nsems; /* number of semaphores in set */
+};
+#endif
@@ -21,26 +21,19 @@
#endif
/* Data structure describing a set of semaphores. */
-#if __TIMESIZE == 32
struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
+#if __TIMESIZE == 32
__time_t sem_otime; /* last semop() time */
- __syscall_ulong_t __glibc_reserved1;
+ __syscall_ulong_t __sem_otime_high;
__time_t sem_ctime; /* last time changed by semctl() */
- __syscall_ulong_t __glibc_reserved2;
- __syscall_ulong_t sem_nsems; /* number of semaphores in set */
- __syscall_ulong_t __glibc_reserved3;
- __syscall_ulong_t __glibc_reserved4;
-};
+ __syscall_ulong_t __sem_ctime_high;
#else
-struct semid_ds
-{
- struct ipc_perm sem_perm; /* operation permission struct */
- __time_t sem_otime; /* last semop() time */
- __time_t sem_ctime; /* last time changed by semctl() */
- __syscall_ulong_t sem_nsems; /* number of semaphores in set */
+ __time_t sem_otime;
+ __time_t sem_ctime;
+#endif
+ __syscall_ulong_t sem_nsems; /* number of semaphores in set */
__syscall_ulong_t __glibc_reserved3;
__syscall_ulong_t __glibc_reserved4;
};
-#endif
@@ -21,16 +21,14 @@
#endif
/* Data structure describing a set of semaphores. */
-#if __TIMESIZE == 32
struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
- __syscall_ulong_t __glibc_reserved1;
+ __syscall_ulong_t __sem_otime_high;
__time_t sem_otime; /* last semop() time */
- __syscall_ulong_t __glibc_reserved2;
+ __syscall_ulong_t __sem_ctime_high;
__time_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
new file mode 100644
@@ -0,0 +1,12 @@
+/* Analogous to kernel struct semid64_ds used on semctl. */
+struct kernel_semid64_ds
+{
+ struct ipc_perm sem_perm;
+ unsigned long sem_otime_high;
+ unsigned long sem_otime;
+ unsigned long sem_ctime_high;
+ unsigned long sem_ctime;
+ unsigned long sem_nsems;
+ unsigned long __ununsed1;
+ unsigned long __ununsed2;
+};
new file mode 100644
@@ -0,0 +1,12 @@
+/* Analogous to kernel struct semid64_ds used on semctl. */
+struct kernel_semid64_ds
+{
+ struct ipc_perm sem_perm;
+ unsigned long sem_otime;
+ unsigned long sem_otime_high;
+ unsigned long sem_ctime;
+ unsigned long sem_ctime_high;
+ __syscall_ulong_t sem_nsems;
+ __syscall_ulong_t __unused3;
+ __syscall_ulong_t __unused4;
+};
@@ -53,4 +53,14 @@ struct __old_ipc_perm
#define SEMTIMEDOP_IPC_ARGS(__nsops, __sops, __timeout) \
(__nsops), 0, (__sops), (__timeout)
+/* Linux SysV ipc does not provide new syscalls for 64-bit time support on
+ 32-bit architectures, but rather split the timestamps on previous unused
+ fields. */
+#if (__WORDSIZE == 32 \
+ && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32))
+# define __IPC_TIME64 1
+#else
+# define __IPC_TIME64 0
+#endif
+
#include <ipc_ops.h>
@@ -27,6 +27,6 @@ struct semid_ds
__time_t sem_otime; /* last semop() time */
__time_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;
+ __syscall_ulong_t __sem_otime_high;
+ __syscall_ulong_t __sem_ctime_high;
};
new file mode 100644
@@ -0,0 +1,10 @@
+/* Analogous to kernel struct semid64_ds used on semctl. */
+struct kernel_semid64_ds
+{
+ struct ipc_perm sem_perm;
+ unsigned long sem_otime;
+ unsigned long sem_ctime;
+ unsigned long sem_nsems;
+ unsigned long sem_otime_high;
+ unsigned long sem_ctime_high;
+};
@@ -25,9 +25,9 @@ struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
#if __TIMESIZE == 32
- __syscall_ulong_t __glibc_reserved1;
+ __syscall_ulong_t __sem_otime_high;
__time_t sem_otime; /* last semop() time */
- __syscall_ulong_t __glibc_reserved2;
+ __syscall_ulong_t __sem_ctime_high;
__time_t sem_ctime; /* last time changed by semctl() */
#else
__time_t sem_otime; /* last semop() time */
new file mode 100644
@@ -0,0 +1,12 @@
+/* Analogous to kernel struct semid64_ds used on semctl. */
+struct kernel_semid64_ds
+{
+ struct ipc_perm sem_perm;
+ unsigned long sem_otime_high;
+ unsigned long sem_otime;
+ unsigned long sem_ctime_high;
+ unsigned long sem_ctime;
+ unsigned long sem_nsems;
+ unsigned long __unused3;
+ unsigned long __unused4;
+};
@@ -21,10 +21,13 @@
#include <ipc_priv.h>
#include <sysdep.h>
#include <shlib-compat.h>
-#include <errno.h>
-#include <linux/posix_types.h> /* For __kernel_mode_t. */
+#include <bits/types/struct_semid64_ds.h> /* For __semid64_ds. */
+#include <linux/posix_types.h> /* For __kernel_mode_t. */
-/* Define a `union semun' suitable for Linux here. */
+/* The struct used to issue the syscall. For architecture that assume
+ 64-bit time as default (!__ASSUME_TIME64_SYSCALLS) the syscall will
+ split the resulting 64-bit sem_{o,c}time in two fields (__sem_{o,c}time
+ and __sem_{o,c}time_hi). */
union semun
{
int val; /* value for SETVAL */
@@ -33,16 +36,89 @@ union semun
struct seminfo *__buf; /* buffer for IPC_INFO */
};
-#ifndef DEFAULT_VERSION
-# ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T
-# define DEFAULT_VERSION GLIBC_2_2
+#if __IPC_TIME64 == 0
+# define semun64 semun
+typedef union semun semctl_arg_t;
+#else
+# include <struct_kernel_semid64_ds.h>
+
+union ksemun64
+{
+ int val;
+ struct kernel_semid64_ds *buf;
+ unsigned short int *array;
+ struct seminfo *__buf;
+};
+
+# if __TIMESIZE == 64
+# define semun64 semun
# else
-# define DEFAULT_VERSION GLIBC_2_31
+/* The struct used when __semctl64 is called. */
+union semun64
+{
+ int val;
+ struct __semid64_ds *buf;
+ unsigned short int *array;
+ struct seminfo *__buf;
+};
# endif
+
+static void
+semid64_to_ksemid64 (const struct __semid64_ds *semid64,
+ struct kernel_semid64_ds *ksemid)
+{
+ ksemid->sem_perm = semid64->sem_perm;
+ ksemid->sem_otime = semid64->sem_otime;
+ ksemid->sem_otime_high = semid64->sem_otime >> 32;
+ ksemid->sem_ctime = semid64->sem_ctime;
+ ksemid->sem_ctime_high = semid64->sem_ctime >> 32;
+ ksemid->sem_nsems = semid64->sem_nsems;
+}
+
+static void
+ksemid64_to_semid64 (const struct kernel_semid64_ds *ksemid,
+ struct __semid64_ds *semid64)
+{
+ semid64->sem_perm = ksemid->sem_perm;
+ semid64->sem_otime = ksemid->sem_otime
+ | ((__time64_t) ksemid->sem_otime_high << 32);
+ semid64->sem_ctime = ksemid->sem_ctime
+ | ((__time64_t) ksemid->sem_ctime_high << 32);
+ semid64->sem_nsems = ksemid->sem_nsems;
+}
+
+static union ksemun64
+semun64_to_ksemun64 (int cmd, union semun64 semun64,
+ struct kernel_semid64_ds *buf)
+{
+ union ksemun64 r = { 0 };
+ switch (cmd)
+ {
+ case SETVAL:
+ r.val = semun64.val;
+ break;
+ case GETALL:
+ case SETALL:
+ r.array = semun64.array;
+ break;
+ case IPC_STAT:
+ case IPC_SET:
+ r.buf = buf;
+ semid64_to_ksemid64 (semun64.buf, r.buf);
+ break;
+ case IPC_INFO:
+ case SEM_INFO:
+ r.__buf = semun64.__buf;
+ break;
+ }
+ return r;
+}
+
+typedef union ksemun64 semctl_arg_t;
#endif
static int
-semctl_syscall (int semid, int semnum, int cmd, union semun arg)
+semctl_syscall (int semid, int semnum, int cmd, semctl_arg_t arg)
{
#ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
return INLINE_SYSCALL_CALL (semctl, semid, semnum, cmd | __IPC_64,
@@ -53,15 +129,15 @@ semctl_syscall (int semid, int semnum, int cmd, union semun arg)
#endif
}
+/* POSIX states ipc_perm mode should have type of mode_t. */
+_Static_assert (sizeof ((struct semid_ds){0}.sem_perm.mode)
+ == sizeof (mode_t),
+ "sizeof (msqid_ds.msg_perm.mode) != sizeof (mode_t)");
+
int
-__new_semctl (int semid, int semnum, int cmd, ...)
+__semctl64 (int semid, int semnum, int cmd, ...)
{
- /* POSIX states ipc_perm mode should have type of mode_t. */
- _Static_assert (sizeof ((struct semid_ds){0}.sem_perm.mode)
- == sizeof (mode_t),
- "sizeof (msqid_ds.msg_perm.mode) != sizeof (mode_t)");
-
- union semun arg = { 0 };
+ union semun64 arg64 = { 0 };
va_list ap;
/* Get the argument only if required. */
@@ -76,44 +152,151 @@ __new_semctl (int semid, int semnum, int cmd, ...)
case IPC_INFO: /* arg.__buf */
case SEM_INFO:
va_start (ap, cmd);
- arg = va_arg (ap, union semun);
+ arg64 = va_arg (ap, union semun64);
va_end (ap);
break;
}
-#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
- struct semid_ds tmpds;
- if (cmd == IPC_SET)
- {
- tmpds = *arg.buf;
- tmpds.sem_perm.mode *= 0x10000U;
- arg.buf = &tmpds;
- }
+#if __IPC_TIME64
+ struct kernel_semid64_ds ksemid;
+ union ksemun64 ksemun = semun64_to_ksemun64 (cmd, arg64, &ksemid);
+ union ksemun64 arg = ksemun;
+#else
+ union semun arg = arg64;
#endif
int ret = semctl_syscall (semid, semnum, cmd, arg);
+ if (ret < 0)
+ return ret;
- if (ret >= 0)
+ switch (cmd)
{
- switch (cmd)
- {
- case IPC_STAT:
- case SEM_STAT:
- case SEM_STAT_ANY:
+ case IPC_STAT:
+ case SEM_STAT:
+ case SEM_STAT_ANY:
#ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
- arg.buf->sem_perm.mode >>= 16;
+ arg.buf->sem_perm.mode >>= 16;
#else
- /* Old Linux kernel versions might not clear the mode padding. */
- if (sizeof ((struct semid_ds){0}.sem_perm.mode)
- != sizeof (__kernel_mode_t))
- arg.buf->sem_perm.mode &= 0xFFFF;
+ /* Old Linux kernel versions might not clear the mode padding. */
+ if (sizeof ((struct semid_ds){0}.sem_perm.mode)
+ != sizeof (__kernel_mode_t))
+ arg.buf->sem_perm.mode &= 0xFFFF;
#endif
- }
+
+#if __IPC_TIME64
+ ksemid64_to_semid64 (arg.buf, arg64.buf);
+#endif
+ }
+
+ return ret;
+}
+#if __TIMESIZE != 64
+libc_hidden_def (__semctl64)
+
+
+/* The 64-bit time_t semid_ds version might have a different layout and
+ internal field alignment. */
+static void
+semid64_ds_to_semid_ds (struct semid_ds *ds, const struct __semid64_ds *ds64)
+{
+ ds->sem_perm = ds64->sem_perm;
+ ds->sem_otime = ds64->sem_otime;
+ ds->sem_ctime = ds64->sem_ctime;
+ ds->sem_nsems = ds64->sem_nsems;
+}
+
+static void
+semid_ds_to_semid64_ds (struct __semid64_ds *ds64, const struct semid_ds *ds)
+{
+ ds64->sem_perm = ds->sem_perm;
+ ds64->sem_otime = ds->sem_otime
+ | ((__time64_t) ds->__sem_otime_high << 32);
+ ds64->sem_ctime = ds->sem_ctime
+ | ((__time64_t) ds->__sem_ctime_high << 32);
+ ds64->sem_nsems = ds->sem_nsems;
+}
+
+static union semun64
+semun_to_semun64 (int cmd, union semun semun, struct __semid64_ds *semid64)
+{
+ union semun64 r = { 0 };
+ switch (cmd)
+ {
+ case SETVAL:
+ r.val = semun.val;
+ break;
+ case GETALL:
+ case SETALL:
+ r.array = semun.array;
+ break;
+ case IPC_STAT:
+ case IPC_SET:
+ r.buf = semid64;
+ semid_ds_to_semid64_ds (r.buf, semun.buf);
+# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
+ if (cmd == IPC_SET)
+ r.buf->sem_perm.mode *= 0x10000U;
+# endif
+ break;
+ case IPC_INFO:
+ case SEM_INFO:
+ r.__buf = semun.__buf;
+ break;
+ }
+ return r;
+}
+
+int
+__semctl (int semid, int semnum, int cmd, ...)
+{
+ union semun arg = { 0 };
+
+ va_list ap;
+
+ /* Get the argument only if required. */
+ switch (cmd)
+ {
+ case SETVAL: /* arg.val */
+ case GETALL: /* arg.array */
+ case SETALL:
+ case IPC_STAT: /* arg.buf */
+ case IPC_SET:
+ case SEM_STAT:
+ case IPC_INFO: /* arg.__buf */
+ case SEM_INFO:
+ va_start (ap, cmd);
+ arg = va_arg (ap, union semun);
+ va_end (ap);
+ break;
+ }
+
+ struct __semid64_ds semid64;
+ union semun64 arg64 = semun_to_semun64 (cmd, arg, &semid64);
+
+ int ret = __semctl64 (semid, semnum, cmd, arg64);
+ if (ret < 0)
+ return ret;
+
+ switch (cmd)
+ {
+ case IPC_STAT:
+ case SEM_STAT:
+ case SEM_STAT_ANY:
+ semid64_ds_to_semid_ds (arg.buf, arg64.buf);
}
return ret;
}
-versioned_symbol (libc, __new_semctl, semctl, DEFAULT_VERSION);
+#endif
+
+#ifndef DEFAULT_VERSION
+# ifndef __ASSUME_SYSVIPC_BROKEN_MODE_T
+# define DEFAULT_VERSION GLIBC_2_2
+# else
+# define DEFAULT_VERSION GLIBC_2_31
+# endif
+#endif
+versioned_symbol (libc, __semctl, semctl, DEFAULT_VERSION);
#if defined __ASSUME_SYSVIPC_BROKEN_MODE_T \
&& SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_31)
@@ -121,7 +304,7 @@ int
attribute_compat_text_section
__semctl_mode16 (int semid, int semnum, int cmd, ...)
{
- union semun arg = { 0 };
+ semctl_arg_t arg = { 0 };
va_list ap;
/* Get the argument only if required. */
@@ -136,7 +319,7 @@ __semctl_mode16 (int semid, int semnum, int cmd, ...)
case IPC_INFO: /* arg.__buf */
case SEM_INFO:
va_start (ap, cmd);
- arg = va_arg (ap, union semun);
+ arg = va_arg (ap, semctl_arg_t);
va_end (ap);
break;
}
@@ -25,9 +25,9 @@ struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
#if __TIMESIZE == 32
- __syscall_ulong_t __glibc_reserved1;
+ __syscall_ulong_t __sem_otime_high;
__time_t sem_otime; /* last semop() time */
- __syscall_ulong_t __glibc_reserved2;
+ __syscall_ulong_t __sem_ctime_high;
__time_t sem_ctime; /* last time changed by semctl() */
#else
__time_t sem_otime; /* last semop() time */
new file mode 100644
@@ -0,0 +1,12 @@
+/* Analogous to kernel struct semid64_ds used on semctl. */
+struct kernel_semid64_ds
+{
+ struct ipc_perm sem_perm;
+ unsigned long sem_otime_high;
+ unsigned long sem_otime;
+ unsigned long sem_ctime_high;
+ unsigned long sem_ctime;
+ unsigned long sem_nsems;
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
new file mode 100644
@@ -0,0 +1,12 @@
+/* Analogous to kernel struct semid64_ds used on semctl. */
+struct kernel_semid64_ds
+{
+ struct ipc_perm sem_perm;
+ unsigned long sem_otime;
+ unsigned long sem_otime_high;
+ unsigned long sem_ctime;
+ unsigned long sem_ctime_high;
+ unsigned long sem_nsems;
+ unsigned long __unused1;
+ unsigned long __unused2;
+};
@@ -25,9 +25,9 @@ struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
__time_t sem_otime; /* last semop() time */
- __syscall_ulong_t __glibc_reserved1;
+ __syscall_ulong_t __sem_otime_high;
__time_t sem_ctime; /* last time changed by semctl() */
- __syscall_ulong_t __glibc_reserved2;
+ __syscall_ulong_t __sem_ctime_high;
__syscall_ulong_t sem_nsems; /* number of semaphores in set */
__syscall_ulong_t __glibc_reserved3;
__syscall_ulong_t __glibc_reserved4;