WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / test_mmap.c
blob4eb42cff5fe966e8405770672daa6aaaf82457f4
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Facebook
4 #include <linux/bpf.h>
5 #include <stdint.h>
6 #include <bpf/bpf_helpers.h>
8 char _license[] SEC("license") = "GPL";
10 struct {
11 __uint(type, BPF_MAP_TYPE_ARRAY);
12 __uint(max_entries, 4096);
13 __uint(map_flags, BPF_F_MMAPABLE | BPF_F_RDONLY_PROG);
14 __type(key, __u32);
15 __type(value, char);
16 } rdonly_map SEC(".maps");
18 struct {
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);
22 __type(key, __u32);
23 __type(value, __u64);
24 } data_map SEC(".maps");
26 __u64 in_val = 0;
27 __u64 out_val = 0;
29 SEC("raw_tracepoint/sys_enter")
30 int test_mmap(void *ctx)
32 int zero = 0, one = 1, two = 2, far = 1500;
33 __u64 val, *p;
35 out_val = in_val;
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);
42 if (p) {
43 val = (*p) * 2;
44 bpf_map_update_elem(&data_map, &one, &val, 0);
47 /* data_map[far] = in_val * 3; */
48 val = in_val * 3;
49 bpf_map_update_elem(&data_map, &far, &val, 0);
51 return 0;