]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
y2038: linux: Provide __clock_settime64 implementation
authorLukasz Majewski <lukma@denx.de>
Tue, 24 Sep 2019 12:22:42 +0000 (14:22 +0200)
committerLukasz Majewski <lukma@denx.de>
Wed, 9 Oct 2019 22:17:46 +0000 (00:17 +0200)
This patch provides new __clock_settime64 explicit 64 bit function for
setting the time. Moreover, a 32 bit version - __clock_settime - has been
refactored to internally use __clock_settime64.

The __clock_settime is now supposed to be used on systems still supporting
32 bit time (__TIMESIZE != 64) - hence the necessary conversion to 64 bit
struct timespec.

The new clock_settime64 syscall available from Linux 5.1+ has been used,
when applicable.

In this patch the internal padding (tv_pad) of struct __timespec64 is
left untouched (on systems with __WORDSIZE == 32) as Linux kernel ignores
upper 32 bits of tv_nsec.

Build tests:
- The code has been tested on x86_64/x86 (native compilation):
make PARALLELMFLAGS="-j8" && make xcheck PARALLELMFLAGS="-j8"

- The glibc has been build tested (make PARALLELMFLAGS="-j8") for
x86 (i386), x86_64-x32, and armv7

Run-time tests:
- Run specific tests on ARM/x86 32bit systems (qemu):
  https://github.com/lmajewski/meta-y2038 and run tests:
  https://github.com/lmajewski/y2038-tests/commits/master

- Use of cross-test-ssh.sh for ARM (armv7):
  make PARALLELMFLAGS="-j8" test-wrapper='./cross-test-ssh.sh root@192.168.7.2' xcheck

Linux kernel, headers and minimal kernel version for glibc build test
matrix:
- Linux v5.1 (with clock_settime64) and glibc build with v5.1 as minimal
  kernel version (--enable-kernel="5.1.0")
  The __ASSUME_TIME64_SYSCALLS flag defined.

- Linux v5.1 and default minimal kernel version
  The __ASSUME_TIME64_SYSCALLS not defined, but kernel supports
  __clock_settime64 syscalls.

- Linux v4.19 (no clock_settime64 support) with default minimal kernel
  version for contemporary glibc

  This kernel doesn't support __clock_settime64 syscalls, so the fallback
  to clock_settime is tested.

The above tests were performed with Y2038 redirection applied as well as
without (so the __TIMESIZE != 64 execution path is checked as well).

No regressions were observed.

* include/time.h (__clock_settime64):
  Add __clock_settime alias according to __TIMESIZE define
* sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime):
  Refactor this function to be used only on 32 bit machines as a wrapper
  on __clock_settime64.
* sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime64): Add
* sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime64):
  Use clock_settime64 kernel syscall (available from 5.1+ Linux)

ChangeLog
include/time.h
sysdeps/unix/sysv/linux/clock_settime.c

index 2e34b2da346f0a116c6654ab33bfa62a671ec6d6..edcf1afe10f93b9ad1a861dd9cbf29300c949a98 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-10-10  Ćukasz Majewski <lukma@denx.de>
+
+       * include/time.h (__clock_settime64):
+       Add __clock_settime alias according to __TIMESIZE define
+       * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime):
+       Refactor this function to be used only on 32 bit machines as a
+       wrapper on __clock_settime64.
+       * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime64): Add
+       * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime64):
+       Use clock_settime64 kernel syscall (available from 5.1+ Linux)
+
 2019-10-09  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
        * include/spawn.h (__posix_spawn_file_actions_addopen): New
index f6dc731ac6dabb28a1c4afa94e76b9f98ef22b25..d93b16a78104b1a10c2784b46632f5579a973862 100644 (file)
@@ -125,6 +125,14 @@ extern __time64_t __timegm64 (struct tm *__tp) __THROW;
 libc_hidden_proto (__timegm64)
 #endif
 
+#if __TIMESIZE == 64
+# define __clock_settime64 __clock_settime
+#else
+extern int __clock_settime64 (clockid_t clock_id,
+                              const struct __timespec64 *tp);
+libc_hidden_proto (__clock_settime64)
+#endif
+
 /* Compute the `struct tm' representation of T,
    offset OFFSET seconds east of UTC,
    and store year, yday, mon, mday, wday, hour, min, sec into *TP.
index f76178e0f6e82892de59356a545e2e1ff227ec2b..fb48de5d501fe6c22740babcbd57ff0bd568b183 100644 (file)
 #include <time.h>
 #include <shlib-compat.h>
 
-#include "kernel-posix-cpu-timers.h"
-
 /* Set CLOCK to value TP.  */
 int
-__clock_settime (clockid_t clock_id, const struct timespec *tp)
+__clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp)
 {
   /* Make sure the time cvalue is OK.  */
   if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
@@ -33,8 +31,38 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
       return -1;
     }
 
-  return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
+#ifdef __ASSUME_TIME64_SYSCALLS
+# ifndef __NR_clock_settime64
+#  define __NR_clock_settime64 __NR_clock_settime
+# endif
+  return INLINE_SYSCALL_CALL (clock_settime64, clock_id, tp);
+#else
+# ifdef __NR_clock_settime64
+  int ret = INLINE_SYSCALL_CALL (clock_settime64, clock_id, tp);
+  if (ret == 0 || errno != ENOSYS)
+    return ret;
+# endif
+  if (! in_time_t_range (tp->tv_sec))
+    {
+      __set_errno (EOVERFLOW);
+      return -1;
+    }
+
+  struct timespec ts32 = valid_timespec64_to_timespec (*tp);
+  return INLINE_SYSCALL_CALL (clock_settime, clock_id, &ts32);
+#endif
 }
+
+#if __TIMESIZE != 64
+int
+__clock_settime (clockid_t clock_id, const struct timespec *tp)
+{
+  struct __timespec64 ts64 = valid_timespec_to_timespec64 (*tp);
+
+  return __clock_settime64 (clock_id, &ts64);
+}
+#endif
+
 libc_hidden_def (__clock_settime)
 
 versioned_symbol (libc, __clock_settime, clock_settime, GLIBC_2_17);