1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright (c) 2019 Facebook 3 4 #include <linux/bpf.h> 5 #include <stdint.h> 6 #include <bpf/bpf_helpers.h> 7 8 char _license[] SEC("license") = "GPL"; 9 10 struct { 11 __uint(type, BPF_MAP_TYPE_ARRAY); 12 __uint(max_entries, 512 * 4); /* at least 4 pages of data */ 13 __uint(map_flags, BPF_F_MMAPABLE); 14 __type(key, __u32); 15 __type(value, __u64); 16 } data_map SEC(".maps"); 17 18 __u64 in_val = 0; 19 __u64 out_val = 0; 20 21 SEC("raw_tracepoint/sys_enter") 22 int test_mmap(void *ctx) 23 { 24 int zero = 0, one = 1, two = 2, far = 1500; 25 __u64 val, *p; 26 27 out_val = in_val; 28 29 /* data_map[2] = in_val; */ 30 bpf_map_update_elem(&data_map, &two, (const void *)&in_val, 0); 31 32 /* data_map[1] = data_map[0] * 2; */ 33 p = bpf_map_lookup_elem(&data_map, &zero); 34 if (p) { 35 val = (*p) * 2; 36 bpf_map_update_elem(&data_map, &one, &val, 0); 37 } 38 39 /* data_map[far] = in_val * 3; */ 40 val = in_val * 3; 41 bpf_map_update_elem(&data_map, &far, &val, 0); 42 43 return 0; 44 } 45 46