- static int (*volatile cgt)(clockid_t, struct timespec *);
- if (!cgt) {
- void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
- if (!f) f = (void *)sc_clock_gettime;
- a_cas_p(&cgt, 0, f);
+ int (*f)(clockid_t, struct timespec *) =
+ (int (*)(clockid_t, struct timespec *))vdso_func;
+ if (f) {
+ r = f(clk, ts);
+ if (!r) return r;
+ if (r == -EINVAL) return __syscall_ret(r);
+ /* Fall through on errors other than EINVAL. Some buggy
+ * vdso implementations return ENOSYS for clocks they
+ * can't handle, rather than making the syscall. This
+ * also handles the case where cgt_init fails to find
+ * a vdso function to use. */
+ }
+#endif
+
+#ifdef SYS_clock_gettime64
+ r = -ENOSYS;
+ if (sizeof(time_t) > 4)
+ r = __syscall(SYS_clock_gettime64, clk, ts);
+ if (SYS_clock_gettime == SYS_clock_gettime64 || r!=-ENOSYS)
+ return __syscall_ret(r);
+ long ts32[2];
+ r = __syscall(SYS_clock_gettime, clk, ts32);
+ if (r==-ENOSYS && clk==CLOCK_REALTIME) {
+ r = __syscall(SYS_gettimeofday, ts32, 0);
+ ts32[1] *= 1000;