Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 99 lines 1.6 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2023 Hengqi Chen */ 3 4#include "vmlinux.h" 5#include <bpf/bpf_helpers.h> 6#include <bpf/bpf_tracing.h> 7 8pid_t my_pid = 0; 9 10int test1_result = 0; 11int test2_result = 0; 12int test3_result = 0; 13int test4_result = 0; 14 15SEC("uprobe/./liburandom_read.so:urandlib_api_sameoffset") 16int BPF_UPROBE(test1) 17{ 18 pid_t pid = bpf_get_current_pid_tgid() >> 32; 19 20 if (pid != my_pid) 21 return 0; 22 23 test1_result = 1; 24 return 0; 25} 26 27SEC("uprobe/./liburandom_read.so:urandlib_api_sameoffset@LIBURANDOM_READ_1.0.0") 28int BPF_UPROBE(test2) 29{ 30 pid_t pid = bpf_get_current_pid_tgid() >> 32; 31 32 if (pid != my_pid) 33 return 0; 34 35 test2_result = 1; 36 return 0; 37} 38 39SEC("uretprobe/./liburandom_read.so:urandlib_api_sameoffset@@LIBURANDOM_READ_2.0.0") 40int BPF_URETPROBE(test3, int ret) 41{ 42 pid_t pid = bpf_get_current_pid_tgid() >> 32; 43 44 if (pid != my_pid) 45 return 0; 46 47 test3_result = ret; 48 return 0; 49} 50 51SEC("uprobe") 52int BPF_UPROBE(test4) 53{ 54 pid_t pid = bpf_get_current_pid_tgid() >> 32; 55 56 if (pid != my_pid) 57 return 0; 58 59 test4_result = 1; 60 return 0; 61} 62 63#if defined(__TARGET_ARCH_x86) 64struct pt_regs regs; 65 66SEC("uprobe") 67int BPF_UPROBE(test_regs_change) 68{ 69 pid_t pid = bpf_get_current_pid_tgid() >> 32; 70 71 if (pid != my_pid) 72 return 0; 73 74 ctx->ax = regs.ax; 75 ctx->cx = regs.cx; 76 ctx->dx = regs.dx; 77 ctx->r8 = regs.r8; 78 ctx->r9 = regs.r9; 79 ctx->r10 = regs.r10; 80 ctx->r11 = regs.r11; 81 ctx->di = regs.di; 82 ctx->si = regs.si; 83 return 0; 84} 85 86unsigned long ip; 87 88SEC("uprobe") 89int BPF_UPROBE(test_regs_change_ip) 90{ 91 pid_t pid = bpf_get_current_pid_tgid() >> 32; 92 93 if (pid != my_pid) 94 return 0; 95 96 ctx->ip = ip; 97 return 0; 98} 99#endif