]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - tools/testing/selftests/bpf/progs/core_reloc_types.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[mirror_ubuntu-jammy-kernel.git] / tools / testing / selftests / bpf / progs / core_reloc_types.h
1 #include <stdint.h>
2 #include <stdbool.h>
3 /*
4 * KERNEL
5 */
6
7 struct core_reloc_kernel_output {
8 int valid[10];
9 char comm[sizeof("test_progs")];
10 int comm_len;
11 };
12
13 /*
14 * FLAVORS
15 */
16 struct core_reloc_flavors {
17 int a;
18 int b;
19 int c;
20 };
21
22 /* this is not a flavor, as it doesn't have triple underscore */
23 struct core_reloc_flavors__err_wrong_name {
24 int a;
25 int b;
26 int c;
27 };
28
29 /*
30 * NESTING
31 */
32 /* original set up, used to record relocations in BPF program */
33 struct core_reloc_nesting_substruct {
34 int a;
35 };
36
37 union core_reloc_nesting_subunion {
38 int b;
39 };
40
41 struct core_reloc_nesting {
42 union {
43 struct core_reloc_nesting_substruct a;
44 } a;
45 struct {
46 union core_reloc_nesting_subunion b;
47 } b;
48 };
49
50 /* inlined anonymous struct/union instead of named structs in original */
51 struct core_reloc_nesting___anon_embed {
52 int __just_for_padding;
53 union {
54 struct {
55 int a;
56 } a;
57 } a;
58 struct {
59 union {
60 int b;
61 } b;
62 } b;
63 };
64
65 /* different mix of nested structs/unions than in original */
66 struct core_reloc_nesting___struct_union_mixup {
67 int __a;
68 struct {
69 int __a;
70 union {
71 char __a;
72 int a;
73 } a;
74 } a;
75 int __b;
76 union {
77 int __b;
78 union {
79 char __b;
80 int b;
81 } b;
82 } b;
83 };
84
85 /* extra anon structs/unions, but still valid a.a.a and b.b.b accessors */
86 struct core_reloc_nesting___extra_nesting {
87 int __padding;
88 struct {
89 struct {
90 struct {
91 struct {
92 union {
93 int a;
94 } a;
95 };
96 };
97 } a;
98 int __some_more;
99 struct {
100 union {
101 union {
102 union {
103 struct {
104 int b;
105 };
106 } b;
107 };
108 } b;
109 };
110 };
111 };
112
113 /* three flavors of same struct with different structure but same layout for
114 * a.a.a and b.b.b, thus successfully resolved and relocatable */
115 struct core_reloc_nesting___dup_compat_types {
116 char __just_for_padding;
117 /* 3 more bytes of padding */
118 struct {
119 struct {
120 int a; /* offset 4 */
121 } a;
122 } a;
123 long long __more_padding;
124 struct {
125 struct {
126 int b; /* offset 16 */
127 } b;
128 } b;
129 };
130
131 struct core_reloc_nesting___dup_compat_types__2 {
132 int __aligned_padding;
133 struct {
134 int __trickier_noop[0];
135 struct {
136 char __some_more_noops[0];
137 int a; /* offset 4 */
138 } a;
139 } a;
140 int __more_padding;
141 struct {
142 struct {
143 struct {
144 int __critical_padding;
145 int b; /* offset 16 */
146 } b;
147 int __does_not_matter;
148 };
149 } b;
150 int __more_irrelevant_stuff;
151 };
152
153 struct core_reloc_nesting___dup_compat_types__3 {
154 char __correct_padding[4];
155 struct {
156 struct {
157 int a; /* offset 4 */
158 } a;
159 } a;
160 /* 8 byte padding due to next struct's alignment */
161 struct {
162 struct {
163 int b;
164 } b;
165 } b __attribute__((aligned(16)));
166 };
167
168 /* b.b.b field is missing */
169 struct core_reloc_nesting___err_missing_field {
170 struct {
171 struct {
172 int a;
173 } a;
174 } a;
175 struct {
176 struct {
177 int x;
178 } b;
179 } b;
180 };
181
182 /* b.b.b field is an array of integers instead of plain int */
183 struct core_reloc_nesting___err_array_field {
184 struct {
185 struct {
186 int a;
187 } a;
188 } a;
189 struct {
190 struct {
191 int b[1];
192 } b;
193 } b;
194 };
195
196 /* middle b container is missing */
197 struct core_reloc_nesting___err_missing_container {
198 struct {
199 struct {
200 int a;
201 } a;
202 } a;
203 struct {
204 int x;
205 } b;
206 };
207
208 /* middle b container is referenced through pointer instead of being embedded */
209 struct core_reloc_nesting___err_nonstruct_container {
210 struct {
211 struct {
212 int a;
213 } a;
214 } a;
215 struct {
216 struct {
217 int b;
218 } *b;
219 } b;
220 };
221
222 /* middle b container is an array of structs instead of plain struct */
223 struct core_reloc_nesting___err_array_container {
224 struct {
225 struct {
226 int a;
227 } a;
228 } a;
229 struct {
230 struct {
231 int b;
232 } b[1];
233 } b;
234 };
235
236 /* two flavors of same struct with incompatible layout for b.b.b */
237 struct core_reloc_nesting___err_dup_incompat_types__1 {
238 struct {
239 struct {
240 int a; /* offset 0 */
241 } a;
242 } a;
243 struct {
244 struct {
245 int b; /* offset 4 */
246 } b;
247 } b;
248 };
249
250 struct core_reloc_nesting___err_dup_incompat_types__2 {
251 struct {
252 struct {
253 int a; /* offset 0 */
254 } a;
255 } a;
256 int __extra_padding;
257 struct {
258 struct {
259 int b; /* offset 8 (!) */
260 } b;
261 } b;
262 };
263
264 /* two flavors of same struct having one of a.a.a and b.b.b, but not both */
265 struct core_reloc_nesting___err_partial_match_dups__a {
266 struct {
267 struct {
268 int a;
269 } a;
270 } a;
271 };
272
273 struct core_reloc_nesting___err_partial_match_dups__b {
274 struct {
275 struct {
276 int b;
277 } b;
278 } b;
279 };
280
281 struct core_reloc_nesting___err_too_deep {
282 struct {
283 struct {
284 int a;
285 } a;
286 } a;
287 /* 65 levels of nestedness for b.b.b */
288 struct {
289 struct {
290 struct { struct { struct { struct { struct {
291 struct { struct { struct { struct { struct {
292 struct { struct { struct { struct { struct {
293 struct { struct { struct { struct { struct {
294 struct { struct { struct { struct { struct {
295 struct { struct { struct { struct { struct {
296 struct { struct { struct { struct { struct {
297 struct { struct { struct { struct { struct {
298 struct { struct { struct { struct { struct {
299 struct { struct { struct { struct { struct {
300 struct { struct { struct { struct { struct {
301 struct { struct { struct { struct { struct {
302 /* this one is one too much */
303 struct {
304 int b;
305 };
306 }; }; }; }; };
307 }; }; }; }; };
308 }; }; }; }; };
309 }; }; }; }; };
310 }; }; }; }; };
311 }; }; }; }; };
312 }; }; }; }; };
313 }; }; }; }; };
314 }; }; }; }; };
315 }; }; }; }; };
316 }; }; }; }; };
317 }; }; }; }; };
318 } b;
319 } b;
320 };
321
322 /*
323 * ARRAYS
324 */
325 struct core_reloc_arrays_output {
326 int a2;
327 char b123;
328 int c1c;
329 int d00d;
330 };
331
332 struct core_reloc_arrays_substruct {
333 int c;
334 int d;
335 };
336
337 struct core_reloc_arrays {
338 int a[5];
339 char b[2][3][4];
340 struct core_reloc_arrays_substruct c[3];
341 struct core_reloc_arrays_substruct d[1][2];
342 };
343
344 /* bigger array dimensions */
345 struct core_reloc_arrays___diff_arr_dim {
346 int a[7];
347 char b[3][4][5];
348 struct core_reloc_arrays_substruct c[4];
349 struct core_reloc_arrays_substruct d[2][3];
350 };
351
352 /* different size of array's value (struct) */
353 struct core_reloc_arrays___diff_arr_val_sz {
354 int a[5];
355 char b[2][3][4];
356 struct {
357 int __padding1;
358 int c;
359 int __padding2;
360 } c[3];
361 struct {
362 int __padding1;
363 int d;
364 int __padding2;
365 } d[1][2];
366 };
367
368 struct core_reloc_arrays___err_too_small {
369 int a[2]; /* this one is too small */
370 char b[2][3][4];
371 struct core_reloc_arrays_substruct c[3];
372 struct core_reloc_arrays_substruct d[1][2];
373 };
374
375 struct core_reloc_arrays___err_too_shallow {
376 int a[5];
377 char b[2][3]; /* this one lacks one dimension */
378 struct core_reloc_arrays_substruct c[3];
379 struct core_reloc_arrays_substruct d[1][2];
380 };
381
382 struct core_reloc_arrays___err_non_array {
383 int a; /* not an array */
384 char b[2][3][4];
385 struct core_reloc_arrays_substruct c[3];
386 struct core_reloc_arrays_substruct d[1][2];
387 };
388
389 struct core_reloc_arrays___err_wrong_val_type {
390 int a[5];
391 char b[2][3][4];
392 int c[3]; /* value is not a struct */
393 struct core_reloc_arrays_substruct d[1][2];
394 };
395
396 /*
397 * PRIMITIVES
398 */
399 enum core_reloc_primitives_enum {
400 A = 0,
401 B = 1,
402 };
403
404 struct core_reloc_primitives {
405 char a;
406 int b;
407 enum core_reloc_primitives_enum c;
408 void *d;
409 int (*f)(const char *);
410 };
411
412 struct core_reloc_primitives___diff_enum_def {
413 char a;
414 int b;
415 void *d;
416 int (*f)(const char *);
417 enum {
418 X = 100,
419 Y = 200,
420 } c; /* inline enum def with differing set of values */
421 };
422
423 struct core_reloc_primitives___diff_func_proto {
424 void (*f)(int); /* incompatible function prototype */
425 void *d;
426 enum core_reloc_primitives_enum c;
427 int b;
428 char a;
429 };
430
431 struct core_reloc_primitives___diff_ptr_type {
432 const char * const d; /* different pointee type + modifiers */
433 char a;
434 int b;
435 enum core_reloc_primitives_enum c;
436 int (*f)(const char *);
437 };
438
439 struct core_reloc_primitives___err_non_enum {
440 char a[1];
441 int b;
442 int c; /* int instead of enum */
443 void *d;
444 int (*f)(const char *);
445 };
446
447 struct core_reloc_primitives___err_non_int {
448 char a[1];
449 int *b; /* ptr instead of int */
450 enum core_reloc_primitives_enum c;
451 void *d;
452 int (*f)(const char *);
453 };
454
455 struct core_reloc_primitives___err_non_ptr {
456 char a[1];
457 int b;
458 enum core_reloc_primitives_enum c;
459 int d; /* int instead of ptr */
460 int (*f)(const char *);
461 };
462
463 /*
464 * MODS
465 */
466 struct core_reloc_mods_output {
467 int a, b, c, d, e, f, g, h;
468 };
469
470 typedef const int int_t;
471 typedef const char *char_ptr_t;
472 typedef const int arr_t[7];
473
474 struct core_reloc_mods_substruct {
475 int x;
476 int y;
477 };
478
479 typedef struct {
480 int x;
481 int y;
482 } core_reloc_mods_substruct_t;
483
484 struct core_reloc_mods {
485 int a;
486 int_t b;
487 char *c;
488 char_ptr_t d;
489 int e[3];
490 arr_t f;
491 struct core_reloc_mods_substruct g;
492 core_reloc_mods_substruct_t h;
493 };
494
495 /* a/b, c/d, e/f, and g/h pairs are swapped */
496 struct core_reloc_mods___mod_swap {
497 int b;
498 int_t a;
499 char *d;
500 char_ptr_t c;
501 int f[3];
502 arr_t e;
503 struct {
504 int y;
505 int x;
506 } h;
507 core_reloc_mods_substruct_t g;
508 };
509
510 typedef int int1_t;
511 typedef int1_t int2_t;
512 typedef int2_t int3_t;
513
514 typedef int arr1_t[5];
515 typedef arr1_t arr2_t;
516 typedef arr2_t arr3_t;
517 typedef arr3_t arr4_t;
518
519 typedef const char * const volatile fancy_char_ptr_t;
520
521 typedef core_reloc_mods_substruct_t core_reloc_mods_substruct_tt;
522
523 /* we need more typedefs */
524 struct core_reloc_mods___typedefs {
525 core_reloc_mods_substruct_tt g;
526 core_reloc_mods_substruct_tt h;
527 arr4_t f;
528 arr4_t e;
529 fancy_char_ptr_t d;
530 fancy_char_ptr_t c;
531 int3_t b;
532 int3_t a;
533 };
534
535 /*
536 * PTR_AS_ARR
537 */
538 struct core_reloc_ptr_as_arr {
539 int a;
540 };
541
542 struct core_reloc_ptr_as_arr___diff_sz {
543 int :32; /* padding */
544 char __some_more_padding;
545 int a;
546 };
547
548 /*
549 * INTS
550 */
551 struct core_reloc_ints {
552 uint8_t u8_field;
553 int8_t s8_field;
554 uint16_t u16_field;
555 int16_t s16_field;
556 uint32_t u32_field;
557 int32_t s32_field;
558 uint64_t u64_field;
559 int64_t s64_field;
560 };
561
562 /* signed/unsigned types swap */
563 struct core_reloc_ints___reverse_sign {
564 int8_t u8_field;
565 uint8_t s8_field;
566 int16_t u16_field;
567 uint16_t s16_field;
568 int32_t u32_field;
569 uint32_t s32_field;
570 int64_t u64_field;
571 uint64_t s64_field;
572 };
573
574 struct core_reloc_ints___bool {
575 bool u8_field; /* bool instead of uint8 */
576 int8_t s8_field;
577 uint16_t u16_field;
578 int16_t s16_field;
579 uint32_t u32_field;
580 int32_t s32_field;
581 uint64_t u64_field;
582 int64_t s64_field;
583 };
584
585 /*
586 * MISC
587 */
588 struct core_reloc_misc_output {
589 int a, b, c;
590 };
591
592 struct core_reloc_misc___a {
593 int a1;
594 int a2;
595 };
596
597 struct core_reloc_misc___b {
598 int b1;
599 int b2;
600 };
601
602 /* this one extends core_reloc_misc_extensible struct from BPF prog */
603 struct core_reloc_misc_extensible {
604 int a;
605 int b;
606 int c;
607 int d;
608 };
609
610 /*
611 * EXISTENCE
612 */
613 struct core_reloc_existence_output {
614 int a_exists;
615 int a_value;
616 int b_exists;
617 int b_value;
618 int c_exists;
619 int c_value;
620 int arr_exists;
621 int arr_value;
622 int s_exists;
623 int s_value;
624 };
625
626 struct core_reloc_existence {
627 int a;
628 struct {
629 int b;
630 };
631 int c;
632 int arr[1];
633 struct {
634 int x;
635 } s;
636 };
637
638 struct core_reloc_existence___minimal {
639 int a;
640 };
641
642 struct core_reloc_existence___err_wrong_int_sz {
643 short a;
644 };
645
646 struct core_reloc_existence___err_wrong_int_type {
647 int b[1];
648 };
649
650 struct core_reloc_existence___err_wrong_int_kind {
651 struct{ int x; } c;
652 };
653
654 struct core_reloc_existence___err_wrong_arr_kind {
655 int arr;
656 };
657
658 struct core_reloc_existence___err_wrong_arr_value_type {
659 short arr[1];
660 };
661
662 struct core_reloc_existence___err_wrong_struct_type {
663 int s;
664 };
665
666 /*
667 * BITFIELDS
668 */
669 /* bitfield read results, all as plain integers */
670 struct core_reloc_bitfields_output {
671 int64_t ub1;
672 int64_t ub2;
673 int64_t ub7;
674 int64_t sb4;
675 int64_t sb20;
676 int64_t u32;
677 int64_t s32;
678 };
679
680 struct core_reloc_bitfields {
681 /* unsigned bitfields */
682 uint8_t ub1: 1;
683 uint8_t ub2: 2;
684 uint32_t ub7: 7;
685 /* signed bitfields */
686 int8_t sb4: 4;
687 int32_t sb20: 20;
688 /* non-bitfields */
689 uint32_t u32;
690 int32_t s32;
691 };
692
693 /* different bit sizes (both up and down) */
694 struct core_reloc_bitfields___bit_sz_change {
695 /* unsigned bitfields */
696 uint16_t ub1: 3; /* 1 -> 3 */
697 uint32_t ub2: 20; /* 2 -> 20 */
698 uint8_t ub7: 1; /* 7 -> 1 */
699 /* signed bitfields */
700 int8_t sb4: 1; /* 4 -> 1 */
701 int32_t sb20: 30; /* 20 -> 30 */
702 /* non-bitfields */
703 uint16_t u32; /* 32 -> 16 */
704 int64_t s32; /* 32 -> 64 */
705 };
706
707 /* turn bitfield into non-bitfield and vice versa */
708 struct core_reloc_bitfields___bitfield_vs_int {
709 uint64_t ub1; /* 3 -> 64 non-bitfield */
710 uint8_t ub2; /* 20 -> 8 non-bitfield */
711 int64_t ub7; /* 7 -> 64 non-bitfield signed */
712 int64_t sb4; /* 4 -> 64 non-bitfield signed */
713 uint64_t sb20; /* 20 -> 16 non-bitfield unsigned */
714 int32_t u32: 20; /* 32 non-bitfield -> 20 bitfield */
715 uint64_t s32: 60; /* 32 non-bitfield -> 60 bitfield */
716 };
717
718 struct core_reloc_bitfields___just_big_enough {
719 uint64_t ub1: 4;
720 uint64_t ub2: 60; /* packed tightly */
721 uint32_t ub7;
722 uint32_t sb4;
723 uint32_t sb20;
724 uint32_t u32;
725 uint32_t s32;
726 } __attribute__((packed)) ;
727
728 struct core_reloc_bitfields___err_too_big_bitfield {
729 uint64_t ub1: 4;
730 uint64_t ub2: 61; /* packed tightly */
731 uint32_t ub7;
732 uint32_t sb4;
733 uint32_t sb20;
734 uint32_t u32;
735 uint32_t s32;
736 } __attribute__((packed)) ;
737
738 /*
739 * SIZE
740 */
741 struct core_reloc_size_output {
742 int int_sz;
743 int struct_sz;
744 int union_sz;
745 int arr_sz;
746 int arr_elem_sz;
747 int ptr_sz;
748 int enum_sz;
749 };
750
751 struct core_reloc_size {
752 int int_field;
753 struct { int x; } struct_field;
754 union { int x; } union_field;
755 int arr_field[4];
756 void *ptr_field;
757 enum { VALUE = 123 } enum_field;
758 };
759
760 struct core_reloc_size___diff_sz {
761 uint64_t int_field;
762 struct { int x; int y; int z; } struct_field;
763 union { int x; char bla[123]; } union_field;
764 char arr_field[10];
765 void *ptr_field;
766 enum { OTHER_VALUE = 0xFFFFFFFFFFFFFFFF } enum_field;
767 };