]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
y2038: Replace __clock_gettime with __clock_gettime64
authorLukasz Majewski <lukma@denx.de>
Mon, 16 Mar 2020 07:31:41 +0000 (08:31 +0100)
committerLukasz Majewski <lukma@denx.de>
Wed, 20 May 2020 14:45:16 +0000 (16:45 +0200)
The __clock_gettime internal function is not supporting 64 bit time on
architectures with __WORDSIZE == 32 and __TIMESIZE != 64 (like e.g. ARM 32
bit).

The __clock_gettime64 function shall be used instead in the glibc itself as
it supports 64 bit time on those systems.
This patch does not bring any changes to systems with __WORDSIZE == 64 as
for them the __clock_gettime64 is aliased to __clock_gettime (in
./include/time.h).

benchtests/bench-timing.h
include/random-bits.h
login/logout.c
login/logwtmp.c
nis/nis_call.c
sysdeps/generic/hp-timing.h
sysdeps/generic/memusage.h
sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
sysdeps/unix/sysv/linux/clock.c

index 5b9a8384bbc61e8a21b6020833f001bd1633b3f2..a0d6f8246537eebaf46ea68f028774b693980e00 100644 (file)
@@ -18,7 +18,7 @@
 
 #undef attribute_hidden
 #define attribute_hidden
-#define __clock_gettime clock_gettime
+#define __clock_gettime __clock_gettime64
 #include <hp-timing.h>
 #include <stdint.h>
 
index fd3fa01f9be5aa72c4d7eefe4b6cf534c7c8a63d..7561e55ca6c198586878d2e24ca770c56d3bf2a1 100644 (file)
@@ -30,8 +30,8 @@
 static inline uint32_t
 random_bits (void)
 {
-  struct timespec tv;
-  __clock_gettime (CLOCK_MONOTONIC, &tv);
+  struct __timespec64 tv;
+  __clock_gettime64 (CLOCK_MONOTONIC, &tv);
   /* Shuffle the lower bits to minimize the clock bias.  */
   uint32_t ret = tv.tv_nsec ^ tv.tv_sec;
   ret ^= (ret << 24) | (ret >> 8);
index 7653fe88862e959e5d7c60f590bd391df93dded2..091312eb1d64c57ced56cad31a0249100239f525 100644 (file)
@@ -47,8 +47,8 @@ logout (const char *line)
       memset (ut->ut_name, '\0', sizeof ut->ut_name);
       memset (ut->ut_host, '\0', sizeof ut->ut_host);
 
-      struct timespec ts;
-      __clock_gettime (CLOCK_REALTIME, &ts);
+      struct __timespec64 ts;
+      __clock_gettime64 (CLOCK_REALTIME, &ts);
       TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
       ut->ut_type = DEAD_PROCESS;
 
index 90406acc3d83a6e8275eb353a9200ded8e28ac0e..050219c1534bf29ad89bbd9cdf5fbc800e92ab63 100644 (file)
@@ -21,6 +21,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <utmp.h>
+#include <struct___timespec64.h>
 
 
 void
@@ -36,8 +37,8 @@ logwtmp (const char *line, const char *name, const char *host)
   strncpy (ut.ut_name, name, sizeof ut.ut_name);
   strncpy (ut.ut_host, host, sizeof ut.ut_host);
 
-  struct timespec ts;
-  __clock_gettime (CLOCK_REALTIME, &ts);
+  struct __timespec64 ts;
+  __clock_gettime64 (CLOCK_REALTIME, &ts);
   TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts);
 
   updwtmp (_PATH_WTMP, &ut);
index 92c70e97aac821b5e3f313da96eb484f0bccaaca..da4c52bdcde89ddb891a67f4bf86377d0adc0bf8 100644 (file)
@@ -575,7 +575,7 @@ static struct nis_server_cache
   unsigned int size;
   unsigned int server_used;
   unsigned int current_ep;
-  time_t expires;
+  __time64_t expires;
   char name[];
 } *nis_server_cache[16];
 static time_t nis_cold_start_mtime;
