multimap-btf.bpf.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // clang-format off
  2. #include <vmlinux.h>
  3. #include <bpf/bpf_helpers.h>
  4. // clang-format on
  5. struct {
  6. __uint(type, BPF_MAP_TYPE_ARRAY);
  7. __type(key, __u32);
  8. __type(value, __u64);
  9. __uint(max_entries, 2);
  10. } map_1 SEC(".maps");
  11. struct {
  12. __uint(type, BPF_MAP_TYPE_ARRAY);
  13. __type(key, __u32);
  14. __type(value, __u64);
  15. __uint(max_entries, 2);
  16. } map_2 SEC(".maps");
  17. struct {
  18. __uint(type, BPF_MAP_TYPE_ARRAY);
  19. __type(key, __u32);
  20. __type(value, __u64);
  21. __uint(max_entries, 2);
  22. __uint(pinning, LIBBPF_PIN_BY_NAME);
  23. } map_pin_by_name SEC(".maps");
  24. SEC("uprobe")
  25. int bpf_prog(void *ctx) {
  26. __u32 key = 0;
  27. __u64 twenty_four = 24;
  28. __u64 forty_two = 42;
  29. __u64 forty_four = 44;
  30. bpf_map_update_elem(&map_1, &key, &twenty_four, BPF_ANY);
  31. bpf_map_update_elem(&map_2, &key, &forty_two, BPF_ANY);
  32. bpf_map_update_elem(&map_pin_by_name, &key, &forty_four, BPF_ANY);
  33. return 0;
  34. }
  35. SEC("uprobe")
  36. int bpf_prog1(void *ctx) {
  37. __u32 key = 1;
  38. __u64 twenty_four = 35;
  39. __u64 forty_two = 53;
  40. __u64 forty_four = 55;
  41. bpf_map_update_elem(&map_1, &key, &twenty_four, BPF_ANY);
  42. bpf_map_update_elem(&map_2, &key, &forty_two, BPF_ANY);
  43. bpf_map_update_elem(&map_pin_by_name, &key, &forty_four, BPF_ANY);
  44. return 0;
  45. }
  46. char _license[] SEC("license") = "GPL";