xref: /linux/tools/testing/selftests/bpf/trace_helpers.h (revision ae22a94997b8a03dcb3c922857c203246711f9d4)
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 struct ksyms;
15 
16 int load_kallsyms(void);
17 struct ksym *ksym_search(long key);
18 long ksym_get_addr(const char *name);
19 
20 struct ksyms *load_kallsyms_local(void);
21 struct ksym *ksym_search_local(struct ksyms *ksyms, long key);
22 long ksym_get_addr_local(struct ksyms *ksyms, const char *name);
23 void free_kallsyms_local(struct ksyms *ksyms);
24 
25 /* open kallsyms and find addresses on the fly, faster than load + search. */
26 int kallsyms_find(const char *sym, unsigned long long *addr);
27 
28 void read_trace_pipe(void);
29 
30 ssize_t get_uprobe_offset(const void *addr);
31 ssize_t get_rel_offset(uintptr_t addr);
32 
33 int read_build_id(const char *path, char *build_id, size_t size);
34 
35 #endif
36