1 #include <time.h>
2 #include <sys/time.h>
3 #include "syscall.h"
4
5 #ifndef __LITEOS__
6 #include <time.h>
7 #include <errno.h>
8 #include <stdint.h>
9 #include "atomic.h"
10
11 #ifdef VDSO_GTD_SYM
12
13 static void *volatile vdso_gtd;
14
gtd_init(struct timeval * tv,void * tz)15 static int gtd_init(struct timeval *tv, void *tz)
16 {
17 __get_vdso_info();
18 void *p = __get_vdso_addr(VDSO_GTD_VER, VDSO_GTD_SYM);
19 int (*f)(struct timeval *, void *) =
20 (int (*)(struct timval *, void *))p;
21 a_cas_p(&vdso_gtd, (void *)gtd_init, p);
22 return f ? f(tv, tz) : -ENOSYS;
23 }
24
25 static void *volatile vdso_gtd = (void *)gtd_init;
26
27 #endif
28 #endif
29
gettimeofday(struct timeval * restrict tv,void * restrict tz)30 int gettimeofday(struct timeval *restrict tv, void *restrict tz)
31 {
32 #if defined(VDSO_GTD_SYM) && (!defined(__LITEOS__))
33 int r;
34 int (*f)(struct timeval *, void *) =
35 (int (*)(struct timeval *, void *))vdso_gtd;
36 if (f) {
37 r = f(tv, tz);
38 if (!r) return r;
39 if (r == -EINVAL) return __syscall_ret(r);
40 }
41 #endif
42
43 struct timespec ts;
44 if (!tv) return 0;
45 clock_gettime(CLOCK_REALTIME, &ts);
46 tv->tv_sec = ts.tv_sec;
47 tv->tv_usec = (int)ts.tv_nsec / 1000;
48 return 0;
49 }
50