1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2022, Oracle and/or its affiliates. */
3 
4 #include "vmlinux.h"
5 
6 #include <bpf/bpf_core_read.h>
7 #include <bpf/bpf_helpers.h>
8 #include <bpf/bpf_tracing.h>
9 
10 int uprobe_byname_parm1 = 0;
11 int uprobe_byname_ran = 0;
12 int uretprobe_byname_rc = 0;
13 int uretprobe_byname_ran = 0;
14 size_t uprobe_byname2_parm1 = 0;
15 int uprobe_byname2_ran = 0;
16 char *uretprobe_byname2_rc = NULL;
17 int uretprobe_byname2_ran = 0;
18 
19 int test_pid;
20 
21 /* This program cannot auto-attach, but that should not stop other
22  * programs from attaching.
23  */
24 SEC("uprobe")
25 int handle_uprobe_noautoattach(struct pt_regs *ctx)
26 {
27 	return 0;
28 }
29 
30 SEC("uprobe//proc/self/exe:autoattach_trigger_func")
31 int handle_uprobe_byname(struct pt_regs *ctx)
32 {
33 	uprobe_byname_parm1 = PT_REGS_PARM1_CORE(ctx);
34 	uprobe_byname_ran = 1;
35 	return 0;
36 }
37 
38 SEC("uretprobe//proc/self/exe:autoattach_trigger_func")
39 int handle_uretprobe_byname(struct pt_regs *ctx)
40 {
41 	uretprobe_byname_rc = PT_REGS_RC_CORE(ctx);
42 	uretprobe_byname_ran = 2;
43 	return 0;
44 }
45 
46 
47 SEC("uprobe/libc.so.6:malloc")
48 int handle_uprobe_byname2(struct pt_regs *ctx)
49 {
50 	int pid = bpf_get_current_pid_tgid() >> 32;
51 
52 	/* ignore irrelevant invocations */
53 	if (test_pid != pid)
54 		return 0;
55 	uprobe_byname2_parm1 = PT_REGS_PARM1_CORE(ctx);
56 	uprobe_byname2_ran = 3;
57 	return 0;
58 }
59 
60 SEC("uretprobe/libc.so.6:malloc")
61 int handle_uretprobe_byname2(struct pt_regs *ctx)
62 {
63 	int pid = bpf_get_current_pid_tgid() >> 32;
64 
65 	/* ignore irrelevant invocations */
66 	if (test_pid != pid)
67 		return 0;
68 	uretprobe_byname2_rc = (char *)PT_REGS_RC_CORE(ctx);
69 	uretprobe_byname2_ran = 4;
70 	return 0;
71 }
72 
73 char _license[] SEC("license") = "GPL";
74