1 // SPDX-License-Identifier: GPL-2.0-only
3 * vdso_test_gettimeofday.c: Sample code to test parse_vdso.c and
5 * Copyright (c) 2014 Andy Lutomirski
8 * gcc -std=gnu99 vdso_test_gettimeofday.c parse_vdso_gettimeofday.c
10 * Tested on x86, 32-bit and 64-bit. It may work on other architectures, too.
19 #include "../kselftest.h"
20 #include "parse_vdso.h"
23 * ARM64's vDSO exports its gettimeofday() implementation with a different
24 * name and version from other architectures, so we need to handle it as
27 #if defined(__aarch64__)
28 const char *version = "LINUX_2.6.39";
29 const char *name = "__kernel_gettimeofday";
31 const char *version = "LINUX_2.6";
32 const char *name = "__vdso_gettimeofday";
35 int main(int argc, char **argv)
37 unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
39 printf("AT_SYSINFO_EHDR is not present!\n");
43 vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
45 /* Find gettimeofday. */
46 typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz);
47 gtod_t gtod = (gtod_t)vdso_sym(version, name);
50 printf("Could not find %s\n", name);
55 long ret = gtod(&tv, 0);
58 printf("The time is %lld.%06lld\n",
59 (long long)tv.tv_sec, (long long)tv.tv_usec);
61 printf("%s failed\n", name);