Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2022, Oracle and/or its affiliates. */
0003 
0004 #include "vmlinux.h"
0005 
0006 #include <bpf/bpf_core_read.h>
0007 #include <bpf/bpf_helpers.h>
0008 #include <bpf/bpf_tracing.h>
0009 
0010 int uprobe_byname_parm1 = 0;
0011 int uprobe_byname_ran = 0;
0012 int uretprobe_byname_rc = 0;
0013 int uretprobe_byname_ran = 0;
0014 size_t uprobe_byname2_parm1 = 0;
0015 int uprobe_byname2_ran = 0;
0016 char *uretprobe_byname2_rc = NULL;
0017 int uretprobe_byname2_ran = 0;
0018 
0019 int test_pid;
0020 
0021 /* This program cannot auto-attach, but that should not stop other
0022  * programs from attaching.
0023  */
0024 SEC("uprobe")
0025 int handle_uprobe_noautoattach(struct pt_regs *ctx)
0026 {
0027     return 0;
0028 }
0029 
0030 SEC("uprobe//proc/self/exe:autoattach_trigger_func")
0031 int handle_uprobe_byname(struct pt_regs *ctx)
0032 {
0033     uprobe_byname_parm1 = PT_REGS_PARM1_CORE(ctx);
0034     uprobe_byname_ran = 1;
0035     return 0;
0036 }
0037 
0038 SEC("uretprobe//proc/self/exe:autoattach_trigger_func")
0039 int handle_uretprobe_byname(struct pt_regs *ctx)
0040 {
0041     uretprobe_byname_rc = PT_REGS_RC_CORE(ctx);
0042     uretprobe_byname_ran = 2;
0043     return 0;
0044 }
0045 
0046 
0047 SEC("uprobe/libc.so.6:malloc")
0048 int handle_uprobe_byname2(struct pt_regs *ctx)
0049 {
0050     int pid = bpf_get_current_pid_tgid() >> 32;
0051 
0052     /* ignore irrelevant invocations */
0053     if (test_pid != pid)
0054         return 0;
0055     uprobe_byname2_parm1 = PT_REGS_PARM1_CORE(ctx);
0056     uprobe_byname2_ran = 3;
0057     return 0;
0058 }
0059 
0060 SEC("uretprobe/libc.so.6:malloc")
0061 int handle_uretprobe_byname2(struct pt_regs *ctx)
0062 {
0063     int pid = bpf_get_current_pid_tgid() >> 32;
0064 
0065     /* ignore irrelevant invocations */
0066     if (test_pid != pid)
0067         return 0;
0068     uretprobe_byname2_rc = (char *)PT_REGS_RC_CORE(ctx);
0069     uretprobe_byname2_ran = 4;
0070     return 0;
0071 }
0072 
0073 char _license[] SEC("license") = "GPL";