Loading...
1// SPDX-License-Identifier: GPL-2.0
2#include "vmlinux.h"
3#include <bpf/bpf_helpers.h>
4#include <bpf/bpf_tracing.h>
5
6char _license[] SEC("license") = "GPL";
7
8extern int bpf_fentry_test1(int a) __ksym;
9extern int bpf_modify_return_test(int a, int *b) __ksym;
10
11extern const void bpf_fentry_test2 __ksym;
12extern const void bpf_fentry_test3 __ksym;
13extern const void bpf_fentry_test4 __ksym;
14
15extern bool CONFIG_X86_KERNEL_IBT __kconfig __weak;
16
17/* This function is here to have CONFIG_X86_KERNEL_IBT
18 * used and added to object BTF.
19 */
20int unused(void)
21{
22 return CONFIG_X86_KERNEL_IBT ? 0 : 1;
23}
24
25__u64 test1_result = 0;
26SEC("fentry/bpf_fentry_test1")
27int BPF_PROG(test1, int a)
28{
29 __u64 addr = bpf_get_func_ip(ctx);
30
31 test1_result = (const void *) addr == &bpf_fentry_test1;
32 return 0;
33}
34
35__u64 test2_result = 0;
36SEC("fexit/bpf_fentry_test2")
37int BPF_PROG(test2, int a)
38{
39 __u64 addr = bpf_get_func_ip(ctx);
40
41 test2_result = (const void *) addr == &bpf_fentry_test2;
42 return 0;
43}
44
45__u64 test3_result = 0;
46SEC("kprobe/bpf_fentry_test3")
47int test3(struct pt_regs *ctx)
48{
49 __u64 addr = bpf_get_func_ip(ctx);
50
51 test3_result = (const void *) addr == &bpf_fentry_test3;
52 return 0;
53}
54
55__u64 test4_result = 0;
56SEC("kretprobe/bpf_fentry_test4")
57int BPF_KRETPROBE(test4)
58{
59 __u64 addr = bpf_get_func_ip(ctx);
60
61 test4_result = (const void *) addr == &bpf_fentry_test4;
62 return 0;
63}
64
65__u64 test5_result = 0;
66SEC("fmod_ret/bpf_modify_return_test")
67int BPF_PROG(test5, int a, int *b, int ret)
68{
69 __u64 addr = bpf_get_func_ip(ctx);
70
71 test5_result = (const void *) addr == &bpf_modify_return_test;
72 return ret;
73}
74
75__u64 test6_result = 0;
76SEC("?kprobe")
77int test6(struct pt_regs *ctx)
78{
79 __u64 addr = bpf_get_func_ip(ctx);
80
81 test6_result = (const void *) addr == 0;
82 return 0;
83}
84
85unsigned long uprobe_trigger;
86
87__u64 test7_result = 0;
88SEC("uprobe//proc/self/exe:uprobe_trigger")
89int BPF_UPROBE(test7)
90{
91 __u64 addr = bpf_get_func_ip(ctx);
92
93 test7_result = (const void *) addr == (const void *) uprobe_trigger;
94 return 0;
95}
96
97__u64 test8_result = 0;
98SEC("uretprobe//proc/self/exe:uprobe_trigger")
99int BPF_URETPROBE(test8, int ret)
100{
101 __u64 addr = bpf_get_func_ip(ctx);
102
103 test8_result = (const void *) addr == (const void *) uprobe_trigger;
104 return 0;
105}
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
7char _license[] SEC("license") = "GPL";
8
9extern const void bpf_fentry_test1 __ksym;
10extern const void bpf_fentry_test2 __ksym;
11extern const void bpf_fentry_test3 __ksym;
12extern const void bpf_fentry_test4 __ksym;
13extern const void bpf_modify_return_test __ksym;
14extern const void bpf_fentry_test6 __ksym;
15extern const void bpf_fentry_test7 __ksym;
16
17extern 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 */
22int unused(void)
23{
24 return CONFIG_X86_KERNEL_IBT ? 0 : 1;
25}
26
27__u64 test1_result = 0;
28SEC("fentry/bpf_fentry_test1")
29int 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;
38SEC("fexit/bpf_fentry_test2")
39int 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;
48SEC("kprobe/bpf_fentry_test3")
49int 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;
58SEC("kretprobe/bpf_fentry_test4")
59int 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;
68SEC("fmod_ret/bpf_modify_return_test")
69int 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;
78SEC("?kprobe")
79int 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}