1 // SPDX-License-Identifier: GPL-2.0-only
3 * vdso_test.c: Sample code to test parse_vdso.c
4 * Copyright (c) 2014 Andy Lutomirski
7 * gcc -std=gnu99 vdso_test.c parse_vdso.c
9 * Tested on x86, 32-bit and 64-bit. It may work on other architectures, too.
18 #include "../kselftest.h"
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
);
25 * ARM64's vDSO exports its gettimeofday() implementation with a different
26 * name and version from other architectures, so we need to handle it as
29 #if defined(__aarch64__)
30 const char *version
= "LINUX_2.6.39";
31 const char *name
= "__kernel_gettimeofday";
33 const char *version
= "LINUX_2.6";
34 const char *name
= "__vdso_gettimeofday";
37 int main(int argc
, char **argv
)
39 unsigned long sysinfo_ehdr
= getauxval(AT_SYSINFO_EHDR
);
41 printf("AT_SYSINFO_EHDR is not present!\n");
45 vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR
));
47 /* Find gettimeofday. */
48 typedef long (*gtod_t
)(struct timeval
*tv
, struct timezone
*tz
);
49 gtod_t gtod
= (gtod_t
)vdso_sym(version
, name
);
52 printf("Could not find %s\n", name
);
57 long ret
= gtod(&tv
, 0);
60 printf("The time is %lld.%06lld\n",
61 (long long)tv
.tv_sec
, (long long)tv
.tv_usec
);
63 printf("%s failed\n", name
);