This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12 #include <stdint.h>
13 #include <elf.h>
14 #include <stdio.h>
15 #include <sys/auxv.h>
16 #include <sys/time.h>
17
18 #include "../kselftest.h"
19
20 extern void *vdso_sym(const char *version, const char *name);
21 extern void vdso_init_from_sysinfo_ehdr(uintptr_t base);
22 extern void vdso_init_from_auxv(void *auxv);
23
24
25
26
27
28
29 #if defined(__aarch64__)
30 const char *version = "LINUX_2.6.39";
31 const char *name = "__kernel_gettimeofday";
32 #else
33 const char *version = "LINUX_2.6";
34 const char *name = "__vdso_gettimeofday";
35 #endif
36
37 int main(int argc, char **argv)
38 {
39 unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
40 if (!sysinfo_ehdr) {
41 printf("AT_SYSINFO_EHDR is not present!\n");
42 return KSFT_SKIP;
43 }
44
45 vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
46
47
48 typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz);
49 gtod_t gtod = (gtod_t)vdso_sym(version, name);
50
51 if (!gtod) {
52 printf("Could not find %s\n", name);
53 return KSFT_SKIP;
54 }
55
56 struct timeval tv;
57 long ret = gtod(&tv, 0);
58
59 if (ret == 0) {
60 printf("The time is %lld.%06lld\n",
61 (long long)tv.tv_sec, (long long)tv.tv_usec);
62 } else {
63 printf("%s failed\n", name);
64 return KSFT_FAIL;
65 }
66
67 return 0;
68 }