[5/5] y2038: Replace __clock_gettime with __clock_gettime64
Commit Message
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 shall be used instead in the glibc itself as it
supports 64 bit time on those systems.
This change does not bring any change to systems with __WORDSIZE == 64 as
for them the __clock_gettime64 is aliased to __clock_gettime
(in ./include/time.h).
The S390 requires special treatment as it has its own definition of
utmp.h at sysdeps/unix/sysv/linux/s390/bits/utmp.h
As it uses int64_t fields for tv_sec and tv_usec the generic
TIMESPEC_TO_TIMEVAL macro must be used.
---
benchtests/bench-timing.h | 2 +-
include/random-bits.h | 4 ++--
login/logout.c | 8 ++++++--
login/logwtmp.c | 10 +++++++---
nis/nis_call.c | 6 +++---
sysdeps/generic/hp-timing.h | 4 ++--
sysdeps/generic/memusage.h | 4 ++--
sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c | 4 ++--
sysdeps/unix/sysv/linux/clock.c | 7 ++-----
9 files changed, 27 insertions(+), 22 deletions(-)
Comments
On Mär 24 2020, Lukasz Majewski wrote:
> diff --git a/login/logout.c b/login/logout.c
> index 7653fe8886..a421d07301 100644
> --- a/login/logout.c
> +++ b/login/logout.c
> @@ -47,9 +47,13 @@ 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);
> +#if __WORDSIZE_TIME64_COMPAT32 || defined __s390x__ || defined __s390__
> TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
> +#else
> + ut->ut_tv = valid_timespec64_to_timeval (ts);
> +#endif
Doesn't TIMESPEC_TO_TIMEVAL work generically?
Andreas.
Hi Andreas,
> On Mär 24 2020, Lukasz Majewski wrote:
>
> > diff --git a/login/logout.c b/login/logout.c
> > index 7653fe8886..a421d07301 100644
> > --- a/login/logout.c
> > +++ b/login/logout.c
> > @@ -47,9 +47,13 @@ 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);
> > +#if __WORDSIZE_TIME64_COMPAT32 || defined __s390x__ || defined
> > __s390__ TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
> > +#else
> > + ut->ut_tv = valid_timespec64_to_timeval (ts);
> > +#endif
>
> Doesn't TIMESPEC_TO_TIMEVAL work generically?
Good point. In this case there shouldn't be any need to add static
inlined (with type checking) conversion functions.
>
> Andreas.
>
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
@@ -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>
@@ -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);
@@ -47,9 +47,13 @@ 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);
+#if __WORDSIZE_TIME64_COMPAT32 || defined __s390x__ || defined __s390__
TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
+#else
+ ut->ut_tv = valid_timespec64_to_timeval (ts);
+#endif
ut->ut_type = DEAD_PROCESS;
if (pututline (ut) != NULL)
@@ -21,6 +21,7 @@
#include <time.h>
#include <unistd.h>
#include <utmp.h>
+#include <struct___timespec64.h>
void
@@ -36,9 +37,12 @@ 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);
+#if __WORDSIZE_TIME64_COMPAT32 || defined __s390x__ || defined __s390__
TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts);
-
+#else
+ ut.ut_tv = valid_timespec64_to_timeval (ts);
+#endif
updwtmp (_PATH_WTMP, &ut);
}
@@ -709,7 +709,7 @@ __nisfind_server (const_nis_name name, int search_parent,
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,8 +719,8 @@ __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);
+ now = valid_timespec64_to_timeval (ts);
if ((flags & NO_CACHE) == 0)
*dir = nis_server_cache_search (name, search_parent, &server_used,
@@ -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); \
})
@@ -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; \
@@ -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;
@@ -23,15 +23,12 @@
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