trace_output_kern.c 609 B

12345678910111213141516171819202122232425262728293031
  1. #include <linux/ptrace.h>
  2. #include <linux/version.h>
  3. #include <uapi/linux/bpf.h>
  4. #include "bpf_helpers.h"
  5. struct bpf_map_def SEC("maps") my_map = {
  6. .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
  7. .key_size = sizeof(int),
  8. .value_size = sizeof(u32),
  9. .max_entries = 2,
  10. };
  11. SEC("kprobe/sys_write")
  12. int bpf_prog1(struct pt_regs *ctx)
  13. {
  14. struct S {
  15. u64 pid;
  16. u64 cookie;
  17. } data;
  18. data.pid = bpf_get_current_pid_tgid();
  19. data.cookie = 0x12345678;
  20. bpf_perf_event_output(ctx, &my_map, 0, &data, sizeof(data));
  21. return 0;
  22. }
  23. char _license[] SEC("license") = "GPL";
  24. u32 _version SEC("version") = LINUX_VERSION_CODE;