xref: /linux/tools/testing/selftests/bpf/trace_helpers.h (revision 34dc1baba215b826e454b8d19e4f24adbeb7d00d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __TRACE_HELPER_H
3 #define __TRACE_HELPER_H
4 
5 #include <bpf/libbpf.h>
6 
7 #define __ALIGN_MASK(x, mask)	(((x)+(mask))&~(mask))
8 #define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a)-1)
9 
10 struct ksym {
11 	long addr;
12 	char *name;
13 };
14 
15 int load_kallsyms(void);
16 int load_kallsyms_refresh(void);
17 
18 struct ksym *ksym_search(long key);
19 long ksym_get_addr(const char *name);
20 
21 /* open kallsyms and find addresses on the fly, faster than load + search. */
22 int kallsyms_find(const char *sym, unsigned long long *addr);
23 
24 void read_trace_pipe(void);
25 
26 ssize_t get_uprobe_offset(const void *addr);
27 ssize_t get_rel_offset(uintptr_t addr);
28 
29 int read_build_id(const char *path, char *build_id, size_t size);
30 
31 #endif
32