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