| ... | @@ -1,12 +1,12 @@ | ... | @@ -1,12 +1,12 @@ |
| 1 | const std = @import("../../../std.zig"); | 1 | const std = @import("../../../std.zig"); |
| 2 | | 2 | |
| 3 | const magic = 0xeb9f; | 3 | pub const magic = 0xeb9f; |
| 4 | const version = 1; | 4 | pub const version = 1; |
| 5 | | 5 | |
| 6 | pub const ext = @import("btf_ext.zig"); | 6 | pub const ext = @import("btf_ext.zig"); |
| 7 | | 7 | |
| 8 | /// All offsets are in bytes relative to the end of this header | 8 | /// All offsets are in bytes relative to the end of this header |
| 9 | pub const Header = packed struct { | 9 | pub const Header = extern struct { |
| 10 | magic: u16, | 10 | magic: u16, |
| 11 | version: u8, | 11 | version: u8, |
| 12 | flags: u8, | 12 | flags: u8, |
| ... | @@ -34,15 +34,15 @@ pub const max_name_offset = 0xffffff; | ... | @@ -34,15 +34,15 @@ pub const max_name_offset = 0xffffff; |
| 34 | /// Max number of struct/union/enum member of func args | 34 | /// Max number of struct/union/enum member of func args |
| 35 | pub const max_vlen = 0xffff; | 35 | pub const max_vlen = 0xffff; |
| 36 | | 36 | |
| 37 | pub const Type = packed struct { | 37 | pub const Type = extern struct { |
| 38 | name_off: u32, | 38 | name_off: u32, |
| 39 | info: packed struct { | 39 | info: packed struct(u32) { |
| 40 | /// number of struct's members | 40 | /// number of struct's members |
| 41 | vlen: u16, | 41 | vlen: u16, |
| 42 | | 42 | |
| 43 | unused_1: u8, | 43 | unused_1: u8, |
| 44 | kind: Kind, | 44 | kind: Kind, |
| 45 | unused_2: u3, | 45 | unused_2: u2, |
| 46 | | 46 | |
| 47 | /// used by Struct, Union, and Fwd | 47 | /// used by Struct, Union, and Fwd |
| 48 | kind_flag: bool, | 48 | kind_flag: bool, |
| ... | @@ -53,31 +53,35 @@ pub const Type = packed struct { | ... | @@ -53,31 +53,35 @@ pub const Type = packed struct { |
| 53 | /// | 53 | /// |
| 54 | /// type is used by Ptr, Typedef, Volatile, Const, Restrict, Func, | 54 | /// type is used by Ptr, Typedef, Volatile, Const, Restrict, Func, |
| 55 | /// FuncProto, and Var. It is a type_id referring to another type | 55 | /// FuncProto, and Var. It is a type_id referring to another type |
| 56 | size_type: union { size: u32, typ: u32 }, | 56 | size_type: extern union { size: u32, typ: u32 }, |
| 57 | }; | 57 | }; |
| 58 | | 58 | |
| 59 | /// For some kinds, Type is immediately followed by extra data | 59 | /// For some kinds, Type is immediately followed by extra data |
| 60 | pub const Kind = enum(u4) { | 60 | pub const Kind = enum(u5) { |
| 61 | unknown, | 61 | unknown, |
| 62 | int, | 62 | int, |
| 63 | ptr, | 63 | ptr, |
| 64 | array, | 64 | array, |
| 65 | structure, | 65 | @"struct", |
| 66 | kind_union, | 66 | @"union", |
| 67 | enumeration, | 67 | @"enum", |
| 68 | fwd, | 68 | fwd, |
| 69 | typedef, | 69 | typedef, |
| 70 | kind_volatile, | 70 | @"volatile", |
| 71 | constant, | 71 | @"const", |
| 72 | restrict, | 72 | restrict, |
| 73 | func, | 73 | func, |
| 74 | funcProto, | 74 | func_proto, |
| 75 | variable, | 75 | @"var", |
| 76 | dataSec, | 76 | datasec, |
| | 77 | float, |
| | 78 | decl_tag, |
| | 79 | type_tag, |
| | 80 | enum64, |
| 77 | }; | 81 | }; |
| 78 | | 82 | |
| 79 | /// Int kind is followed by this struct | 83 | /// int kind is followed by this struct |
| 80 | pub const IntInfo = packed struct { | 84 | pub const IntInfo = packed struct(u32) { |
| 81 | bits: u8, | 85 | bits: u8, |
| 82 | unused: u8, | 86 | unused: u8, |
| 83 | offset: u8, | 87 | offset: u8, |
| ... | @@ -92,36 +96,43 @@ test "IntInfo is 32 bits" { | ... | @@ -92,36 +96,43 @@ test "IntInfo is 32 bits" { |
| 92 | try std.testing.expectEqual(@bitSizeOf(IntInfo), 32); | 96 | try std.testing.expectEqual(@bitSizeOf(IntInfo), 32); |
| 93 | } | 97 | } |
| 94 | | 98 | |
| 95 | /// Enum kind is followed by this struct | 99 | /// enum kind is followed by this struct |
| 96 | pub const Enum = packed struct { | 100 | pub const Enum = extern struct { |
| 97 | name_off: u32, | 101 | name_off: u32, |
| 98 | val: i32, | 102 | val: i32, |
| 99 | }; | 103 | }; |
| 100 | | 104 | |
| 101 | /// Array kind is followd by this struct | 105 | /// enum64 kind is followed by this struct |
| 102 | pub const Array = packed struct { | 106 | pub const Enum64 = extern struct { |
| | 107 | name_off: u32, |
| | 108 | val_lo32: i32, |
| | 109 | val_hi32: i32, |
| | 110 | }; |
| | 111 | |
| | 112 | /// array kind is followd by this struct |
| | 113 | pub const Array = extern struct { |
| 103 | typ: u32, | 114 | typ: u32, |
| 104 | index_type: u32, | 115 | index_type: u32, |
| 105 | nelems: u32, | 116 | nelems: u32, |
| 106 | }; | 117 | }; |
| 107 | | 118 | |
| 108 | /// Struct and Union kinds are followed by multiple Member structs. The exact | 119 | /// struct and union kinds are followed by multiple Member structs. The exact |
| 109 | /// number is stored in vlen | 120 | /// number is stored in vlen |
| 110 | pub const Member = packed struct { | 121 | pub const Member = extern struct { |
| 111 | name_off: u32, | 122 | name_off: u32, |
| 112 | typ: u32, | 123 | typ: u32, |
| 113 | | 124 | |
| 114 | /// if the kind_flag is set, offset contains both member bitfield size and | 125 | /// if the kind_flag is set, offset contains both member bitfield size and |
| 115 | /// bit offset, the bitfield size is set for bitfield members. If the type | 126 | /// bit offset, the bitfield size is set for bitfield members. If the type |
| 116 | /// info kind_flag is not set, the offset contains only bit offset | 127 | /// info kind_flag is not set, the offset contains only bit offset |
| 117 | offset: packed struct { | 128 | offset: packed struct(u32) { |
| 118 | bit: u24, | 129 | bit: u24, |
| 119 | bitfield_size: u8, | 130 | bitfield_size: u8, |
| 120 | }, | 131 | }, |
| 121 | }; | 132 | }; |
| 122 | | 133 | |
| 123 | /// FuncProto is followed by multiple Params, the exact number is stored in vlen | 134 | /// func_proto is followed by multiple Params, the exact number is stored in vlen |
| 124 | pub const Param = packed struct { | 135 | pub const Param = extern struct { |
| 125 | name_off: u32, | 136 | name_off: u32, |
| 126 | typ: u32, | 137 | typ: u32, |
| 127 | }; | 138 | }; |
| ... | @@ -138,16 +149,26 @@ pub const FuncLinkage = enum { | ... | @@ -138,16 +149,26 @@ pub const FuncLinkage = enum { |
| 138 | external, | 149 | external, |
| 139 | }; | 150 | }; |
| 140 | | 151 | |
| 141 | /// Var kind is followd by a single Var struct to describe additional | 152 | /// var kind is followd by a single Var struct to describe additional |
| 142 | /// information related to the variable such as its linkage | 153 | /// information related to the variable such as its linkage |
| 143 | pub const Var = packed struct { | 154 | pub const Var = extern struct { |
| 144 | linkage: u32, | 155 | linkage: u32, |
| 145 | }; | 156 | }; |
| 146 | | 157 | |
| 147 | /// Datasec kind is followed by multible VarSecInfo to describe all Var kind | 158 | /// datasec kind is followed by multible VarSecInfo to describe all Var kind |
| 148 | /// types it contains along with it's in-section offset as well as size. | 159 | /// types it contains along with it's in-section offset as well as size. |
| 149 | pub const VarSecInfo = packed struct { | 160 | pub const VarSecInfo = extern struct { |
| 150 | typ: u32, | 161 | typ: u32, |
| 151 | offset: u32, | 162 | offset: u32, |
| 152 | size: u32, | 163 | size: u32, |
| 153 | }; | 164 | }; |
| | 165 | |
| | 166 | // decl_tag kind is followed by a single DeclTag struct to describe |
| | 167 | // additional information related to the tag applied location. |
| | 168 | // If component_idx == -1, the tag is applied to a struct, union, |
| | 169 | // variable or function. Otherwise, it is applied to a struct/union |
| | 170 | // member or a func argument, and component_idx indicates which member |
| | 171 | // or argument (0 ... vlen-1). |
| | 172 | pub const DeclTag = extern struct { |
| | 173 | component_idx: u32, |
| | 174 | }; |