1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/bpf.h>
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
5
6 char _license[] SEC("license") = "GPL";
7
8 extern const void bpf_fentry_test1 __ksym;
9 extern const void bpf_fentry_test2 __ksym;
10 extern const void bpf_fentry_test3 __ksym;
11 extern const void bpf_fentry_test4 __ksym;
12 extern const void bpf_modify_return_test __ksym;
13 extern const void bpf_fentry_test6 __ksym;
14 extern const void bpf_fentry_test7 __ksym;
15
16 __u64 test1_result = 0;
17 SEC("fentry/bpf_fentry_test1")
BPF_PROG(test1,int a)18 int BPF_PROG(test1, int a)
19 {
20 __u64 addr = bpf_get_func_ip(ctx);
21
22 test1_result = (const void *) addr == &bpf_fentry_test1;
23 return 0;
24 }
25
26 __u64 test2_result = 0;
27 SEC("fexit/bpf_fentry_test2")
BPF_PROG(test2,int a)28 int BPF_PROG(test2, int a)
29 {
30 __u64 addr = bpf_get_func_ip(ctx);
31
32 test2_result = (const void *) addr == &bpf_fentry_test2;
33 return 0;
34 }
35
36 __u64 test3_result = 0;
37 SEC("kprobe/bpf_fentry_test3")
test3(struct pt_regs * ctx)38 int test3(struct pt_regs *ctx)
39 {
40 __u64 addr = bpf_get_func_ip(ctx);
41
42 test3_result = (const void *) addr == &bpf_fentry_test3;
43 return 0;
44 }
45
46 __u64 test4_result = 0;
47 SEC("kretprobe/bpf_fentry_test4")
BPF_KRETPROBE(test4)48 int BPF_KRETPROBE(test4)
49 {
50 __u64 addr = bpf_get_func_ip(ctx);
51
52 test4_result = (const void *) addr == &bpf_fentry_test4;
53 return 0;
54 }
55
56 __u64 test5_result = 0;
57 SEC("fmod_ret/bpf_modify_return_test")
BPF_PROG(test5,int a,int * b,int ret)58 int BPF_PROG(test5, int a, int *b, int ret)
59 {
60 __u64 addr = bpf_get_func_ip(ctx);
61
62 test5_result = (const void *) addr == &bpf_modify_return_test;
63 return ret;
64 }
65
66 __u64 test6_result = 0;
67 SEC("kprobe/bpf_fentry_test6+0x5")
test6(struct pt_regs * ctx)68 int test6(struct pt_regs *ctx)
69 {
70 __u64 addr = bpf_get_func_ip(ctx);
71
72 test6_result = (const void *) addr == &bpf_fentry_test6 + 5;
73 return 0;
74 }
75
76 __u64 test7_result = 0;
77 SEC("kprobe/bpf_fentry_test7+5")
test7(struct pt_regs * ctx)78 int test7(struct pt_regs *ctx)
79 {
80 __u64 addr = bpf_get_func_ip(ctx);
81
82 test7_result = (const void *) addr == &bpf_fentry_test7 + 5;
83 return 0;
84 }
85