get_func_ip_test.c (1876B)
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 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 16__u64 test1_result = 0; 17SEC("fentry/bpf_fentry_test1") 18int BPF_PROG(test1, int a) 19{ 20 __u64 addr = bpf_get_func_ip(ctx); 21 22 test1_result = (const void *) addr == &bpf_fentry_test1; 23 return 0; 24} 25 26__u64 test2_result = 0; 27SEC("fexit/bpf_fentry_test2") 28int BPF_PROG(test2, int a) 29{ 30 __u64 addr = bpf_get_func_ip(ctx); 31 32 test2_result = (const void *) addr == &bpf_fentry_test2; 33 return 0; 34} 35 36__u64 test3_result = 0; 37SEC("kprobe/bpf_fentry_test3") 38int test3(struct pt_regs *ctx) 39{ 40 __u64 addr = bpf_get_func_ip(ctx); 41 42 test3_result = (const void *) addr == &bpf_fentry_test3; 43 return 0; 44} 45 46__u64 test4_result = 0; 47SEC("kretprobe/bpf_fentry_test4") 48int BPF_KRETPROBE(test4) 49{ 50 __u64 addr = bpf_get_func_ip(ctx); 51 52 test4_result = (const void *) addr == &bpf_fentry_test4; 53 return 0; 54} 55 56__u64 test5_result = 0; 57SEC("fmod_ret/bpf_modify_return_test") 58int BPF_PROG(test5, int a, int *b, int ret) 59{ 60 __u64 addr = bpf_get_func_ip(ctx); 61 62 test5_result = (const void *) addr == &bpf_modify_return_test; 63 return ret; 64} 65 66__u64 test6_result = 0; 67SEC("kprobe/bpf_fentry_test6+0x5") 68int test6(struct pt_regs *ctx) 69{ 70 __u64 addr = bpf_get_func_ip(ctx); 71 72 test6_result = (const void *) addr == &bpf_fentry_test6 + 5; 73 return 0; 74} 75 76__u64 test7_result = 0; 77SEC("kprobe/bpf_fentry_test7+5") 78int test7(struct pt_regs *ctx) 79{ 80 __u64 addr = bpf_get_func_ip(ctx); 81 82 test7_result = (const void *) addr == &bpf_fentry_test7 + 5; 83 return 0; 84}