This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC v5 05/21] sysdeps/clock_gettime: Use clock_gettime64 if avaliable
- From: Alistair Francis <alistair dot francis at wdc dot com>
- To: libc-alpha at sourceware dot org
- Cc: arnd at arndb dot de, adhemerval dot zanella at linaro dot org, fweimer at redhat dot com, palmer at sifive dot com, macro at wdc dot com, zongbox at gmail dot com, alistair dot francis at wdc dot com, alistair23 at gmail dot com
- Date: Thu, 29 Aug 2019 09:50:13 -0700
- Subject: [RFC v5 05/21] sysdeps/clock_gettime: Use clock_gettime64 if avaliable
- Ironport-sdr: AnoQU4n4FmzC/CytAQCtn0dOmCNBEsaftNBrgGtp11j1Y6vYuUu3AXar7b7lhbKhDDo7p2A7xg mfvMFYhKfZQ+FR69i2iGOebjbbBZAmE2mq04y3ZL4UrsxN1UxCZuxYMSjh6eblEv3yXZ5MUGUO vu4V5SosCnjIUvOGyUK0CFCcXIBfXpVSVs/kHvR3MODiqzLX18/DIg/3xI0N12F7oMwDar6eT2 oIG1pDiBfqpYGp2mn1Ztw5/+rXv6Nh1ZPzbCoWC2cVI81l+Tq4QfrgfJfn0pQYd0Eg3o80NwC+ hBk=
- Ironport-sdr: Af/xawCzTklhgdXSPahC2nxCyvEeLwoEmqzmjRO13HFBBxXcP7xBriwFCtmgRwYyx83gbyxebe 6aVKgEB+GyVUfYtEzzPimI2fnwmVqjsZ6/Rgppz7cxxfzfTBoSQc3hed17BEPXwm7xG6qfAWWv S6cXb5byhw4Ez3t3Clu6UCK/YMAevdcFiDmilMwhVshnZy6wOthFXQ7gjKIdhHJ5WEf7MVTbbz nDXrLkBAEh7GwzCxheWDRSet62Z4easuM9bUPZV3MlHoZucL2lr4SnFJaFC8YAvMuaGAjiYJ38 Riq2hh8awbG5jp3cqiJIfn9N
- Ironport-sdr: MnfmaZTy1mN9hjBD+ZBlBIK5N6g2d8VPYLCQ0r/0f5D0vQYZmbg1U+yqIgaYpc7eE3QAt6/V69 ZE1KznWDs/H0AuxgAKG7b7ytD69uPJvf1nw/hKQMzoKZFSgWUnc63dL3joPNKti2RFdJjEdoc4 hGhs5sBRM+m1PrxI7tdj4afPCOms9I95RQF74kyT1Th704jGbfxDd/u/yUgaLGXSZICtxelaUh Nd7Xd3h3GNh1b/oMxi67iDQovHGG6LpT1UZhy4L6oHT8O10RwduuekpLxwRutRSojlSHxnyeOy ldY=
- References: <cover.1567097252.git.alistair.francis@wdc.com>
- Wdcironportexception: Internal
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
* sysdeps/unix/sysv/linux/clock_gettime.c: Use clock_gettime64 if avaliable.
---
include/time.h | 1 +
sysdeps/unix/sysv/linux/clock_gettime.c | 48 ++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/include/time.h b/include/time.h
index 6d81f91384b..1e33f34e1f6 100644
--- a/include/time.h
+++ b/include/time.h
@@ -177,6 +177,7 @@ extern double __difftime (time_t time1, time_t time0);
#define __clock_nanosleep_time64 __clock_nanosleep
#define __nanosleep_time64 __nanosleep
#define __nanosleep_nocancel_time64 __nanosleep_nocancel
+#define __clock_gettime64 __clock_gettime
#endif
/* Use in the clock_* functions. Size of the field representing the
diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c
index 5fc47fb7dc7..ea98af9bf1a 100644
--- a/sysdeps/unix/sysv/linux/clock_gettime.c
+++ b/sysdeps/unix/sysv/linux/clock_gettime.c
@@ -28,9 +28,55 @@
/* Get current value of CLOCK and store it in TP. */
int
+__clock_gettime64 (clockid_t clock_id, struct timespec *tp)
+{
+#ifdef __ASSUME_TIME64_SYSCALLS
+# ifndef __NR_clock_gettime64
+# define __NR_clock_gettime64 __NR_clock_gettime
+# endif
+ return INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
+#else
+ int ret;
+# ifdef __NR_clock_gettime64
+ ret = INLINE_VSYSCALL (clock_gettime64, 2, clock_id, tp);
+
+ if (ret == 0 || errno != ENOSYS)
+ return ret;
+# endif /* __NR_clock_gettime64 */
+ struct timespec tp32;
+
+ ret = INLINE_VSYSCALL (clock_gettime, 2, clock_id, &tp32);
+
+ if (ret == 0 || errno != ENOSYS)
+ valid_timespec_to_timespec64(tp32, tp);
+
+ return ret;
+#endif /* __ASSUME_TIME64_SYSCALLS */
+}
+
+#if __TIMESIZE != 64
+int
__clock_gettime (clockid_t clock_id, struct timespec *tp)
{
- return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp);
+ int ret;
+ struct __timespec64 tp64;
+
+ ret = __clock_gettime64 (clock_id, &tp64);
+
+ if (ret == 0 || errno != ENOSYS)
+ {
+ if (! in_time_t_range (tp64.tv_sec))
+ {
+ __set_errno (EOVERFLOW);
+ return -1;
+ }
+
+ valid_timespec64_to_timespec(&tp64, tp);
+
+ return ret;
+ }
}
+#endif
+
weak_alias (__clock_gettime, clock_gettime)
libc_hidden_def (__clock_gettime)
--
2.22.0