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