github.com/cilium/ebpf@v0.10.0/testdata/btf_map_init.c (about) 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 7 int __section("socket/tail") tail_1() { 8 return 42; 9 } 10 11 // Tail call map (program array) initialized with program pointers. 12 struct { 13 __uint(type, BPF_MAP_TYPE_PROG_ARRAY); 14 __type(key, uint32_t); 15 __type(value, uint32_t); 16 __uint(max_entries, 2); 17 __array(values, int()); 18 } prog_array_init __section(".maps") = { 19 .values = 20 { 21 // Skip index 0 to exercise empty array slots. 22 [1] = &tail_1, 23 }, 24 }; 25 26 int __section("socket/main") tail_main(void *ctx) { 27 // If prog_array_init is correctly populated, the tail call 28 // will succeed and the program will continue in tail_1 and 29 // not return here. 30 tail_call(ctx, &prog_array_init, 1); 31 32 return 0; 33 } 34 35 // Inner map with a single possible entry. 36 struct { 37 __uint(type, BPF_MAP_TYPE_ARRAY); 38 __uint(max_entries, 1); 39 __type(key, uint32_t); 40 __type(value, uint32_t); 41 } inner_map __section(".maps"); 42 43 // Outer map carrying a reference to the inner map. 44 struct { 45 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS); 46 __uint(max_entries, 2); 47 __type(key, uint32_t); 48 __type(value, uint32_t); 49 __array(values, typeof(inner_map)); 50 } outer_map_init __section(".maps") = { 51 .values = 52 { 53 // Skip index 0 to exercise empty array slots. 54 [1] = &inner_map, 55 }, 56 }; 57 58 #else 59 #error This file has to be compiled with clang >= 9 60 #endif