Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/bpf.h>
0003 #include <bpf/bpf_helpers.h>
0004 #include <bpf/bpf_tracing.h>
0005 
0006 char _license[] SEC("license") = "GPL";
0007 
0008 extern const void bpf_fentry_test1 __ksym;
0009 extern const void bpf_fentry_test2 __ksym;
0010 extern const void bpf_fentry_test3 __ksym;
0011 extern const void bpf_fentry_test4 __ksym;
0012 extern const void bpf_modify_return_test __ksym;
0013 extern const void bpf_fentry_test6 __ksym;
0014 extern const void bpf_fentry_test7 __ksym;
0015 
0016 __u64 test1_result = 0;
0017 SEC("fentry/bpf_fentry_test1")
0018 int BPF_PROG(test1, int a)
0019 {
0020     __u64 addr = bpf_get_func_ip(ctx);
0021 
0022     test1_result = (const void *) addr == &bpf_fentry_test1;
0023     return 0;
0024 }
0025 
0026 __u64 test2_result = 0;
0027 SEC("fexit/bpf_fentry_test2")
0028 int BPF_PROG(test2, int a)
0029 {
0030     __u64 addr = bpf_get_func_ip(ctx);
0031 
0032     test2_result = (const void *) addr == &bpf_fentry_test2;
0033     return 0;
0034 }
0035 
0036 __u64 test3_result = 0;
0037 SEC("kprobe/bpf_fentry_test3")
0038 int test3(struct pt_regs *ctx)
0039 {
0040     __u64 addr = bpf_get_func_ip(ctx);
0041 
0042     test3_result = (const void *) addr == &bpf_fentry_test3;
0043     return 0;
0044 }
0045 
0046 __u64 test4_result = 0;
0047 SEC("kretprobe/bpf_fentry_test4")
0048 int BPF_KRETPROBE(test4)
0049 {
0050     __u64 addr = bpf_get_func_ip(ctx);
0051 
0052     test4_result = (const void *) addr == &bpf_fentry_test4;
0053     return 0;
0054 }
0055 
0056 __u64 test5_result = 0;
0057 SEC("fmod_ret/bpf_modify_return_test")
0058 int BPF_PROG(test5, int a, int *b, int ret)
0059 {
0060     __u64 addr = bpf_get_func_ip(ctx);
0061 
0062     test5_result = (const void *) addr == &bpf_modify_return_test;
0063     return ret;
0064 }
0065 
0066 __u64 test6_result = 0;
0067 SEC("kprobe/bpf_fentry_test6+0x5")
0068 int test6(struct pt_regs *ctx)
0069 {
0070     __u64 addr = bpf_get_func_ip(ctx);
0071 
0072     test6_result = (const void *) addr == &bpf_fentry_test6 + 5;
0073     return 0;
0074 }
0075 
0076 __u64 test7_result = 0;
0077 SEC("kprobe/bpf_fentry_test7+5")
0078 int test7(struct pt_regs *ctx)
0079 {
0080     __u64 addr = bpf_get_func_ip(ctx);
0081 
0082     test7_result = (const void *) addr == &bpf_fentry_test7 + 5;
0083     return 0;
0084 }