1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Facebook
6 #include <bpf/bpf_helpers.h>
8 char _license
[] SEC("license") = "GPL";
11 __uint(type
, BPF_MAP_TYPE_ARRAY
);
12 __uint(max_entries
, 4096);
13 __uint(map_flags
, BPF_F_MMAPABLE
| BPF_F_RDONLY_PROG
);
16 } rdonly_map
SEC(".maps");
19 __uint(type
, BPF_MAP_TYPE_ARRAY
);
20 __uint(max_entries
, 512 * 4); /* at least 4 pages of data */
21 __uint(map_flags
, BPF_F_MMAPABLE
);
24 } data_map
SEC(".maps");
29 SEC("raw_tracepoint/sys_enter")
30 int test_mmap(void *ctx
)
32 int zero
= 0, one
= 1, two
= 2, far
= 1500;
37 /* data_map[2] = in_val; */
38 bpf_map_update_elem(&data_map
, &two
, (const void *)&in_val
, 0);
40 /* data_map[1] = data_map[0] * 2; */
41 p
= bpf_map_lookup_elem(&data_map
, &zero
);
44 bpf_map_update_elem(&data_map
, &one
, &val
, 0);
47 /* data_map[far] = in_val * 3; */
49 bpf_map_update_elem(&data_map
, &far
, &val
, 0);