Patchwork [RFC,v1,03/16] sysdeps/gettimeofday: Use clock_gettime64 syscall for gettimeofday

login
register
mail settings
Submitter Alistair Francis
Date June 22, 2019, 4:37 a.m.
Message ID <131e5b75cc2173b6cfd75f169b9a971877bcd44f.1561177967.git.alistair.francis@wdc.com>
Download mbox | patch
Permalink /patch/33264/
State New
Headers show

Comments

Alistair Francis - June 22, 2019, 4:37 a.m.
Not all architectures support the obsolete gettimeofday so use the
newer clock_gettime64 syscall. This fixes RV32 build issues.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 ChangeLog                              |  1 +
 sysdeps/unix/sysv/linux/gettimeofday.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

Patch

diff --git a/ChangeLog b/ChangeLog
index a700783ef3..f1c7acb6ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@ 
 	* sysdeps/unix/sysv/linux/nanosleep.c: Likewise.
 	* sysdeps/unix/sysv/linux/nanosleep_nocancel.c: Likewise.
 	* sysdeps/unix/sysv/linux/lowlevellock-futex.h: Use __NR_futex_time64 if we don't have __NR_futex.
+	* sysdeps/unix/sysv/linux/gettimeofday.c: Use clock_gettime64 syscall for gettimeofday.
 
 2019-06-20  Dmitry V. Levin  <ldv@altlinux.org>
 	    Florian Weimer  <fweimer@redhat.com>
diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c
index a74f03825a..58be2fdcc5 100644
--- a/sysdeps/unix/sysv/linux/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/gettimeofday.c
@@ -32,7 +32,21 @@ 
 int
 __gettimeofday (struct timeval *tv, struct timezone *tz)
 {
+#ifdef __NR_gettimeofday
   return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
+#else
+  int ret;
+  struct timespec now;
+
+  ret = INLINE_VSYSCALL (clock_gettime64, 2, CLOCK_REALTIME,
+                         &now);
+
+  /* Convert from timespec to timeval */
+  tv->tv_sec = now.tv_sec;
+  tv->tv_usec = now.tv_nsec / 1000;
+
+  return ret;
+#endif
 }
 libc_hidden_def (__gettimeofday)
 weak_alias (__gettimeofday, gettimeofday)