0001
0002
0003
0004 #include <linux/ptrace.h>
0005 #include <linux/bpf.h>
0006 #include <bpf/bpf_helpers.h>
0007 #include <bpf/bpf_tracing.h>
0008
0009 struct {
0010 __uint(type, BPF_MAP_TYPE_ARRAY);
0011 __type(key, int);
0012 __type(value, int);
0013 __uint(max_entries, 1);
0014 } my_pid_map SEC(".maps");
0015
0016 struct {
0017 __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
0018 __type(key, int);
0019 __type(value, int);
0020 } perf_buf_map SEC(".maps");
0021
0022 SEC("tp/raw_syscalls/sys_enter")
0023 int handle_sys_enter(void *ctx)
0024 {
0025 int zero = 0, *my_pid, cur_pid;
0026 int cpu = bpf_get_smp_processor_id();
0027
0028 my_pid = bpf_map_lookup_elem(&my_pid_map, &zero);
0029 if (!my_pid)
0030 return 1;
0031
0032 cur_pid = bpf_get_current_pid_tgid() >> 32;
0033 if (cur_pid != *my_pid)
0034 return 1;
0035
0036 bpf_perf_event_output(ctx, &perf_buf_map, BPF_F_CURRENT_CPU,
0037 &cpu, sizeof(cpu));
0038 return 1;
0039 }
0040
0041 char _license[] SEC("license") = "GPL";