[PATCH v2 3/5] linux: consistently use time64 syscalls if available

Arnd Bergmann arnd@kernel.org
Mon Nov 16 12:08:55 GMT 2026


From: Arnd Bergmann <arnd@arndb.de>

Prefer the 64 bit time_t for the futex and ppoll internal syscall
usages.

The tests that call futex directly cannot check
__ASSUME_TIME64_SYSCALLS, because regular tests do not include
kernel-features.h.  Since clone3 requires Linux 5.3, so tst-clone3 and
tst-clone3-internal assume futex_time64.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 sysdeps/unix/sysv/linux/i386/tst-bz21269.c    |  6 ++++++
 sysdeps/unix/sysv/linux/not-cancel.h          |  4 ++++
 sysdeps/unix/sysv/linux/pause.c               |  2 ++
 sysdeps/unix/sysv/linux/poll.c                | 13 +++++++++++++
 sysdeps/unix/sysv/linux/tst-clone3-internal.c |  7 ++++---
 sysdeps/unix/sysv/linux/tst-clone3.c          |  7 ++++---
 6 files changed, 33 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..4cd1faa4b29f 100644
--- a/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
+++ b/sysdeps/unix/sysv/linux/i386/tst-bz21269.c
@@ -66,6 +66,12 @@ static int
 futex (int *uaddr, int futex_op, int val, void *timeout, int *uaddr2,
 	int val3)
 {
+#ifdef SYS_futex_time64
+  long int r = syscall (SYS_futex_time64, uaddr, futex_op, val, timeout,
+			uaddr2, val3);
+  if (r != -1 || errno != ENOSYS)
+    return r;
+#endif
   return syscall (SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
 }
 
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..32dd96a8ad7e 100644
--- a/sysdeps/unix/sysv/linux/poll.c
+++ b/sysdeps/unix/sysv/linux/poll.c
@@ -28,8 +28,17 @@ __poll (struct pollfd *fds, nfds_t nfds, int timeout)
 #ifdef __NR_poll
   return SYSCALL_CANCEL (poll, fds, nfds, timeout);
 #else
+  /* The timeout always fits in the time32 ppoll.  */
+# ifdef __ASSUME_TIME64_SYSCALLS
+#  ifndef __NR_ppoll_time64
+#   define __NR_ppoll_time64 __NR_ppoll
+#  endif
+  struct __timespec64 timeout_ts;
+  struct __timespec64 *timeout_ts_p = NULL;
+# else
   struct timespec timeout_ts;
   struct timespec *timeout_ts_p = NULL;
+# endif
 
   if (timeout >= 0)
     {
@@ -38,7 +47,11 @@ __poll (struct pollfd *fds, nfds_t nfds, int timeout)
       timeout_ts_p = &timeout_ts;
     }
 
+# ifdef __ASSUME_TIME64_SYSCALLS
+  return SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout_ts_p, NULL, 0);
+# else
   return SYSCALL_CANCEL (ppoll, fds, nfds, timeout_ts_p, NULL, 0);
+# endif
 #endif
 }
 libc_hidden_def (__poll)
diff --git a/sysdeps/unix/sysv/linux/tst-clone3-internal.c b/sysdeps/unix/sysv/linux/tst-clone3-internal.c
index a24c976f299b..2aaccbfc19fe 100644
--- a/sysdeps/unix/sysv/linux/tst-clone3-internal.c
+++ b/sysdeps/unix/sysv/linux/tst-clone3-internal.c
@@ -56,10 +56,11 @@ f (void *a)
 static inline int
 futex_wait (_Atomic int *futexp, int val)
 {
-#ifdef __NR_futex
-  return syscall (__NR_futex, futexp, FUTEX_WAIT, val);
+  /* clone3 needs Linux 5.3, so assume futex_time64 (Linux 5.1).  */
+#ifdef __NR_futex_time64
+  return syscall (__NR_futex_time64, futexp, FUTEX_WAIT, val, NULL);
 #else
-  return syscall (__NR_futex_time64, futexp, FUTEX_WAIT, val);
+  return syscall (__NR_futex, futexp, FUTEX_WAIT, val, NULL);
 #endif
 }
 
diff --git a/sysdeps/unix/sysv/linux/tst-clone3.c b/sysdeps/unix/sysv/linux/tst-clone3.c
index 9b41e84ee6d6..5c4136ddcba8 100644
--- a/sysdeps/unix/sysv/linux/tst-clone3.c
+++ b/sysdeps/unix/sysv/linux/tst-clone3.c
@@ -56,10 +56,11 @@ f (void *a)
 static inline int
 futex_wait (_Atomic int *futexp, int val)
 {
-#ifdef __NR_futex
-  return syscall (__NR_futex, futexp, FUTEX_WAIT, val);
+  /* clone3 needs Linux 5.3, so assume futex_time64 (Linux 5.1).  */
+#ifdef __NR_futex_time64
+  return syscall (__NR_futex_time64, futexp, FUTEX_WAIT, val, NULL);
 #else
-  return syscall (__NR_futex_time64, futexp, FUTEX_WAIT, val);
+  return syscall (__NR_futex, futexp, FUTEX_WAIT, val, NULL);
 #endif
 }
 
-- 
2.53.0



More information about the Libc-alpha mailing list