Debian Codegraph @

testdata/btf_map_init.c

raw symbols SCIP
1 /* This file excercises the ELF loader. It is not a valid BPF program. */
2
3 #include "common.h"
4
5 int __section("socket/tail") tail_1() {
6 return 42;
7 }
8
9 // Tail call map (program array) initialized with program pointers.
10 struct {
11 __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
12 __type(key, uint32_t);
13 __type(value, uint32_t);
14 __uint(max_entries, 2);
15 __array(values, int());
16 } prog_array_init __section(".maps") = {
17 .values =
18 {
19 // Skip index 0 to exercise empty array slots.
20 [1] = &tail_1,
21 },
22 };
23
24 int __section("socket/main") tail_main(void *ctx) {
25 // If prog_array_init is correctly populated, the tail call
26 // will succeed and the program will continue in tail_1 and
27 // not return here.
28 bpf_tail_call(ctx, &prog_array_init, 1);
29
30 return 0;
31 }
32
33 // Inner map with a single possible entry.
34 struct {
35 __uint(type, BPF_MAP_TYPE_ARRAY);
36 __uint(max_entries, 1);
37 __type(key, uint32_t);
38 __type(value, uint32_t);
39 } inner_map __section(".maps");
40
41 // Outer map carrying a reference to the inner map.
42 struct {
43 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
44 __uint(max_entries, 2);
45 __type(key, uint32_t);
46 __type(value, uint32_t);
47 __array(values, typeof(inner_map));
48 } outer_map_init __section(".maps") = {
49 .values =
50 {
51 // Skip index 0 to exercise empty array slots.
52 [1] = &inner_map,
53 },
54 };