1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* Copyright (c) 2019 Facebook */ |
3 | |
4 | #include <stdbool.h> |
5 | #include <linux/bpf.h> |
6 | #include <bpf/bpf_helpers.h> |
7 | |
8 | #define __read_mostly SEC(".data.read_mostly") |
9 | |
10 | struct s { |
11 | int a; |
12 | long long b; |
13 | } __attribute__((packed)); |
14 | |
15 | /* .data section */ |
16 | int in1 = -1; |
17 | long long in2 = -1; |
18 | |
19 | /* .bss section */ |
20 | char in3 = '\0'; |
21 | long long in4 __attribute__((aligned(64))) = 0; |
22 | struct s in5 = {}; |
23 | |
24 | /* .rodata section */ |
25 | const volatile struct { |
26 | const int in6; |
27 | } in = {}; |
28 | |
29 | /* .data section */ |
30 | int out1 = -1; |
31 | long long out2 = -1; |
32 | |
33 | /* .bss section */ |
34 | char out3 = 0; |
35 | long long out4 = 0; |
36 | int out6 = 0; |
37 | |
38 | extern bool CONFIG_BPF_SYSCALL __kconfig; |
39 | extern int LINUX_KERNEL_VERSION __kconfig; |
40 | bool bpf_syscall = 0; |
41 | int kern_ver = 0; |
42 | |
43 | struct s out5 = {}; |
44 | |
45 | |
46 | const volatile int in_dynarr_sz SEC(".rodata.dyn" ); |
47 | const volatile int in_dynarr[4] SEC(".rodata.dyn" ) = { -1, -2, -3, -4 }; |
48 | |
49 | int out_dynarr[4] SEC(".data.dyn" ) = { 1, 2, 3, 4 }; |
50 | |
51 | int read_mostly_var __read_mostly; |
52 | int out_mostly_var; |
53 | |
54 | char huge_arr[16 * 1024 * 1024]; |
55 | |
56 | /* non-mmapable custom .data section */ |
57 | |
58 | struct my_value { int x, y, z; }; |
59 | |
60 | __hidden int zero_key SEC(".data.non_mmapable" ); |
61 | static struct my_value zero_value SEC(".data.non_mmapable" ); |
62 | |
63 | struct { |
64 | __uint(type, BPF_MAP_TYPE_ARRAY); |
65 | __type(key, int); |
66 | __type(value, struct my_value); |
67 | __uint(max_entries, 1); |
68 | } my_map SEC(".maps" ); |
69 | |
70 | SEC("raw_tp/sys_enter" ) |
71 | int handler(const void *ctx) |
72 | { |
73 | int i; |
74 | |
75 | out1 = in1; |
76 | out2 = in2; |
77 | out3 = in3; |
78 | out4 = in4; |
79 | out5 = in5; |
80 | out6 = in.in6; |
81 | |
82 | bpf_syscall = CONFIG_BPF_SYSCALL; |
83 | kern_ver = LINUX_KERNEL_VERSION; |
84 | |
85 | for (i = 0; i < in_dynarr_sz; i++) |
86 | out_dynarr[i] = in_dynarr[i]; |
87 | |
88 | out_mostly_var = read_mostly_var; |
89 | |
90 | huge_arr[sizeof(huge_arr) - 1] = 123; |
91 | |
92 | /* make sure zero_key and zero_value are not optimized out */ |
93 | bpf_map_update_elem(&my_map, &zero_key, &zero_value, BPF_ANY); |
94 | |
95 | return 0; |
96 | } |
97 | |
98 | char _license[] SEC("license" ) = "GPL" ; |
99 | |