• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <time.h>
2 #include "syscall.h"
3 
4 #ifndef __LITEOS__
5 #include <errno.h>
6 #include <stdint.h>
7 #include "atomic.h"
8 
9 #ifdef VDSO_CGR_SYM
10 
11 static void *volatile vdso_cgr;
12 
cgr_init(clockid_t clk,struct timespec * ts)13 static int cgr_init(clockid_t clk, struct timespec *ts)
14 {
15 	__get_vdso_info();
16 	void *p = __get_vdso_addr(VDSO_CGR_VER, VDSO_CGR_SYM);
17 	int (*f)(clockid_t, struct timespec *) =
18 		(int (*)(clockid_t, struct timespec *))p;
19 	a_cas_p(&vdso_cgr, (void *)cgr_init, p);
20 	return f ? f(clk, ts) : -ENOSYS;
21 }
22 
23 static void *volatile vdso_cgr = (void *)cgr_init;
24 
25 #endif
26 #endif
27 
clock_getres(clockid_t clk,struct timespec * ts)28 int clock_getres(clockid_t clk, struct timespec *ts)
29 {
30 	int r;
31 #if defined(VDSO_CGR_SYM) && (!defined(__LITEOS__))
32 	int (*f)(clockid_t, struct timespec *) =
33 		(int (*)(clockid_t, struct timespec *))vdso_cgr;
34 	if (f) {
35 		r = f(clk, ts);
36 		if (!r) return r;
37 		if (r == -EINVAL) return __syscall_ret(r);
38 	}
39 #endif
40 
41 #ifdef SYS_clock_getres_time64
42 	/* On a 32-bit arch, use the old syscall if it exists. */
43 	if (SYS_clock_getres != SYS_clock_getres_time64) {
44 		long ts32[2];
45 		r = __syscall(SYS_clock_getres, clk, ts32);
46 		if (!r && ts) {
47 			ts->tv_sec = ts32[0];
48 			ts->tv_nsec = ts32[1];
49 		}
50 		return __syscall_ret(r);
51 	}
52 #endif
53 	/* If reaching this point, it's a 64-bit arch or time64-only
54 	 * 32-bit arch and we can get result directly into timespec. */
55 	return syscall(SYS_clock_getres, clk, ts);
56 }
57