@@ -584,7 +584,7 @@ __libc_lock_define_initialized (static, nis_server_cache_lock)
 static directory_obj *
 nis_server_cache_search (const_nis_name name, int search_parent,
                         unsigned int *server_used, unsigned int *current_ep,
-                        struct timeval *now)
+                        struct __timespec64 *now)
 {
   directory_obj *ret = NULL;
   int i;
@@ -642,7 +642,7 @@ nis_server_cache_search (const_nis_name name, int search_parent,
 static void
 nis_server_cache_add (const_nis_name name, int search_parent,
                      directory_obj *dir, unsigned int server_used,
-                     unsigned int current_ep, struct timeval *now)
+                     unsigned int current_ep, struct __timespec64 *now)
 {
   struct nis_server_cache **loc;
   struct nis_server_cache *new;
@@ -708,8 +708,7 @@ __nisfind_server (const_nis_name name, int search_parent,
   nis_error result = NIS_SUCCESS;
   nis_error status;
   directory_obj *obj;
-  struct timeval now;
-  struct timespec ts;
+  struct __timespec64 ts;
   unsigned int server_used = ~0;
   unsigned int current_ep = ~0;
 
@@ -719,12 +718,11 @@ __nisfind_server (const_nis_name name, int search_parent,
   if (*dir != NULL)
     return NIS_SUCCESS;
 
-  __clock_gettime (CLOCK_REALTIME, &ts);
-  TIMESPEC_TO_TIMEVAL (&now, &ts);
+  __clock_gettime64 (CLOCK_REALTIME, &ts);
 
   if ((flags & NO_CACHE) == 0)
     *dir = nis_server_cache_search (name, search_parent, &server_used,
-                                   &current_ep, &now);
+                                   &current_ep, &ts);
   if (*dir != NULL)
     {
       unsigned int server_len = (*dir)->do_servers.do_servers_len;
@@ -783,7 +781,7 @@ __nisfind_server (const_nis_name name, int search_parent,
            }
          if ((flags & NO_CACHE) == 0)
            nis_server_cache_add (name, search_parent, obj,
-                                 server_used, current_ep, &now);
+                                 server_used, current_ep, &ts);
        }
       else
        {
index e2d7447212d473ab1b9a9ac5854d7f2c0bd8911c..af9d92f7f71bf8442f2832c6aaed91dbf166f474 100644 (file)
@@ -34,8 +34,8 @@ typedef uint64_t hp_timing_t;
    vDSO symbol.  */
 #define HP_TIMING_NOW(var) \
 ({                                                             \
-  struct timespec tv;                                          \
-  __clock_gettime (CLOCK_MONOTONIC, &tv);                      \
+  struct __timespec64 tv;                                              \
+  __clock_gettime64 (CLOCK_MONOTONIC, &tv);                    \
   (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec);     \
 })
 
index a111864b0ba58366b52901f8ae53bb1d13062c79..91e56d24de1ab6e8fd736302677b3c139d69a8fd 100644 (file)
@@ -28,9 +28,9 @@
 #ifndef GETTIME
 # define GETTIME(low,high)                                                \
   {                                                                       \
-    struct timespec now;                                                  \
+    struct __timespec64 now;                                              \
     uint64_t usecs;                                                       \
-    clock_gettime (CLOCK_REALTIME, &now);                                 \
+    __clock_gettime64 (CLOCK_REALTIME, &now);                             \
     usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \
     low = usecs & 0xffffffff;                                             \
     high = usecs >> 32;                                                           \
index 8cf5d303f977525b92cfe40c08b705806be8b2ff..5075ae044456a4bb87f46f46b5a366cb32577e8d 100644 (file)
@@ -35,8 +35,8 @@ __gettimeofday_tv32 (struct __timeval32 *restrict tv32, void *restrict tz)
   if (__glibc_unlikely (tz != 0))
     memset (tz, 0, sizeof (struct timezone));
 
-  struct timespec ts;
-  __clock_gettime (CLOCK_REALTIME, &ts);
+  struct __timespec64 ts;
+  __clock_gettime64 (CLOCK_REALTIME, &ts);
 
   *tv32 = valid_timespec_to_timeval32 (ts);
   return 0;
index 24a8df0cf5de0f99ab7bd6e81d24ee3c1d409264..157ae8eb3f7bc70a4c5dba81feebf8cc483018ed 100644 (file)
 clock_t
 clock (void)
 {
-  struct timespec ts;
+  struct __timespec64 ts;
 
   _Static_assert (CLOCKS_PER_SEC == 1000000,
                  "CLOCKS_PER_SEC should be 1000000");
 
-  /* clock_gettime shouldn't fail here since CLOCK_PROCESS_CPUTIME_ID is
-     supported since 2.6.12.  Check the return value anyway in case the kernel
-     barfs on us for some reason.  */
-  if (__glibc_unlikely (__clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts) != 0))
+  if (__glibc_unlikely (__clock_gettime64 (CLOCK_PROCESS_CPUTIME_ID, &ts) != 0))
     return (clock_t) -1;
 
   return (ts.tv_sec * CLOCKS_PER_SEC