xref: /OK3568_Linux_fs/kernel/tools/testing/selftests/vDSO/parse_vdso.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun #ifndef PARSE_VDSO_H
4*4882a593Smuzhiyun #define PARSE_VDSO_H
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #include <stdint.h>
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun /*
9*4882a593Smuzhiyun  * To use this vDSO parser, first call one of the vdso_init_* functions.
10*4882a593Smuzhiyun  * If you've already parsed auxv, then pass the value of AT_SYSINFO_EHDR
11*4882a593Smuzhiyun  * to vdso_init_from_sysinfo_ehdr.  Otherwise pass auxv to vdso_init_from_auxv.
12*4882a593Smuzhiyun  * Then call vdso_sym for each symbol you want.  For example, to look up
13*4882a593Smuzhiyun  * gettimeofday on x86_64, use:
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  *     <some pointer> = vdso_sym("LINUX_2.6", "gettimeofday");
16*4882a593Smuzhiyun  * or
17*4882a593Smuzhiyun  *     <some pointer> = vdso_sym("LINUX_2.6", "__vdso_gettimeofday");
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * vdso_sym will return 0 if the symbol doesn't exist or if the init function
20*4882a593Smuzhiyun  * failed or was not called.  vdso_sym is a little slow, so its return value
21*4882a593Smuzhiyun  * should be cached.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * vdso_sym is threadsafe; the init functions are not.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * These are the prototypes:
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun void *vdso_sym(const char *version, const char *name);
28*4882a593Smuzhiyun void vdso_init_from_sysinfo_ehdr(uintptr_t base);
29*4882a593Smuzhiyun void vdso_init_from_auxv(void *auxv);
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #endif
32