• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2020 Linaro Limited. All rights reserved.
4  * Author: Viresh Kumar<viresh.kumar@linaro.org>
5  */
6 
7 #define TST_NO_DEFAULT_MAIN
8 #include "tst_test.h"
9 
10 #include "parse_vdso.h"
11 #include "config.h"
12 
13 #ifdef HAVE_GETAUXVAL
14 # include <sys/auxv.h>
15 #endif /* HAVE_GETAUXVAL */
16 
17 static unsigned long sysinfo_ehdr;
18 
vdso_init(void)19 static void vdso_init(void)
20 {
21 #ifdef HAVE_GETAUXVAL
22 	if (sysinfo_ehdr)
23 		return;
24 
25 	sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
26 	if (!sysinfo_ehdr) {
27 		tst_res(TINFO, "Couldn't find AT_SYSINFO_EHDR");
28 		return;
29 	}
30 
31 	vdso_init_from_sysinfo_ehdr(sysinfo_ehdr);
32 #else
33 	tst_res(TINFO, "getauxval() not supported");
34 #endif /* HAVE_GETAUXVAL */
35 }
36 
find_clock_gettime_vdso(gettime_t * ptr_vdso_gettime,gettime_t * ptr_vdso_gettime64)37 void find_clock_gettime_vdso(gettime_t *ptr_vdso_gettime,
38 			     gettime_t *ptr_vdso_gettime64)
39 {
40 	/*
41 	 * Some vDSO exports its clock_gettime() implementation with a different
42 	 * name and version from other architectures, so we need to handle it as
43 	 * a special case.
44 	 */
45 #if defined(__powerpc__) || defined(__powerpc64__)
46 	const char *version = "LINUX_2.6.15";
47 	const char *name = "__kernel_clock_gettime";
48 #elif defined(__aarch64__)
49 	const char *version = "LINUX_2.6.39";
50 	const char *name = "__kernel_clock_gettime";
51 #elif defined(__s390__)
52 	const char *version = "LINUX_2.6.29";
53 	const char *name = "__kernel_clock_gettime";
54 #elif defined(__nds32__)
55 	const char *version = "LINUX_4";
56 	const char *name = "__vdso_clock_gettime";
57 #elif defined(__riscv)
58 	const char *version = "LINUX_4.15";
59 	const char *name = "__vdso_clock_gettime";
60 #else
61 	const char *version = "LINUX_2.6";
62 	const char *name = "__vdso_clock_gettime";
63 #endif
64 
65 	const char *version64 = "LINUX_2.6";
66 	const char *name64 = "__vdso_clock_gettime64";
67 
68 	vdso_init();
69 
70 	*ptr_vdso_gettime = vdso_sym(version, name);
71 	if (!*ptr_vdso_gettime)
72 		tst_res(TINFO, "Couldn't find vdso_gettime()");
73 
74 	*ptr_vdso_gettime64 = vdso_sym(version64, name64);
75 	if (!*ptr_vdso_gettime64)
76 		tst_res(TINFO, "Couldn't find vdso_gettime64()");
77 }
78