106 lines · c
1// SPDX-License-Identifier: GPL-2.02#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_IBT18 * 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}106