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