1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright (c) 2017 Facebook 3 4 #include <linux/ptrace.h> 5 #include <linux/bpf.h> 6 #include <bpf/bpf_helpers.h> 7 #include <bpf/bpf_tracing.h> 8 9 int kprobe_res = 0; 10 int kretprobe_res = 0; 11 int uprobe_res = 0; 12 int uretprobe_res = 0; 13 int uprobe_byname_res = 0; 14 int uretprobe_byname_res = 0; 15 int uprobe_byname2_res = 0; 16 int uretprobe_byname2_res = 0; 17 18 SEC("kprobe/sys_nanosleep") 19 int handle_kprobe(struct pt_regs *ctx) 20 { 21 kprobe_res = 1; 22 return 0; 23 } 24 25 SEC("kretprobe/sys_nanosleep") 26 int BPF_KRETPROBE(handle_kretprobe) 27 { 28 kretprobe_res = 2; 29 return 0; 30 } 31 32 SEC("uprobe") 33 int handle_uprobe(struct pt_regs *ctx) 34 { 35 uprobe_res = 3; 36 return 0; 37 } 38 39 SEC("uretprobe") 40 int handle_uretprobe(struct pt_regs *ctx) 41 { 42 uretprobe_res = 4; 43 return 0; 44 } 45 46 SEC("uprobe") 47 int handle_uprobe_byname(struct pt_regs *ctx) 48 { 49 uprobe_byname_res = 5; 50 return 0; 51 } 52 53 /* use auto-attach format for section definition. */ 54 SEC("uretprobe//proc/self/exe:trigger_func2") 55 int handle_uretprobe_byname(struct pt_regs *ctx) 56 { 57 uretprobe_byname_res = 6; 58 return 0; 59 } 60 61 SEC("uprobe") 62 int handle_uprobe_byname2(struct pt_regs *ctx) 63 { 64 unsigned int size = PT_REGS_PARM1(ctx); 65 66 /* verify malloc size */ 67 if (size == 1) 68 uprobe_byname2_res = 7; 69 return 0; 70 } 71 72 SEC("uretprobe") 73 int handle_uretprobe_byname2(struct pt_regs *ctx) 74 { 75 uretprobe_byname2_res = 8; 76 return 0; 77 } 78 79 char _license[] SEC("license") = "GPL"; 80