10 void *__vdsosym(const char *, const char *);
12 static void *volatile vdso_func;
14 static int cgt_init(clockid_t clk, struct timespec *ts)
16 void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM);
17 int (*f)(clockid_t, struct timespec *) =
18 (int (*)(clockid_t, struct timespec *))p;
19 a_cas_p(&vdso_func, (void *)cgt_init, p);
20 return f ? f(clk, ts) : -ENOSYS;
23 static void *volatile vdso_func = (void *)cgt_init;
27 int __clock_gettime(clockid_t clk, struct timespec *ts)
32 int (*f)(clockid_t, struct timespec *) =
33 (int (*)(clockid_t, struct timespec *))vdso_func;
37 if (r == -EINVAL) return __syscall_ret(r);
38 /* Fall through on errors other than EINVAL. Some buggy
39 * vdso implementations return ENOSYS for clocks they
40 * can't handle, rather than making the syscall. This
41 * also handles the case where cgt_init fails to find
42 * a vdso function to use. */
46 r = __syscall(SYS_clock_gettime, clk, ts);
48 if (clk == CLOCK_REALTIME) {
49 __syscall(SYS_gettimeofday, ts, 0);
50 ts->tv_nsec = (int)ts->tv_nsec * 1000;
55 return __syscall_ret(r);
58 weak_alias(__clock_gettime, clock_gettime);