linux/tools/testing/selftests/bpf/progs/get_func_ip_test.c
Jiri Olsa e3f9bc35ea libbpf: Allow decimal offset for kprobes
Allow to specify decimal offset in SEC macro, like:
  SEC("kprobe/bpf_fentry_test7+5")

Add selftest for that.

Suggested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
Link: https://lore.kernel.org/bpf/20210721215810.889975-3-jolsa@kernel.org
2021-07-22 20:09:16 -07:00

85 lines
1.8 KiB
C

// SPDX-License-Identifier: GPL-2.0
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
char _license[] SEC("license") = "GPL";
extern const void bpf_fentry_test1 __ksym;
extern const void bpf_fentry_test2 __ksym;
extern const void bpf_fentry_test3 __ksym;
extern const void bpf_fentry_test4 __ksym;
extern const void bpf_modify_return_test __ksym;
extern const void bpf_fentry_test6 __ksym;
extern const void bpf_fentry_test7 __ksym;
__u64 test1_result = 0;
SEC("fentry/bpf_fentry_test1")
int BPF_PROG(test1, int a)
{
__u64 addr = bpf_get_func_ip(ctx);
test1_result = (const void *) addr == &bpf_fentry_test1;
return 0;
}
__u64 test2_result = 0;
SEC("fexit/bpf_fentry_test2")
int BPF_PROG(test2, int a)
{
__u64 addr = bpf_get_func_ip(ctx);
test2_result = (const void *) addr == &bpf_fentry_test2;
return 0;
}
__u64 test3_result = 0;
SEC("kprobe/bpf_fentry_test3")
int test3(struct pt_regs *ctx)
{
__u64 addr = bpf_get_func_ip(ctx);
test3_result = (const void *) addr == &bpf_fentry_test3;
return 0;
}
__u64 test4_result = 0;
SEC("kretprobe/bpf_fentry_test4")
int BPF_KRETPROBE(test4)
{
__u64 addr = bpf_get_func_ip(ctx);
test4_result = (const void *) addr == &bpf_fentry_test4;
return 0;
}
__u64 test5_result = 0;
SEC("fmod_ret/bpf_modify_return_test")
int BPF_PROG(test5, int a, int *b, int ret)
{
__u64 addr = bpf_get_func_ip(ctx);
test5_result = (const void *) addr == &bpf_modify_return_test;
return ret;
}
__u64 test6_result = 0;
SEC("kprobe/bpf_fentry_test6+0x5")
int test6(struct pt_regs *ctx)
{
__u64 addr = bpf_get_func_ip(ctx);
test6_result = (const void *) addr == &bpf_fentry_test6 + 5;
return 0;
}
__u64 test7_result = 0;
SEC("kprobe/bpf_fentry_test7+5")
int test7(struct pt_regs *ctx)
{
__u64 addr = bpf_get_func_ip(ctx);
test7_result = (const void *) addr == &bpf_fentry_test7 + 5;
return 0;
}