tracex6_kern.c 912 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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") counters = {
  6. .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
  7. .key_size = sizeof(int),
  8. .value_size = sizeof(u32),
  9. .max_entries = 64,
  10. };
  11. struct bpf_map_def SEC("maps") values = {
  12. .type = BPF_MAP_TYPE_HASH,
  13. .key_size = sizeof(int),
  14. .value_size = sizeof(u64),
  15. .max_entries = 64,
  16. };
  17. SEC("kprobe/htab_map_get_next_key")
  18. int bpf_prog1(struct pt_regs *ctx)
  19. {
  20. u32 key = bpf_get_smp_processor_id();
  21. u64 count, *val;
  22. s64 error;
  23. count = bpf_perf_event_read(&counters, key);
  24. error = (s64)count;
  25. if (error <= -2 && error >= -22)
  26. return 0;
  27. val = bpf_map_lookup_elem(&values, &key);
  28. if (val)
  29. *val = count;
  30. else
  31. bpf_map_update_elem(&values, &key, &count, BPF_NOEXIST);
  32. return 0;
  33. }
  34. char _license[] SEC("license") = "GPL";
  35. u32 _version SEC("version") = LINUX_VERSION_CODE;