xref: /linux/tools/testing/selftests/bpf/progs/for_each_map_elem_write_key.c (revision 58f6259b7a08f8d47d4629609703d358b042f0fd)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <vmlinux.h>
3 #include <bpf/bpf_helpers.h>
4 
5 struct {
6 	__uint(type, BPF_MAP_TYPE_ARRAY);
7 	__uint(max_entries, 1);
8 	__type(key, __u32);
9 	__type(value, __u64);
10 } array_map SEC(".maps");
11 
12 static __u64
13 check_array_elem(struct bpf_map *map, __u32 *key, __u64 *val,
14 		 void *data)
15 {
16 	bpf_get_current_comm(key, sizeof(*key));
17 	return 0;
18 }
19 
20 SEC("raw_tp/sys_enter")
21 int test_map_key_write(const void *ctx)
22 {
23 	bpf_for_each_map_elem(&array_map, check_array_elem, NULL, 0);
24 	return 0;
25 }
26 
27 char _license[] SEC("license") = "GPL";
28