[RFC PATCH 3/4] linux: consistently use time64 syscalls if available
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Wed Nov 11 12:09:02 GMT 2026
On 10/11/26 11:51, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> The futex() and ppoll() syscalls exist in time32 and time64
> variants because of the optional timeout. A few internal functions
> call these without a timeout, where either version works, and on
> __WORDSIZE=32/__TIMESIZE=64 architectures, this ends up using the
> time64 variants, whiel on __TIMESIZE=32 architectures, these use the
> time32 variants.
s/whiel/while/
The libc parts (not-cancel.h, pause.c, poll.c) look right to me.
The test changes have three problems:
>
> When running on a Linux kernel that is configured without the
> time32 syscalls (CONFIG_COMPAT_32BIT_TIME=n), this fails, even when
> __ASSUME_TIME64_SYSCALLS is set and all other syscalls use the time64
> versions.
>
> Change these to always pick the time64 version when
> __ASSUME_TIME64_SYSCALLS is enabled, for consistency and to allow running
> with CONFIG_COMPAT_32BIT_TIME=n on __TIMESIZE=32 architectures.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> sysdeps/unix/sysv/linux/i386/tst-bz21269.c | 4 ++++
> sysdeps/unix/sysv/linux/not-cancel.h | 4 ++++
> sysdeps/unix/sysv/linux/pause.c | 2 ++
> sysdeps/unix/sysv/linux/poll.c | 12 ++++++++++++
> sysdeps/unix/sysv/linux/tst-clone3-internal.c | 6 +++---
> sysdeps/unix/sysv/linux/tst-clone3.c | 6 +++---
> 6 files changed, 28 insertions(+), 6 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
> index fbf7fe01dae8..0d490e3fd6b9 100644
> --- a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
> +++ b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
> @@ -66,7 +66,11 @@ static int
> futex (int *uaddr, int futex_op, int val, void *timeout, int *uaddr2,
> int val3)
> {
> +#if defined(__ASSUME_TIME64_SYSCALLS) && defined(SYS_futex_time64)
> + return syscall (SYS_futex_time64, uaddr, futex_op, val, timeout, uaddr2, val3);
> +#else
> return syscall (SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
> +#endif
> }
>
> static void
> diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
> index 35951a3caebe..6268228449cd 100644
> --- a/sysdeps/unix/sysv/linux/not-cancel.h
> +++ b/sysdeps/unix/sysv/linux/not-cancel.h
> @@ -99,7 +99,11 @@ __getrandom_nocancel_nostatus_direct (void *buf, size_t buflen, unsigned int fla
> static inline int
> __poll_infinity_nocancel (struct pollfd *fds, nfds_t nfds)
> {
> +#if defined(__ASSUME_TIME64_SYSCALLS) && defined(__NR_ppoll_time64)
> + return INLINE_SYSCALL_CALL (ppoll_time64, fds, nfds, NULL, NULL, 0);
> +#else
> return INLINE_SYSCALL_CALL (ppoll, fds, nfds, NULL, NULL, 0);
> +#endif
> }
>
> #endif /* NOT_CANCEL_H */
> diff --git a/sysdeps/unix/sysv/linux/pause.c b/sysdeps/unix/sysv/linux/pause.c
> index 01a23d8fa6a3..ffe7fba41de6 100644
> --- a/sysdeps/unix/sysv/linux/pause.c
> +++ b/sysdeps/unix/sysv/linux/pause.c
> @@ -27,6 +27,8 @@ __libc_pause (void)
> {
> #ifdef __NR_pause
> return SYSCALL_CANCEL (pause);
> +#elif defined(__ASSUME_TIME64_SYSCALLS) && defined(__NR_ppoll_time64)
> + return SYSCALL_CANCEL (ppoll_time64, NULL, 0, NULL, NULL);
> #else
> return SYSCALL_CANCEL (ppoll, NULL, 0, NULL, NULL);
> #endif
> diff --git a/sysdeps/unix/sysv/linux/poll.c b/sysdeps/unix/sysv/linux/poll.c
> index 504cb444c44e..c1e45d29a50c 100644
> --- a/sysdeps/unix/sysv/linux/poll.c
> +++ b/sysdeps/unix/sysv/linux/poll.c
> @@ -27,6 +27,18 @@ __poll (struct pollfd *fds, nfds_t nfds, int timeout)
> {
> #ifdef __NR_poll
> return SYSCALL_CANCEL (poll, fds, nfds, timeout);
> +#elif defined(__ASSUME_TIME64_SYSCALLS) && defined(__NR_ppoll_time64)
> + struct __timespec64 timeout_ts;
> + struct __timespec64 *timeout_ts_p = NULL;
> +
> + if (timeout >= 0)
> + {
> + timeout_ts.tv_sec = timeout / 1000;
> + timeout_ts.tv_nsec = (timeout % 1000) * 1000000;
> + timeout_ts_p = &timeout_ts;
> + }
> +
> + return SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout_ts_p, NULL, 0);
The could avoid duplicating the timeout conversion by using the usual:
#ifndef __NR_ppoll_time64
# define __NR_ppoll_time64 __NR_ppoll
#endif
It is fine either way.
> #else
> struct timespec timeout_ts;
> struct timespec *timeout_ts_p = NULL;
> diff --git a/sysdeps/unix/sysv/linux/tst-clone3-internal.c b/sysdeps/unix/sysv/linux/tst-clone3-internal.c
> index a24c976f299b..db08214c5bcd 100644
> --- a/sysdeps/unix/sysv/linux/tst-clone3-internal.c
> +++ b/sysdeps/unix/sysv/linux/tst-clone3-internal.c
> @@ -56,10 +56,10 @@ f (void *a)
> static inline int
> futex_wait (_Atomic int *futexp, int val)
> {
> -#ifdef __NR_futex
> - return syscall (__NR_futex, futexp, FUTEX_WAIT, val);
> -#else
> +#if defined(__ASSUME_TIME64_SYSCALLS) && defined(__NR_futex_time64)
> return syscall (__NR_futex_time64, futexp, FUTEX_WAIT, val);
> +#else
> + return syscall (__NR_futex, futexp, FUTEX_WAIT, val);
> #endif
> }
>
> diff --git a/sysdeps/unix/sysv/linux/tst-clone3.c b/sysdeps/unix/sysv/linux/tst-clone3.c
> index 9b41e84ee6d6..f8008dddd791 100644
> --- a/sysdeps/unix/sysv/linux/tst-clone3.c
> +++ b/sysdeps/unix/sysv/linux/tst-clone3.c
> @@ -56,10 +56,10 @@ f (void *a)
> static inline int
> futex_wait (_Atomic int *futexp, int val)
> {
> -#ifdef __NR_futex
> - return syscall (__NR_futex, futexp, FUTEX_WAIT, val);
> -#else
> +#if defined(__ASSUME_TIME64_SYSCALLS) && defined(__NR_futex_time64
Missing ')'. More importantly, tst-clone3.c and i386/tst-bz21269.c are regular tests
and do not include <kernel-features.h>, so __ASSUME_TIME64_SYSCALLS is never defined
there.
The clone3 needs Linux 5.3, so when tst-clone3* reach futex_wait, futex_time64
always exists.
> return syscall (__NR_futex_time64, futexp, FUTEX_WAIT, val);
> +#else
> + return syscall (__NR_futex, futexp, FUTEX_WAIT, val);
> #endif
> }
>
More information about the Libc-alpha
mailing list