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 #ifndef PARSE_VDSO_H__ 8*49cdfc7eSAndroid Build Coastguard Worker #define PARSE_VDSO_H__ 9*49cdfc7eSAndroid Build Coastguard Worker 10*49cdfc7eSAndroid Build Coastguard Worker #include <stdint.h> 11*49cdfc7eSAndroid Build Coastguard Worker 12*49cdfc7eSAndroid Build Coastguard Worker /* 13*49cdfc7eSAndroid Build Coastguard Worker * To use this vDSO parser, first call one of the vdso_init_* functions. 14*49cdfc7eSAndroid Build Coastguard Worker * If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR 15*49cdfc7eSAndroid Build Coastguard Worker * to vdso_init_from_sysinfo_ehdr. Otherwise pass auxv to vdso_init_from_auxv. 16*49cdfc7eSAndroid Build Coastguard Worker * Then call vdso_sym for each symbol you want. For example, to look up 17*49cdfc7eSAndroid Build Coastguard Worker * gettimeofday on x86_64, use: 18*49cdfc7eSAndroid Build Coastguard Worker * 19*49cdfc7eSAndroid Build Coastguard Worker * <some pointer> = vdso_sym("LINUX_2.6", "gettimeofday"); 20*49cdfc7eSAndroid Build Coastguard Worker * or 21*49cdfc7eSAndroid Build Coastguard Worker * <some pointer> = vdso_sym("LINUX_2.6", "__vdso_gettimeofday"); 22*49cdfc7eSAndroid Build Coastguard Worker * 23*49cdfc7eSAndroid Build Coastguard Worker * vdso_sym will return 0 if the symbol doesn't exist or if the init function 24*49cdfc7eSAndroid Build Coastguard Worker * failed or was not called. vdso_sym is a little slow, so its return value 25*49cdfc7eSAndroid Build Coastguard Worker * should be cached. 26*49cdfc7eSAndroid Build Coastguard Worker * 27*49cdfc7eSAndroid Build Coastguard Worker * vdso_sym is threadsafe; the init functions are not. 28*49cdfc7eSAndroid Build Coastguard Worker * 29*49cdfc7eSAndroid Build Coastguard Worker * These are the prototypes: 30*49cdfc7eSAndroid Build Coastguard Worker */ 31*49cdfc7eSAndroid Build Coastguard Worker 32*49cdfc7eSAndroid Build Coastguard Worker #include <time.h> 33*49cdfc7eSAndroid Build Coastguard Worker 34*49cdfc7eSAndroid Build Coastguard Worker extern void vdso_init_from_auxv(void *auxv); 35*49cdfc7eSAndroid Build Coastguard Worker extern void vdso_init_from_sysinfo_ehdr(uintptr_t base); 36*49cdfc7eSAndroid Build Coastguard Worker extern void *vdso_sym(const char *version, const char *name); 37*49cdfc7eSAndroid Build Coastguard Worker 38*49cdfc7eSAndroid Build Coastguard Worker typedef int (*gettime_t)(clockid_t clk_id, void *ts); 39*49cdfc7eSAndroid Build Coastguard Worker void find_clock_gettime_vdso(gettime_t *ptr_vdso_gettime, 40*49cdfc7eSAndroid Build Coastguard Worker gettime_t *ptr_vdso_gettime64); 41*49cdfc7eSAndroid Build Coastguard Worker #endif /* PARSE_VDSO_H__ */ 42