This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v9] y2038: Introduce the __ASSUME_TIME64_SYSCALLS define


From: Lukasz Majewski <lukma@denx.de>

The __ASSUME_TIME64_SYSCALLS macro indicates if the Linux kernel provides
64-bit time syscalls. If __ASSUME_TIME64_SYSCALLS is defined glibc will
only use the *64/_time64 suffixed syscalls.

__ASSUME_TIME64_SYSCALLS is defined when:
 1. __WORDSIZE == 64 - 64-bit time and syscalls have previously been
    supported for 64-bit platforms.

 2. __WORDSIZE == 32 - Since kernel 5.1 a new set of 64-bit time
    syscalls have been added. This provides a 64-bit time ABI to 32-bit
    userspace applications.

    List of new syscalls added to v5.1. kernel (they accept data based on
    struct timespec and timeval with 64 bit tv_sec):

     clock_gettime64
     clock_settime64
     clock_adjtime64
     clock_getres_time64
     clock_nanosleep_time64
     timer_gettime64
     timer_settime64
     timerfd_gettime64
     timerfd_settime64
     utimensat_time64
     pselect6_time64
     ppoll_time64
     io_pgetevents_time64
     recvmmsg_time64
     mq_timedsend_time64
     mq_timedreceive_time64
     semtimedop_time64
     rt_sigtimedwait_time64
     futex_time64
     sched_rr_get_interval_time64

3. __WORDSIZE == 32 && _SYSCALL_WORDSIZE == 64 - a special case for machines
  with ILP32 data model, but already supporting 64 bit time (the 'x32'
  architecture to be precise).

This flag can be removed when glibc's minimal supported kernel version
passes 5.1 as after that all architectures will provide a 64-bit time
syscall.

* sysdeps/unix/sysv/linux/kernel-features.h:
(__ASSUME_TIME64_SYSCALLS): Define.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
v9:
 - Reword the commit message and code comment

 sysdeps/unix/sysv/linux/kernel-features.h | 48 +++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 1518bb52287..24939b8603d 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -139,3 +139,51 @@
    */
 
 #define __ASSUME_CLONE_DEFAULT 1
+
+/* Support for the 64-bit time Linux kernel syscalls.
+
+   This flag indicates support for Linux kernel syscalls using the 64-bit time
+   ABI. It is defined for all 64-bit architectures as they have always
+   supported 64-bit time. It is also defined for all 32-bit architectures when
+   using Linux kernel version 5.1 or newer.
+
+   When the __ASSUME_TIME64_SYSCALLS macro is defined glibc can call, without needing to
+   check at runtime for ENOSYS errors, the *64/time64 suffixed syscalls. These
+   should be #defined to the the unsuffixed versions when required (such as
+   when running on 64-bit systems).
+
+   __ASSUME_TIME64_SYSCALLS macro being defined does not mean that __TIMESIZE is
+   64-bit. In cases where the __TIMESIZE is 64-bit the 64-bit syscalls can be
+   used directly. In cases where __TIMESIZE is 32-bit conversions between the
+   original 32-bit values and the kernel's 64-bit values will need to occur.
+
+   As an example - the syscall to set clock (clock_settime) - if the
+   __ASSUME_TIME64_SYSCALLS macro is defined, it indicates that 64-bit time can
+   be set in the system.
+
+   On systems with __WORDSIZE == 64 the __NR_clock_settime syscall is used
+   to achieve this goal. Systems with __WORDSIZE == 32 use the
+   __NR_clock_settime64 syscall available from Linux version 5.1.
+
+   The __ASSUME_TIME64_SYSCALLS macro is defined for:
+
+   1. 64-bit systems that have always had 64-bit time support (__WORDSIZE == 64).
+
+   2. For x32 architecture, which is a special case in respect to 64-bit
+      time support (it has __WORDSIZE==32 but __TIMESIZE==64)
+
+   3. Systems with __WORDSIZE==32, which gain 64-bit time support
+      with the syscalls added to Linux kernel 5.1.
+
+   4. 32-bit architectures for which support was added in Linux 5.1 or later,
+      or for which the kernel/userspace ABI changed incompatibly in Linux 5.1
+      or later so that there are no syscalls using 32-bit time.
+   */
+
+#include <bits/wordsize.h>
+#if (__WORDSIZE == 64                                                   \
+     || (__WORDSIZE == 32                                               \
+         && (__LINUX_KERNEL_VERSION >= 0x050100                         \
+             || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64))))
+# define __ASSUME_TIME64_SYSCALLS 1
+#endif
-- 
2.22.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]