#include #include "syscall.h" #include "atomic.h" static int syscall_clock_gettime(clockid_t clk, struct timespec *ts) { return __syscall(SYS_clock_gettime, clk, ts); } void *__vdsosym(const char *, const char *); /* There is no other implemented value than TIME_UTC, all other values are considered erroneous. */ int timespec_get(struct timespec * ts, int base) { if (base != TIME_UTC) return 0; int ret; #ifdef VDSO_CGT_SYM static int (*cgt)(clockid_t, struct timespec *); if (!cgt) { void *f = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM); if (!f) f = (void *)syscall_clock_gettime; a_cas_p(&cgt, 0, f); } /* The vdso variants never fail, and thus never set errno. */ ret = cgt(CLOCK_REALTIME, ts); #else ret = syscall_clock_gettime(CLOCK_REALTIME, ts); #endif return ret < 0 ? 0 : base; }