staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / vDSO / vdso_test.c
blob719d5a6bd664cbcc620ecbf9e953621fc1858942
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * vdso_test.c: Sample code to test parse_vdso.c
4 * Copyright (c) 2014 Andy Lutomirski
6 * Compile with:
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.
12 #include <stdint.h>
13 #include <elf.h>
14 #include <stdio.h>
15 #include <sys/auxv.h>
16 #include <sys/time.h>
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
27 * a special case.
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
37 int main(int argc, char **argv)
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;
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);
51 if (!gtod) {
52 printf("Could not find %s\n", name);
53 return KSFT_SKIP;
56 struct timeval tv;
57 long ret = gtod(&tv, 0);
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;
67 return 0;