kprobe.c 529 B

123456789101112131415161718192021222324252627
  1. //go:build ignore
  2. #include "common.h"
  3. char __license[] SEC("license") = "Dual MIT/GPL";
  4. struct bpf_map_def SEC("maps") kprobe_map = {
  5. .type = BPF_MAP_TYPE_ARRAY,
  6. .key_size = sizeof(u32),
  7. .value_size = sizeof(u64),
  8. .max_entries = 1,
  9. };
  10. SEC("kprobe/sys_execve")
  11. int kprobe_execve() {
  12. u32 key = 0;
  13. u64 initval = 1, *valp;
  14. valp = bpf_map_lookup_elem(&kprobe_map, &key);
  15. if (!valp) {
  16. bpf_map_update_elem(&kprobe_map, &key, &initval, BPF_ANY);
  17. return 0;
  18. }
  19. __sync_fetch_and_add(valp, 1);
  20. return 0;
  21. }