Skip to content

Commit

Permalink
Use BTF style map pinning
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Ungureanu <vladu@palantir.com>
  • Loading branch information
ungureanuvladvictor committed Aug 10, 2021
1 parent dd1bec6 commit 911d43e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 62 deletions.
31 changes: 16 additions & 15 deletions examples/kprobepin/bpf/kprobe_pin_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@

char __license[] SEC("license") = "Dual MIT/GPL";

struct bpf_map_def SEC("maps") kprobe_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u64),
.max_entries = 1,
};
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, u32);
__type(value, u64);
__uint(max_entries, 1);
__uint(pinning, LIBBPF_PIN_BY_NAME);
} kprobe_map SEC(".maps");

SEC("kprobe/sys_execve")
int kprobe_execve() {
u32 key = 0;
u64 initval = 1, *valp;
u32 key = 0;
u64 initval = 1, *valp;

valp = bpf_map_lookup_elem(&kprobe_map, &key);
if (!valp) {
bpf_map_update_elem(&kprobe_map, &key, &initval, BPF_ANY);
return 0;
}
__sync_fetch_and_add(valp, 1);
valp = bpf_map_lookup_elem(&kprobe_map, &key);
if (!valp) {
bpf_map_update_elem(&kprobe_map, &key, &initval, BPF_ANY);
return 0;
}
__sync_fetch_and_add(valp, 1);

return 0;
return 0;
}
Loading

0 comments on commit 911d43e

Please sign in to comment.