@@ -127,6 +127,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.
@@ -19,11 +19,9 @@
#include <sysdep.h>
#include <time.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)
@@ -32,6 +30,55 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp)
return -1;
}
+#ifdef __ASSUME_TIME64_SYSCALLS
+# ifdef __NR_clock_settime64
+ /* For Y2038 safe systems with __WORDSIZE==32 and __TIMESIZE==64
+ (x86, arm) the glibc exported struct timespec has 64 bit tv_sec,
+ 32 bit tv_nsec (to be still POSIX compliant -> long tv_nsec )
+ and 32 bits of unnamed padding.
+
+ It may happen that due to dynamic allocation the tv_pad, which
+ corresponds to upper 32 bits of kernel's 64 bit tv_nsec accepted
+ by syscalls, may not be zero.
+
+ However, the Linux kernel is ignoring those 32 bits (to be more
+ precise - as of 5.1 - it casts 64 bit tv_nsec to internal's 32 bit
+ representation) and hence the padding clearing is not needed. */
+ int ret = INLINE_SYSCALL_CALL (clock_settime64, clock_id, tp);
+ if (ret == 0 || errno != ENOSYS)
+ return ret;
+# endif
+#endif
+
+/* For systems supporting 32 bit time only __WORDSIZE==32 and
+ __TIMESIZE==32 (!=64) the passed struct __timespec64 must be
+ converted to 32 bit one before invoking Linux syscall. */
+#if __WORDSIZE == 32 && __TIMESIZE != 64
+ /* Fall back to syscall supporting 32bit struct timespec. */
+ struct timespec ts32;
+ valid_timespec64_to_timespec (tp, &ts32);
+ return INLINE_SYSCALL_CALL (clock_settime, clock_id, &ts32);
+#else
+/* Systems with __WORDSIZE==64 (i.e. x86_64, aarch64) or
+ __WORDSIZE==32 && __TIMESIZE == 64 (i.e. x32 - special case). */
return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
+#endif
}
weak_alias (__clock_settime, clock_settime)
+
+#if __TIMESIZE != 64
+int
+__clock_settime (clockid_t clock_id, const struct timespec *tp)
+{
+ struct __timespec64 ts64;
+
+ if (! in_time_t_range (tp->tv_sec))
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+
+ valid_timespec_to_timespec64 (tp, &ts64);
+ return __clock_settime64 (clock_id, &ts64);
+}
+#endif