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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/test_vmlinux.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 /* Copyright (c) 2020 Facebook */
  3 
  4 #include "vmlinux.h"
  5 #include <asm/unistd.h>
  6 #include <bpf/bpf_helpers.h>
  7 #include <bpf/bpf_tracing.h>
  8 #include <bpf/bpf_core_read.h>
  9 
 10 #define MY_TV_NSEC 1337
 11 
 12 bool tp_called = false;
 13 bool raw_tp_called = false;
 14 bool tp_btf_called = false;
 15 bool kprobe_called = false;
 16 bool fentry_called = false;
 17 
 18 SEC("tp/syscalls/sys_enter_nanosleep")
 19 int handle__tp(struct syscall_trace_enter *args)
 20 {
 21         struct __kernel_timespec *ts;
 22         long tv_nsec;
 23 
 24         if (args->nr != __NR_nanosleep)
 25                 return 0;
 26 
 27         ts = (void *)args->args[0];
 28         if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
 29             tv_nsec != MY_TV_NSEC)
 30                 return 0;
 31 
 32         tp_called = true;
 33         return 0;
 34 }
 35 
 36 SEC("raw_tp/sys_enter")
 37 int BPF_PROG(handle__raw_tp, struct pt_regs *regs, long id)
 38 {
 39         struct __kernel_timespec *ts;
 40         long tv_nsec;
 41 
 42         if (id != __NR_nanosleep)
 43                 return 0;
 44 
 45         ts = (void *)PT_REGS_PARM1_CORE_SYSCALL(regs);
 46         if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
 47             tv_nsec != MY_TV_NSEC)
 48                 return 0;
 49 
 50         raw_tp_called = true;
 51         return 0;
 52 }
 53 
 54 SEC("tp_btf/sys_enter")
 55 int BPF_PROG(handle__tp_btf, struct pt_regs *regs, long id)
 56 {
 57         struct __kernel_timespec *ts;
 58         long tv_nsec;
 59 
 60         if (id != __NR_nanosleep)
 61                 return 0;
 62 
 63         ts = (void *)PT_REGS_PARM1_CORE_SYSCALL(regs);
 64         if (bpf_probe_read_user(&tv_nsec, sizeof(ts->tv_nsec), &ts->tv_nsec) ||
 65             tv_nsec != MY_TV_NSEC)
 66                 return 0;
 67 
 68         tp_btf_called = true;
 69         return 0;
 70 }
 71 
 72 SEC("kprobe/hrtimer_start_range_ns")
 73 int BPF_KPROBE(handle__kprobe, struct hrtimer *timer, ktime_t tim, u64 delta_ns,
 74                const enum hrtimer_mode mode)
 75 {
 76         if (tim == MY_TV_NSEC)
 77                 kprobe_called = true;
 78         return 0;
 79 }
 80 
 81 SEC("fentry/hrtimer_start_range_ns")
 82 int BPF_PROG(handle__fentry, struct hrtimer *timer, ktime_t tim, u64 delta_ns,
 83              const enum hrtimer_mode mode)
 84 {
 85         if (tim == MY_TV_NSEC)
 86                 fentry_called = true;
 87         return 0;
 88 }
 89 
 90 char _license[] SEC("license") = "GPL";
 91 

~ [ 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