1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 Facebook */
6 #include <bpf/bpf_helpers.h>
8 #define __read_mostly SEC(".data.read_mostly")
13 } __attribute__((packed));
21 long long in4 __attribute__((aligned(64))) = 0;
25 const volatile struct {
38 extern bool CONFIG_BPF_SYSCALL __kconfig;
39 extern int LINUX_KERNEL_VERSION __kconfig;
46 const volatile int in_dynarr_sz SEC(".rodata.dyn");
47 const volatile int in_dynarr[4] SEC(".rodata.dyn") = { -1, -2, -3, -4 };
49 int out_dynarr[4] SEC(".data.dyn") = { 1, 2, 3, 4 };
51 int read_mostly_var __read_mostly;
54 char huge_arr[16 * 1024 * 1024];
56 /* non-mmapable custom .data section */
58 struct my_value { int x, y, z; };
60 __hidden int zero_key SEC(".data.non_mmapable");
61 static struct my_value zero_value SEC(".data.non_mmapable");
64 __uint(type, BPF_MAP_TYPE_ARRAY);
66 __type(value, struct my_value);
67 __uint(max_entries, 1);
68 } my_map SEC(".maps");
70 SEC("raw_tp/sys_enter")
71 int handler(const void *ctx)
82 bpf_syscall = CONFIG_BPF_SYSCALL;
83 kern_ver = LINUX_KERNEL_VERSION;
85 for (i = 0; i < in_dynarr_sz; i++)
86 out_dynarr[i] = in_dynarr[i];
88 out_mostly_var = read_mostly_var;
90 huge_arr[sizeof(huge_arr) - 1] = 123;
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);
98 char _license[] SEC("license") = "GPL";