linux/tools/testing/selftests/bpf/progs/test_skeleton.c
Andrii Nakryiko 256eab48e7 selftests/bpf: Stop using static variables for passing data to/from user-space
In preparation of skipping emitting static variables in BPF skeletons, switch
all current selftests uses of static variables to pass data between BPF and
user-space to use global variables.

All non-read-only `static volatile` variables become just plain global
variables by dropping `static volatile` part.

Read-only `static volatile const` variables, though, still require `volatile`
modifier, otherwise compiler will ignore whatever values are set from
user-space.

Few static linker tests are using name-conflicting static variables to
validate that static linker still properly handles static variables and
doesn't trip up on name conflicts.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210507054119.270888-4-andrii@kernel.org
2021-05-11 15:07:17 -07:00

60 lines
973 B
C

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2019 Facebook */
#include <stdbool.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
struct s {
int a;
long long b;
} __attribute__((packed));
/* .data section */
int in1 = -1;
long long in2 = -1;
/* .bss section */
char in3 = '\0';
long long in4 __attribute__((aligned(64))) = 0;
struct s in5 = {};
/* .rodata section */
const volatile struct {
const int in6;
} in = {};
/* .data section */
int out1 = -1;
long long out2 = -1;
/* .bss section */
char out3 = 0;
long long out4 = 0;
int out6 = 0;
extern bool CONFIG_BPF_SYSCALL __kconfig;
extern int LINUX_KERNEL_VERSION __kconfig;
bool bpf_syscall = 0;
int kern_ver = 0;
struct s out5 = {};
SEC("raw_tp/sys_enter")
int handler(const void *ctx)
{
out1 = in1;
out2 = in2;
out3 = in3;
out4 = in4;
out5 = in5;
out6 = in.in6;
bpf_syscall = CONFIG_BPF_SYSCALL;
kern_ver = LINUX_KERNEL_VERSION;
return 0;
}
char _license[] SEC("license") = "GPL";