Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/bpf: add ksym_get_addr() in trace_helpers

Given a kernel function name, ksym_get_addr() will return the kernel
address for this function, or 0 if it cannot find this function name
in /proc/kallsyms. This function will be used later when a kernel
address is used to initiate a kprobe perf event.

Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Yonghong Song and committed by
Alexei Starovoitov
73bc4d9f 30687ad9

+13
+12
tools/testing/selftests/bpf/trace_helpers.c
··· 72 72 return &syms[0]; 73 73 } 74 74 75 + long ksym_get_addr(const char *name) 76 + { 77 + int i; 78 + 79 + for (i = 0; i < sym_cnt; i++) { 80 + if (strcmp(syms[i].name, name) == 0) 81 + return syms[i].addr; 82 + } 83 + 84 + return 0; 85 + } 86 + 75 87 static int page_size; 76 88 static int page_cnt = 8; 77 89 static struct perf_event_mmap_page *header;
+1
tools/testing/selftests/bpf/trace_helpers.h
··· 11 11 12 12 int load_kallsyms(void); 13 13 struct ksym *ksym_search(long key); 14 + long ksym_get_addr(const char *name); 14 15 15 16 typedef enum bpf_perf_event_ret (*perf_event_print_fn)(void *data, int size); 16 17