OLD | NEW |
1 #include <time.h> | 1 #include <time.h> |
2 #include <errno.h> | 2 #include <errno.h> |
3 #include <stdint.h> | 3 #include <stdint.h> |
4 #include "syscall.h" | 4 #include "syscall.h" |
5 #include "libc.h" | 5 #include "libc.h" |
6 #include "atomic.h" | 6 #include "atomic.h" |
7 | 7 |
8 #ifdef VDSO_CGT_SYM | 8 #ifdef VDSO_CGT_SYM |
9 | 9 |
10 void *__vdsosym(const char *, const char *); | 10 void* __vdsosym(const char*, const char*); |
11 | 11 |
12 static void *volatile vdso_func; | 12 static void* volatile vdso_func; |
13 | 13 |
14 static int cgt_init(clockid_t clk, struct timespec *ts) | 14 static int cgt_init(clockid_t clk, struct timespec* ts) { |
15 { | 15 void* p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM); |
16 » void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM); | 16 int (*f)(clockid_t, struct timespec*) = |
17 » int (*f)(clockid_t, struct timespec *) = | 17 (int (*)(clockid_t, struct timespec*))p; |
18 » » (int (*)(clockid_t, struct timespec *))p; | 18 a_cas_p(&vdso_func, (void*)cgt_init, p); |
19 » a_cas_p(&vdso_func, (void *)cgt_init, p); | 19 return f ? f(clk, ts) : -ENOSYS; |
20 » return f ? f(clk, ts) : -ENOSYS; | |
21 } | 20 } |
22 | 21 |
23 static void *volatile vdso_func = (void *)cgt_init; | 22 static void* volatile vdso_func = (void*)cgt_init; |
24 | 23 |
25 #endif | 24 #endif |
26 | 25 |
27 int __clock_gettime(clockid_t clk, struct timespec *ts) | 26 int __clock_gettime(clockid_t clk, struct timespec* ts) { |
28 { | 27 int r; |
29 » int r; | |
30 | 28 |
31 #ifdef VDSO_CGT_SYM | 29 #ifdef VDSO_CGT_SYM |
32 » int (*f)(clockid_t, struct timespec *) = | 30 int (*f)(clockid_t, struct timespec*) = |
33 » » (int (*)(clockid_t, struct timespec *))vdso_func; | 31 (int (*)(clockid_t, struct timespec*))vdso_func; |
34 » if (f) { | 32 if (f) { |
35 » » r = f(clk, ts); | 33 r = f(clk, ts); |
36 » » if (!r) return r; | 34 if (!r) |
37 » » if (r == -EINVAL) return __syscall_ret(r); | 35 return r; |
38 » » /* Fall through on errors other than EINVAL. Some buggy | 36 if (r == -EINVAL) |
39 » » * vdso implementations return ENOSYS for clocks they | 37 return __syscall_ret(r); |
40 » » * can't handle, rather than making the syscall. This | 38 /* Fall through on errors other than EINVAL. Some buggy |
41 » » * also handles the case where cgt_init fails to find | 39 * vdso implementations return ENOSYS for clocks they |
42 » » * a vdso function to use. */ | 40 * can't handle, rather than making the syscall. This |
43 » } | 41 * also handles the case where cgt_init fails to find |
| 42 * a vdso function to use. */ |
| 43 } |
44 #endif | 44 #endif |
45 | 45 |
46 » r = __syscall(SYS_clock_gettime, clk, ts); | 46 r = __syscall(SYS_clock_gettime, clk, ts); |
47 » if (r == -ENOSYS) { | 47 if (r == -ENOSYS) { |
48 » » if (clk == CLOCK_REALTIME) { | 48 if (clk == CLOCK_REALTIME) { |
49 » » » __syscall(SYS_gettimeofday, ts, 0); | 49 __syscall(SYS_gettimeofday, ts, 0); |
50 » » » ts->tv_nsec = (int)ts->tv_nsec * 1000; | 50 ts->tv_nsec = (int)ts->tv_nsec * 1000; |
51 » » » return 0; | 51 return 0; |
52 » » } | 52 } |
53 » » r = -EINVAL; | 53 r = -EINVAL; |
54 » } | 54 } |
55 » return __syscall_ret(r); | 55 return __syscall_ret(r); |
56 } | 56 } |
57 | 57 |
58 weak_alias(__clock_gettime, clock_gettime); | 58 weak_alias(__clock_gettime, clock_gettime); |
OLD | NEW |