~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/uprobe_multi.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include "vmlinux.h"
  3 #include <bpf/bpf_helpers.h>
  4 #include <bpf/bpf_tracing.h>
  5 #include <bpf/usdt.bpf.h>
  6 
  7 char _license[] SEC("license") = "GPL";
  8 
  9 __u64 uprobe_multi_func_1_addr = 0;
 10 __u64 uprobe_multi_func_2_addr = 0;
 11 __u64 uprobe_multi_func_3_addr = 0;
 12 
 13 __u64 uprobe_multi_func_1_result = 0;
 14 __u64 uprobe_multi_func_2_result = 0;
 15 __u64 uprobe_multi_func_3_result = 0;
 16 
 17 __u64 uretprobe_multi_func_1_result = 0;
 18 __u64 uretprobe_multi_func_2_result = 0;
 19 __u64 uretprobe_multi_func_3_result = 0;
 20 
 21 __u64 uprobe_multi_sleep_result = 0;
 22 
 23 int pid = 0;
 24 int child_pid = 0;
 25 int child_tid = 0;
 26 int child_pid_usdt = 0;
 27 int child_tid_usdt = 0;
 28 
 29 int expect_pid = 0;
 30 bool bad_pid_seen = false;
 31 bool bad_pid_seen_usdt = false;
 32 
 33 bool test_cookie = false;
 34 void *user_ptr = 0;
 35 
 36 static __always_inline bool verify_sleepable_user_copy(void)
 37 {
 38         char data[9];
 39 
 40         bpf_copy_from_user(data, sizeof(data), user_ptr);
 41         return bpf_strncmp(data, sizeof(data), "test_data") == 0;
 42 }
 43 
 44 static void uprobe_multi_check(void *ctx, bool is_return, bool is_sleep)
 45 {
 46         __u64 cur_pid_tgid = bpf_get_current_pid_tgid();
 47         __u32 cur_pid;
 48 
 49         cur_pid = cur_pid_tgid >> 32;
 50         if (pid && cur_pid != pid)
 51                 return;
 52 
 53         if (expect_pid && cur_pid != expect_pid)
 54                 bad_pid_seen = true;
 55 
 56         child_pid = cur_pid_tgid >> 32;
 57         child_tid = (__u32)cur_pid_tgid;
 58 
 59         __u64 cookie = test_cookie ? bpf_get_attach_cookie(ctx) : 0;
 60         __u64 addr = bpf_get_func_ip(ctx);
 61 
 62 #define SET(__var, __addr, __cookie) ({                 \
 63         if (addr == __addr &&                           \
 64            (!test_cookie || (cookie == __cookie)))      \
 65                 __var += 1;                             \
 66 })
 67 
 68         if (is_return) {
 69                 SET(uretprobe_multi_func_1_result, uprobe_multi_func_1_addr, 2);
 70                 SET(uretprobe_multi_func_2_result, uprobe_multi_func_2_addr, 3);
 71                 SET(uretprobe_multi_func_3_result, uprobe_multi_func_3_addr, 1);
 72         } else {
 73                 SET(uprobe_multi_func_1_result, uprobe_multi_func_1_addr, 3);
 74                 SET(uprobe_multi_func_2_result, uprobe_multi_func_2_addr, 1);
 75                 SET(uprobe_multi_func_3_result, uprobe_multi_func_3_addr, 2);
 76         }
 77 
 78 #undef SET
 79 
 80         if (is_sleep && verify_sleepable_user_copy())
 81                 uprobe_multi_sleep_result += 1;
 82 }
 83 
 84 SEC("uprobe.multi//proc/self/exe:uprobe_multi_func_*")
 85 int uprobe(struct pt_regs *ctx)
 86 {
 87         uprobe_multi_check(ctx, false, false);
 88         return 0;
 89 }
 90 
 91 SEC("uretprobe.multi//proc/self/exe:uprobe_multi_func_*")
 92 int uretprobe(struct pt_regs *ctx)
 93 {
 94         uprobe_multi_check(ctx, true, false);
 95         return 0;
 96 }
 97 
 98 SEC("uprobe.multi.s//proc/self/exe:uprobe_multi_func_*")
 99 int uprobe_sleep(struct pt_regs *ctx)
100 {
101         uprobe_multi_check(ctx, false, true);
102         return 0;
103 }
104 
105 SEC("uretprobe.multi.s//proc/self/exe:uprobe_multi_func_*")
106 int uretprobe_sleep(struct pt_regs *ctx)
107 {
108         uprobe_multi_check(ctx, true, true);
109         return 0;
110 }
111 
112 SEC("uprobe.multi//proc/self/exe:uprobe_multi_func_*")
113 int uprobe_extra(struct pt_regs *ctx)
114 {
115         /* we need this one just to mix PID-filtered and global uprobes */
116         return 0;
117 }
118 
119 SEC("usdt")
120 int usdt_pid(struct pt_regs *ctx)
121 {
122         __u64 cur_pid_tgid = bpf_get_current_pid_tgid();
123         __u32 cur_pid;
124 
125         cur_pid = cur_pid_tgid >> 32;
126         if (pid && cur_pid != pid)
127                 return 0;
128 
129         if (expect_pid && cur_pid != expect_pid)
130                 bad_pid_seen_usdt = true;
131 
132         child_pid_usdt = cur_pid_tgid >> 32;
133         child_tid_usdt = (__u32)cur_pid_tgid;
134 
135         return 0;
136 }
137 
138 SEC("usdt")
139 int usdt_extra(struct pt_regs *ctx)
140 {
141         /* we need this one just to mix PID-filtered and global USDT probes */
142         return 0;
143 }
144 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php