Alexei Starovoitov | 3911169 | 2015-10-20 20:02:35 -0700 | [diff] [blame] | 1 | #include <linux/ptrace.h> |
| 2 | #include <linux/version.h> |
| 3 | #include <uapi/linux/bpf.h> |
Toke Høiland-Jørgensen | 7cf245a | 2020-01-20 14:06:49 +0100 | [diff] [blame] | 4 | #include <bpf/bpf_helpers.h> |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 5 | #include "trace_common.h" |
Alexei Starovoitov | 3911169 | 2015-10-20 20:02:35 -0700 | [diff] [blame] | 6 | |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 7 | struct { |
| 8 | __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); |
| 9 | __uint(key_size, sizeof(int)); |
| 10 | __uint(value_size, sizeof(u32)); |
| 11 | __uint(max_entries, 2); |
| 12 | } my_map SEC(".maps"); |
Alexei Starovoitov | 3911169 | 2015-10-20 20:02:35 -0700 | [diff] [blame] | 13 | |
Daniel T. Lee | 3677d0a | 2020-08-23 17:53:33 +0900 | [diff] [blame] | 14 | SEC("kprobe/" SYSCALL(sys_write)) |
Alexei Starovoitov | 3911169 | 2015-10-20 20:02:35 -0700 | [diff] [blame] | 15 | int bpf_prog1(struct pt_regs *ctx) |
| 16 | { |
| 17 | struct S { |
| 18 | u64 pid; |
| 19 | u64 cookie; |
| 20 | } data; |
| 21 | |
Alexei Starovoitov | 3911169 | 2015-10-20 20:02:35 -0700 | [diff] [blame] | 22 | data.pid = bpf_get_current_pid_tgid(); |
| 23 | data.cookie = 0x12345678; |
| 24 | |
| 25 | bpf_perf_event_output(ctx, &my_map, 0, &data, sizeof(data)); |
| 26 | |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | char _license[] SEC("license") = "GPL"; |
| 31 | u32 _version SEC("version") = LINUX_VERSION_CODE; |