[RFC,3/7] y2038: clock_settime: Provide __clock_settime64 implementation for linux
diff mbox series

Message ID 20190327085210.22019-4-lukma@denx.de
State New
Headers show
Series
  • y2038: clock_settime rework to be Y2038 safe on 32bit systems
Related show

Commit Message

Lukasz Majewski March 27, 2019, 8:52 a.m. UTC
* include/time.h: Remove __clock_settime typeof
* include/time.h: Add __clock_settime64 definition according to __TIMESIZE
* sysdeps/unix/sysv/linux/clock_settime.c: Remove clock_settime alias
* sysdeps/unix/sysv/linux/clock_settime.c:
  Add clock_settime when __TIMESIZE != 64
  Rewrite __clock_settime() to __clock_settime64 with explicit support for
  64 bit time
---
 include/time.h                          |  9 +++++++-
 sysdeps/unix/sysv/linux/clock_settime.c | 40 +++++++++++++++++++++++----------
 2 files changed, 36 insertions(+), 13 deletions(-)

Comments

Joseph Myers March 27, 2019, 1:45 p.m. UTC | #1
On Wed, 27 Mar 2019, Lukasz Majewski wrote:

> * include/time.h: Remove __clock_settime typeof
> * include/time.h: Add __clock_settime64 definition according to __TIMESIZE
> * sysdeps/unix/sysv/linux/clock_settime.c: Remove clock_settime alias
> * sysdeps/unix/sysv/linux/clock_settime.c:
>   Add clock_settime when __TIMESIZE != 64
>   Rewrite __clock_settime() to __clock_settime64 with explicit support for
>   64 bit time

For every patch posted, please state explicitly how that patch was tested 
(should include the glibc testsuite for at least one 32-bit and at least 
one 64-bit configuration).  That's critical information to have any 
confidence in the lack of obvious ABI / linknamespace issues in a patch.

> +int
> +__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)
> +		{
> +			__set_errno (EINVAL);
> +			return -1;
> +		}
> +
> +	return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
> +}

Globally, in the patch series, follow GNU style for indentation 
(two-column).

> +/* The clock_settime symbol needs to be public as librt is also
> +   using it */

Globally, in the patch series, follow GNU style for comments (start with a 
capital letter, end with '.' and two spaces).

Patch
diff mbox series

diff --git a/include/time.h b/include/time.h
index 09231073b5..c8c0a6936e 100644
--- a/include/time.h
+++ b/include/time.h
@@ -22,7 +22,6 @@  libc_hidden_proto (strptime)
 extern __typeof (clock_getres) __clock_getres;
 extern __typeof (clock_gettime) __clock_gettime;
 libc_hidden_proto (__clock_gettime)
-extern __typeof (clock_settime) __clock_settime;
 extern __typeof (clock_nanosleep) __clock_nanosleep;
 extern __typeof (clock_getcpuclockid) __clock_getcpuclockid;
 
@@ -103,6 +102,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.
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index d837e3019c..5b7ab7fcb3 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -19,19 +19,35 @@ 
 #include <sysdep.h>
 #include <time.h>
 
-#include "kernel-posix-cpu-timers.h"
+int
+__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)
+		{
+			__set_errno (EINVAL);
+			return -1;
+		}
+
+	return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
+}
 
-/* Set CLOCK to value TP.  */
+#if __TIMESIZE != 64
 int
-__clock_settime (clockid_t clock_id, const struct timespec *tp)
+clock_settime (clockid_t clock_id, const struct timespec *tp)
 {
-  /* Make sure the time cvalue is OK.  */
-  if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000)
-    {
-      __set_errno (EINVAL);
-      return -1;
-    }
-
-  return INLINE_SYSCALL_CALL (clock_settime, clock_id, 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);
 }
-weak_alias (__clock_settime, clock_settime)
+
+/* The clock_settime symbol needs to be public as librt is also
+   using it */
+#endif