xref: /openbmc/linux/tools/testing/selftests/bpf/progs/test_subskeleton_lib.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1  // SPDX-License-Identifier: GPL-2.0
2  /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3  
4  #include <stdbool.h>
5  #include <linux/bpf.h>
6  #include <bpf/bpf_helpers.h>
7  
8  /* volatile to force a read */
9  const volatile int var1;
10  volatile int var2 = 1;
11  struct {
12  	int var3_1;
13  	__s64 var3_2;
14  } var3;
15  int libout1;
16  
17  extern volatile bool CONFIG_BPF_SYSCALL __kconfig;
18  
19  int var4[4];
20  
21  __weak int var5 SEC(".data");
22  
23  /* Fully contained within library extern-and-definition */
24  extern int var6;
25  
26  int var7 SEC(".data.custom");
27  
28  int (*fn_ptr)(void);
29  
30  struct {
31  	__uint(type, BPF_MAP_TYPE_HASH);
32  	__type(key, __u32);
33  	__type(value, __u32);
34  	__uint(max_entries, 16);
35  } map1 SEC(".maps");
36  
37  extern struct {
38  	__uint(type, BPF_MAP_TYPE_HASH);
39  	__type(key, __u32);
40  	__type(value, __u32);
41  	__uint(max_entries, 16);
42  } map2 SEC(".maps");
43  
lib_routine(void)44  int lib_routine(void)
45  {
46  	__u32 key = 1, value = 2;
47  
48  	(void) CONFIG_BPF_SYSCALL;
49  	bpf_map_update_elem(&map2, &key, &value, BPF_ANY);
50  
51  	libout1 = var1 + var2 + var3.var3_1 + var3.var3_2 + var5 + var6;
52  	return libout1;
53  }
54  
55  SEC("perf_event")
lib_perf_handler(struct pt_regs * ctx)56  int lib_perf_handler(struct pt_regs *ctx)
57  {
58  	return 0;
59  }
60  
61  char LICENSE[] SEC("license") = "GPL";
62