tracex6_kern.c 611 B

12345678910111213141516171819202122232425262728
  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 = 32,
  10. };
  11. SEC("kprobe/sys_write")
  12. int bpf_prog1(struct pt_regs *ctx)
  13. {
  14. u64 count;
  15. u32 key = bpf_get_smp_processor_id();
  16. char fmt[] = "CPU-%d %llu\n";
  17. count = bpf_perf_event_read(&my_map, key);
  18. bpf_trace_printk(fmt, sizeof(fmt), key, count);
  19. return 0;
  20. }
  21. char _license[] SEC("license") = "GPL";
  22. u32 _version SEC("version") = LINUX_VERSION_CODE;