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 #include <stdbool.h>
6
7 char _license[] SEC("license") = "GPL";
8
9 extern const void bpf_fentry_test1 __ksym;
10 extern const void bpf_fentry_test2 __ksym;
11 extern const void bpf_fentry_test3 __ksym;
12 extern const void bpf_fentry_test4 __ksym;
13 extern const void bpf_modify_return_test __ksym;
14 extern const void bpf_fentry_test6 __ksym;
15 extern const void bpf_fentry_test7 __ksym;
16
17 extern bool CONFIG_X86_KERNEL_IBT __kconfig __weak;
18
19 /* This function is here to have CONFIG_X86_KERNEL_IBT
20 * used and added to object BTF.
21 */
unused(void)22 int unused(void)
23 {
24 return CONFIG_X86_KERNEL_IBT ? 0 : 1;
25 }
26
27 __u64 test1_result = 0;
28 SEC("fentry/bpf_fentry_test1")
BPF_PROG(test1,int a)29 int BPF_PROG(test1, int a)
30 {
31 __u64 addr = bpf_get_func_ip(ctx);
32
33 test1_result = (const void *) addr == &bpf_fentry_test1;
34 return 0;
35 }
36
37 __u64 test2_result = 0;
38 SEC("fexit/bpf_fentry_test2")
BPF_PROG(test2,int a)39 int BPF_PROG(test2, int a)
40 {
41 __u64 addr = bpf_get_func_ip(ctx);
42
43 test2_result = (const void *) addr == &bpf_fentry_test2;
44 return 0;
45 }
46
47 __u64 test3_result = 0;
48 SEC("kprobe/bpf_fentry_test3")
test3(struct pt_regs * ctx)49 int test3(struct pt_regs *ctx)
50 {
51 __u64 addr = bpf_get_func_ip(ctx);
52
53 test3_result = (const void *) addr == &bpf_fentry_test3;
54 return 0;
55 }
56
57 __u64 test4_result = 0;
58 SEC("kretprobe/bpf_fentry_test4")
BPF_KRETPROBE(test4)59 int BPF_KRETPROBE(test4)
60 {
61 __u64 addr = bpf_get_func_ip(ctx);
62
63 test4_result = (const void *) addr == &bpf_fentry_test4;
64 return 0;
65 }
66
67 __u64 test5_result = 0;
68 SEC("fmod_ret/bpf_modify_return_test")
BPF_PROG(test5,int a,int * b,int ret)69 int BPF_PROG(test5, int a, int *b, int ret)
70 {
71 __u64 addr = bpf_get_func_ip(ctx);
72
73 test5_result = (const void *) addr == &bpf_modify_return_test;
74 return ret;
75 }
76
77 __u64 test6_result = 0;
78 SEC("?kprobe")
test6(struct pt_regs * ctx)79 int test6(struct pt_regs *ctx)
80 {
81 __u64 addr = bpf_get_func_ip(ctx);
82
83 test6_result = (const void *) addr == 0;
84 return 0;
85 }
86