Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2019 Facebook */
0003 
0004 #include <stdbool.h>
0005 #include <linux/bpf.h>
0006 #include <bpf/bpf_helpers.h>
0007 
0008 #define __read_mostly SEC(".data.read_mostly")
0009 
0010 struct s {
0011     int a;
0012     long long b;
0013 } __attribute__((packed));
0014 
0015 /* .data section */
0016 int in1 = -1;
0017 long long in2 = -1;
0018 
0019 /* .bss section */
0020 char in3 = '\0';
0021 long long in4 __attribute__((aligned(64))) = 0;
0022 struct s in5 = {};
0023 
0024 /* .rodata section */
0025 const volatile struct {
0026     const int in6;
0027 } in = {};
0028 
0029 /* .data section */
0030 int out1 = -1;
0031 long long out2 = -1;
0032 
0033 /* .bss section */
0034 char out3 = 0;
0035 long long out4 = 0;
0036 int out6 = 0;
0037 
0038 extern bool CONFIG_BPF_SYSCALL __kconfig;
0039 extern int LINUX_KERNEL_VERSION __kconfig;
0040 bool bpf_syscall = 0;
0041 int kern_ver = 0;
0042 
0043 struct s out5 = {};
0044 
0045 
0046 const volatile int in_dynarr_sz SEC(".rodata.dyn");
0047 const volatile int in_dynarr[4] SEC(".rodata.dyn") = { -1, -2, -3, -4 };
0048 
0049 int out_dynarr[4] SEC(".data.dyn") = { 1, 2, 3, 4 };
0050 
0051 int read_mostly_var __read_mostly;
0052 int out_mostly_var;
0053 
0054 char huge_arr[16 * 1024 * 1024];
0055 
0056 SEC("raw_tp/sys_enter")
0057 int handler(const void *ctx)
0058 {
0059     int i;
0060 
0061     out1 = in1;
0062     out2 = in2;
0063     out3 = in3;
0064     out4 = in4;
0065     out5 = in5;
0066     out6 = in.in6;
0067 
0068     bpf_syscall = CONFIG_BPF_SYSCALL;
0069     kern_ver = LINUX_KERNEL_VERSION;
0070 
0071     for (i = 0; i < in_dynarr_sz; i++)
0072         out_dynarr[i] = in_dynarr[i];
0073 
0074     out_mostly_var = read_mostly_var;
0075 
0076     huge_arr[sizeof(huge_arr) - 1] = 123;
0077 
0078     return 0;
0079 }
0080 
0081 char _license[] SEC("license") = "GPL";