[RFC PATCH 3/4] linux: consistently use time64 syscalls if available
Arnd Bergmann
arnd@kernel.org
Tue Nov 10 14:51:45 GMT 2026
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.
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);
#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
return syscall (__NR_futex_time64, futexp, FUTEX_WAIT, val);
+#else
+ return syscall (__NR_futex, futexp, FUTEX_WAIT, val);
#endif
}
--
2.53.0
More information about the Libc-alpha
mailing list