github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/tools/syz-declextract/testdata/types.c (about) 1 // Copyright 2024 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 #include "include/syscall.h" 5 #include "include/types.h" 6 7 typedef struct { float f; } anon_t; 8 struct empty_struct {}; 9 typedef int fd_t; 10 typedef struct forward forward_t; 11 12 struct anon_struct { 13 // Various tricky anon cases. 14 struct { int x; } a; 15 struct {} b; 16 struct { int y; }; 17 union { int q; long w; }; 18 anon_t foo; 19 forward_t* forward; 20 struct { int a; int b; } array[4]; 21 struct { int a; int b; } *ptr; 22 struct { int a; int b; } *ptr_array[4]; 23 }; 24 25 enum bitfield_enum { a, b, c }; 26 27 struct bitfields { 28 int a : 1; 29 int : 2; 30 int b : 3; 31 long d : 2; 32 long pad : 3; 33 enum bitfield_enum e : 10; 34 int l : 10; 35 int* p __attribute__((counted_by(l))); 36 } __attribute__((aligned(32))); 37 38 struct packed_t { 39 char x; 40 int y; 41 } __attribute__((packed, aligned(32))); 42 43 struct various { 44 struct various* recursive; 45 struct recursive* next; 46 struct packed_t packed; 47 }; 48 49 struct recursive { 50 struct various various; 51 }; 52 53 SYSCALL_DEFINE1(types_syscall, struct anon_struct* p, struct empty_struct* y, 54 struct bitfields* b, int pid, fd_t f, struct various __user* v, 55 int __user* pi, u32 __user* pu) { 56 return 0; 57 } 58 59 enum enum_foo { 60 enum_foo_a, 61 enum_foo_b, 62 }; 63 64 typedef const enum { 65 enum_bar_a, 66 enum_bar_b, 67 } enum_bar; 68 69 SYSCALL_DEFINE1(types_syscall2, const enum enum_foo foo, const enum_bar bar) { 70 return 0; 71 } 72 73 void anon_flow(int x) { 74 struct anon_struct s; 75 s.a.x = x; 76 s.y = x; 77 s.w = x; 78 s.foo.f = x; 79 s.array[1].a = x; 80 s.ptr->a = x; 81 s.ptr_array[1]->b = x; 82 } 83 84 struct aligned_empty_struct {} __attribute__((aligned(8))); 85 struct large_struct { long foo[10]; }; 86 87 struct align1 { 88 char f1; 89 long aligner[0]; 90 char f2; 91 }; 92 93 struct align2 { 94 char f1; 95 struct empty_struct aligner; 96 char f2; 97 }; 98 99 struct align3 { 100 char f1; 101 struct aligned_empty_struct aligner; 102 char f2; 103 }; 104 105 struct align4 { 106 char f1; 107 struct large_struct aligner[0]; 108 char f2; 109 }; 110 111 SYSCALL_DEFINE1(align_syscall, struct align1* a1, struct align2* a2, struct align3* a3, struct align4* a4) { 112 return 0; 113 } 114