Commit | Line | Data |
---|---|---|
67337c4a MD |
1 | // SPDX-License-Identifier: MIT |
2 | /* | |
3 | * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | */ | |
5 | ||
6 | #ifndef _SIDE_TRACE_H | |
7 | #define _SIDE_TRACE_H | |
8 | ||
9 | #include <stdint.h> | |
10 | #include <inttypes.h> | |
11 | #include <stdlib.h> | |
12 | #include <stdio.h> | |
13 | #include <math.h> | |
25ea4c79 | 14 | #include <stdbool.h> |
67337c4a MD |
15 | #include <side/macros.h> |
16 | #include <side/endian.h> | |
17 | ||
18 | /* | |
551d8244 | 19 | * SIDE stands for "Software Instrumentation Dynamically Enabled" |
67337c4a | 20 | * |
2e197497 | 21 | * This is an instrumentation ABI for Linux user-space, which exposes an |
67337c4a MD |
22 | * instrumentation type system and facilities allowing a kernel or |
23 | * user-space tracer to consume user-space instrumentation. | |
24 | * | |
2e197497 | 25 | * This instrumentation ABI exposes 3 type systems: |
67337c4a MD |
26 | * |
27 | * * Stack-copy type system: This is the core type system which can | |
28 | * represent all supported types and into which all other type systems | |
29 | * can be nested. This type system requires that every type is | |
30 | * statically or dynamically declared and then registered, thus giving | |
31 | * tracers a complete description of the events and their associated | |
32 | * fields before the associated instrumentation is invoked. The | |
33 | * application needs to copy each argument (side_arg_...()) onto the | |
34 | * stack when calling the instrumentation. | |
35 | * | |
36 | * This is the most expressive of the 3 type systems, althrough not the | |
37 | * fastest due to the extra copy of the arguments. | |
38 | * | |
39 | * * Data-gathering type system: This type system requires every type to | |
40 | * be statically or dynamically declared and registered, but does not | |
41 | * require the application to copy its arguments onto the stack. | |
42 | * Instead, the type description contains all the required information | |
43 | * to fetch the data from the application memory. The only argument | |
44 | * required from the instrumentation is the base pointer from which | |
45 | * the data should be fetched. | |
46 | * | |
47 | * This type system can be used as an event field, or nested within | |
48 | * the stack-copy type system. Nesting of gather-vla within | |
49 | * gather-array and gather-vla types is not allowed. | |
50 | * | |
51 | * This type system is has the least overhead of the 3 type systems. | |
52 | * | |
53 | * * Dynamic type system: This type system receives both type | |
54 | * description and actual data onto the stack at runtime. It has more | |
55 | * overhead that the 2 other type systems, but does not require a | |
56 | * prior registration of event field description. This makes it useful | |
57 | * for seldom used types which are not performance critical, but for | |
58 | * which registering each individual events would needlessly grow the | |
59 | * number of events to declare and register. | |
60 | * | |
61 | * Another use-case for this type system is for use by dynamically | |
62 | * typed language runtimes, where the field type is only known when | |
63 | * the instrumentation is called. | |
64 | * | |
65 | * Those dynamic types can be either used as arguments to a variadic | |
66 | * field list, or as on-stack instrumentation argument for a static | |
67 | * type SIDE_TYPE_DYNAMIC place holder in the stack-copy type system. | |
2e197497 MD |
68 | * |
69 | * The extensibility scheme for the SIDE ABI is as follows: | |
70 | * | |
71 | * * Existing field types are never changed nor extended. Field types | |
72 | * can be added to the ABI by reserving a label within | |
73 | * enum side_type_label. | |
74 | * * Existing attribute types are never changed nor extended. Attribute | |
75 | * types can be added to the ABI by reserving a label within | |
76 | * enum side_attr_type. | |
77 | * * Each union part of the ABI has an explicit side defined by a | |
78 | * side_padding() member. Each structure and union have a static | |
79 | * assert validating its size. | |
80 | * | |
81 | * Handling of unknown types by the tracers: | |
82 | * | |
83 | * * A tracer may choose to support only a subset of the types supported | |
84 | * by libside. When encountering an unknown or unsupported type, the | |
85 | * tracer has the option to either disallow the entire event or skip | |
86 | * over the unknown type, both at event registration and when | |
87 | * receiving the side_call arguments. | |
88 | * | |
89 | * TODO: extend event description with new fields ? | |
67337c4a MD |
90 | */ |
91 | ||
92 | //TODO: as those structures will be ABI, we need to either consider them | |
93 | //fixed forever, or think of a scheme that would allow their binary | |
94 | //representation to be extended if need be. | |
95 | ||
96 | struct side_arg; | |
97 | struct side_arg_vec; | |
09515e04 | 98 | union side_arg_dynamic; |
67337c4a MD |
99 | struct side_arg_dynamic_field; |
100 | struct side_arg_dynamic_vla; | |
101 | struct side_type; | |
102 | struct side_event_field; | |
103 | struct side_tracer_visitor_ctx; | |
104 | struct side_tracer_dynamic_struct_visitor_ctx; | |
105 | struct side_event_description; | |
106 | struct side_arg_dynamic_struct; | |
107 | struct side_events_register_handle; | |
5530345d | 108 | struct side_arg_variant; |
0d747f98 | 109 | struct side_event_state; |
2e197497 | 110 | struct side_callback; |
67337c4a MD |
111 | |
112 | enum side_type_label { | |
113 | /* Stack-copy basic types */ | |
114 | SIDE_TYPE_NULL, | |
115 | SIDE_TYPE_BOOL, | |
116 | SIDE_TYPE_U8, | |
117 | SIDE_TYPE_U16, | |
118 | SIDE_TYPE_U32, | |
119 | SIDE_TYPE_U64, | |
120 | SIDE_TYPE_S8, | |
121 | SIDE_TYPE_S16, | |
122 | SIDE_TYPE_S32, | |
123 | SIDE_TYPE_S64, | |
124 | SIDE_TYPE_BYTE, | |
125 | SIDE_TYPE_POINTER, | |
126 | SIDE_TYPE_FLOAT_BINARY16, | |
127 | SIDE_TYPE_FLOAT_BINARY32, | |
128 | SIDE_TYPE_FLOAT_BINARY64, | |
129 | SIDE_TYPE_FLOAT_BINARY128, | |
130 | SIDE_TYPE_STRING_UTF8, | |
131 | SIDE_TYPE_STRING_UTF16, | |
132 | SIDE_TYPE_STRING_UTF32, | |
133 | ||
134 | /* Stack-copy compound types */ | |
135 | SIDE_TYPE_STRUCT, | |
5530345d | 136 | SIDE_TYPE_VARIANT, |
67337c4a MD |
137 | SIDE_TYPE_ARRAY, |
138 | SIDE_TYPE_VLA, | |
139 | SIDE_TYPE_VLA_VISITOR, | |
140 | ||
141 | /* Stack-copy enumeration types */ | |
142 | SIDE_TYPE_ENUM, | |
143 | SIDE_TYPE_ENUM_BITMAP, | |
144 | ||
145 | /* Stack-copy place holder for dynamic types */ | |
146 | SIDE_TYPE_DYNAMIC, | |
147 | ||
148 | /* Gather basic types */ | |
149 | SIDE_TYPE_GATHER_BOOL, | |
150 | SIDE_TYPE_GATHER_INTEGER, | |
151 | SIDE_TYPE_GATHER_BYTE, | |
152 | SIDE_TYPE_GATHER_POINTER, | |
153 | SIDE_TYPE_GATHER_FLOAT, | |
154 | SIDE_TYPE_GATHER_STRING, | |
155 | ||
156 | /* Gather compound types */ | |
157 | SIDE_TYPE_GATHER_STRUCT, | |
158 | SIDE_TYPE_GATHER_ARRAY, | |
159 | SIDE_TYPE_GATHER_VLA, | |
160 | ||
161 | /* Gather enumeration types */ | |
162 | SIDE_TYPE_GATHER_ENUM, | |
163 | ||
164 | /* Dynamic basic types */ | |
165 | SIDE_TYPE_DYNAMIC_NULL, | |
166 | SIDE_TYPE_DYNAMIC_BOOL, | |
167 | SIDE_TYPE_DYNAMIC_INTEGER, | |
168 | SIDE_TYPE_DYNAMIC_BYTE, | |
169 | SIDE_TYPE_DYNAMIC_POINTER, | |
170 | SIDE_TYPE_DYNAMIC_FLOAT, | |
171 | SIDE_TYPE_DYNAMIC_STRING, | |
172 | ||
173 | /* Dynamic compound types */ | |
174 | SIDE_TYPE_DYNAMIC_STRUCT, | |
175 | SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, | |
176 | SIDE_TYPE_DYNAMIC_VLA, | |
177 | SIDE_TYPE_DYNAMIC_VLA_VISITOR, | |
178 | }; | |
179 | ||
180 | enum side_attr_type { | |
181 | SIDE_ATTR_TYPE_NULL, | |
182 | SIDE_ATTR_TYPE_BOOL, | |
183 | SIDE_ATTR_TYPE_U8, | |
184 | SIDE_ATTR_TYPE_U16, | |
185 | SIDE_ATTR_TYPE_U32, | |
186 | SIDE_ATTR_TYPE_U64, | |
187 | SIDE_ATTR_TYPE_S8, | |
188 | SIDE_ATTR_TYPE_S16, | |
189 | SIDE_ATTR_TYPE_S32, | |
190 | SIDE_ATTR_TYPE_S64, | |
191 | SIDE_ATTR_TYPE_FLOAT_BINARY16, | |
192 | SIDE_ATTR_TYPE_FLOAT_BINARY32, | |
193 | SIDE_ATTR_TYPE_FLOAT_BINARY64, | |
194 | SIDE_ATTR_TYPE_FLOAT_BINARY128, | |
195 | SIDE_ATTR_TYPE_STRING, | |
196 | }; | |
197 | ||
198 | enum side_loglevel { | |
199 | SIDE_LOGLEVEL_EMERG = 0, | |
200 | SIDE_LOGLEVEL_ALERT = 1, | |
201 | SIDE_LOGLEVEL_CRIT = 2, | |
202 | SIDE_LOGLEVEL_ERR = 3, | |
203 | SIDE_LOGLEVEL_WARNING = 4, | |
204 | SIDE_LOGLEVEL_NOTICE = 5, | |
205 | SIDE_LOGLEVEL_INFO = 6, | |
206 | SIDE_LOGLEVEL_DEBUG = 7, | |
207 | }; | |
208 | ||
209 | enum side_visitor_status { | |
210 | SIDE_VISITOR_STATUS_OK = 0, | |
211 | SIDE_VISITOR_STATUS_ERROR = -1, | |
212 | }; | |
213 | ||
214 | enum side_error { | |
215 | SIDE_ERROR_OK = 0, | |
216 | SIDE_ERROR_INVAL = 1, | |
217 | SIDE_ERROR_EXIST = 2, | |
218 | SIDE_ERROR_NOMEM = 3, | |
219 | SIDE_ERROR_NOENT = 4, | |
220 | SIDE_ERROR_EXITING = 5, | |
221 | }; | |
222 | ||
223 | enum side_type_label_byte_order { | |
224 | SIDE_TYPE_BYTE_ORDER_LE = 0, | |
225 | SIDE_TYPE_BYTE_ORDER_BE = 1, | |
226 | }; | |
227 | ||
228 | #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN) | |
229 | # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE | |
230 | #else | |
231 | # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE | |
232 | #endif | |
233 | ||
234 | #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN) | |
235 | # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE | |
236 | #else | |
237 | # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE | |
238 | #endif | |
239 | ||
240 | enum side_type_gather_access_mode { | |
241 | SIDE_TYPE_GATHER_ACCESS_DIRECT, | |
242 | SIDE_TYPE_GATHER_ACCESS_POINTER, /* Pointer dereference */ | |
243 | }; | |
244 | ||
245 | typedef enum side_visitor_status (*side_visitor_func)( | |
246 | const struct side_tracer_visitor_ctx *tracer_ctx, | |
247 | void *app_ctx); | |
248 | typedef enum side_visitor_status (*side_dynamic_struct_visitor_func)( | |
249 | const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, | |
250 | void *app_ctx); | |
2e197497 MD |
251 | typedef enum side_visitor_status (*side_write_elem_func)( |
252 | const struct side_tracer_visitor_ctx *tracer_ctx, | |
253 | const struct side_arg *elem); | |
254 | typedef enum side_visitor_status (*side_write_field_func)( | |
255 | const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, | |
256 | const struct side_arg_dynamic_field *dynamic_field); | |
67337c4a MD |
257 | |
258 | union side_integer_value { | |
259 | uint8_t side_u8; | |
260 | uint16_t side_u16; | |
261 | uint32_t side_u32; | |
262 | uint64_t side_u64; | |
263 | int8_t side_s8; | |
264 | int16_t side_s16; | |
265 | int32_t side_s32; | |
266 | int64_t side_s64; | |
267 | uintptr_t side_uptr; | |
2e197497 | 268 | side_padding(32); |
67337c4a | 269 | } SIDE_PACKED; |
2e197497 | 270 | side_check_size(union side_integer_value, 32); |
67337c4a MD |
271 | |
272 | union side_bool_value { | |
273 | uint8_t side_bool8; | |
274 | uint16_t side_bool16; | |
275 | uint32_t side_bool32; | |
276 | uint64_t side_bool64; | |
2e197497 | 277 | side_padding(32); |
67337c4a | 278 | } SIDE_PACKED; |
2e197497 | 279 | side_check_size(union side_bool_value, 32); |
67337c4a MD |
280 | |
281 | union side_float_value { | |
282 | #if __HAVE_FLOAT16 | |
283 | _Float16 side_float_binary16; | |
284 | #endif | |
285 | #if __HAVE_FLOAT32 | |
286 | _Float32 side_float_binary32; | |
287 | #endif | |
288 | #if __HAVE_FLOAT64 | |
289 | _Float64 side_float_binary64; | |
290 | #endif | |
291 | #if __HAVE_FLOAT128 | |
292 | _Float128 side_float_binary128; | |
293 | #endif | |
2e197497 | 294 | side_padding(32); |
67337c4a | 295 | } SIDE_PACKED; |
2e197497 | 296 | side_check_size(union side_float_value, 32); |
67337c4a MD |
297 | |
298 | struct side_type_raw_string { | |
3db2d8a1 | 299 | side_ptr_t(const void) p; /* pointer to string */ |
67337c4a | 300 | uint8_t unit_size; /* 1, 2, or 4 bytes */ |
3bc9ba43 | 301 | side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order; |
67337c4a | 302 | } SIDE_PACKED; |
2e197497 | 303 | side_check_size(struct side_type_raw_string, 18); |
67337c4a MD |
304 | |
305 | struct side_attr_value { | |
15f17024 | 306 | side_enum_t(enum side_attr_type, uint32_t) type; |
67337c4a MD |
307 | union { |
308 | uint8_t bool_value; | |
309 | struct side_type_raw_string string_value; | |
310 | union side_integer_value integer_value; | |
311 | union side_float_value float_value; | |
2e197497 | 312 | side_padding(32); |
67337c4a MD |
313 | } SIDE_PACKED u; |
314 | }; | |
2e197497 | 315 | side_check_size(struct side_attr_value, 36); |
67337c4a MD |
316 | |
317 | /* User attributes. */ | |
318 | struct side_attr { | |
319 | const struct side_type_raw_string key; | |
320 | const struct side_attr_value value; | |
321 | } SIDE_PACKED; | |
2e197497 | 322 | side_check_size(struct side_attr, 54); |
67337c4a MD |
323 | |
324 | /* Type descriptions */ | |
325 | struct side_type_null { | |
b313067b | 326 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
327 | uint32_t nr_attr; |
328 | } SIDE_PACKED; | |
2e197497 | 329 | side_check_size(struct side_type_null, 20); |
67337c4a MD |
330 | |
331 | struct side_type_bool { | |
db8df9b5 | 332 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
333 | uint32_t nr_attr; |
334 | uint16_t bool_size; /* bytes */ | |
335 | uint16_t len_bits; /* bits. 0 for (bool_size * CHAR_BITS) */ | |
3bc9ba43 | 336 | side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order; |
67337c4a | 337 | } SIDE_PACKED; |
2e197497 | 338 | side_check_size(struct side_type_bool, 25); |
67337c4a MD |
339 | |
340 | struct side_type_byte { | |
12d787db | 341 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
342 | uint32_t nr_attr; |
343 | } SIDE_PACKED; | |
2e197497 | 344 | side_check_size(struct side_type_byte, 20); |
67337c4a MD |
345 | |
346 | struct side_type_string { | |
12d787db | 347 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
348 | uint32_t nr_attr; |
349 | uint8_t unit_size; /* 1, 2, or 4 bytes */ | |
3bc9ba43 | 350 | side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order; |
67337c4a | 351 | } SIDE_PACKED; |
2e197497 | 352 | side_check_size(struct side_type_string, 22); |
67337c4a MD |
353 | |
354 | struct side_type_integer { | |
12d787db | 355 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
356 | uint32_t nr_attr; |
357 | uint16_t integer_size; /* bytes */ | |
358 | uint16_t len_bits; /* bits. 0 for (integer_size * CHAR_BITS) */ | |
359 | uint8_t signedness; /* true/false */ | |
3bc9ba43 | 360 | side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order; |
67337c4a | 361 | } SIDE_PACKED; |
2e197497 | 362 | side_check_size(struct side_type_integer, 26); |
67337c4a MD |
363 | |
364 | struct side_type_float { | |
12d787db | 365 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
366 | uint32_t nr_attr; |
367 | uint16_t float_size; /* bytes */ | |
3bc9ba43 | 368 | side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order; |
67337c4a | 369 | } SIDE_PACKED; |
2e197497 | 370 | side_check_size(struct side_type_float, 23); |
67337c4a MD |
371 | |
372 | struct side_enum_mapping { | |
373 | int64_t range_begin; | |
374 | int64_t range_end; | |
375 | struct side_type_raw_string label; | |
376 | } SIDE_PACKED; | |
2e197497 | 377 | side_check_size(struct side_enum_mapping, 16 + sizeof(struct side_type_raw_string)); |
67337c4a MD |
378 | |
379 | struct side_enum_mappings { | |
64037418 | 380 | side_ptr_t(const struct side_enum_mapping) mappings; |
12d787db | 381 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
382 | uint32_t nr_mappings; |
383 | uint32_t nr_attr; | |
384 | } SIDE_PACKED; | |
2e197497 | 385 | side_check_size(struct side_enum_mappings, 40); |
67337c4a MD |
386 | |
387 | struct side_enum_bitmap_mapping { | |
388 | uint64_t range_begin; | |
389 | uint64_t range_end; | |
390 | struct side_type_raw_string label; | |
391 | } SIDE_PACKED; | |
2e197497 | 392 | side_check_size(struct side_enum_bitmap_mapping, 16 + sizeof(struct side_type_raw_string)); |
67337c4a MD |
393 | |
394 | struct side_enum_bitmap_mappings { | |
64037418 | 395 | side_ptr_t(const struct side_enum_bitmap_mapping) mappings; |
12d787db | 396 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
397 | uint32_t nr_mappings; |
398 | uint32_t nr_attr; | |
399 | } SIDE_PACKED; | |
2e197497 | 400 | side_check_size(struct side_enum_bitmap_mappings, 40); |
67337c4a MD |
401 | |
402 | struct side_type_struct { | |
c5789285 | 403 | side_ptr_t(const struct side_event_field) fields; |
12d787db | 404 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
405 | uint32_t nr_fields; |
406 | uint32_t nr_attr; | |
407 | } SIDE_PACKED; | |
2e197497 | 408 | side_check_size(struct side_type_struct, 40); |
67337c4a MD |
409 | |
410 | struct side_type_array { | |
c5789285 | 411 | side_ptr_t(const struct side_type) elem_type; |
12d787db | 412 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
413 | uint32_t length; |
414 | uint32_t nr_attr; | |
415 | } SIDE_PACKED; | |
2e197497 | 416 | side_check_size(struct side_type_array, 40); |
67337c4a MD |
417 | |
418 | struct side_type_vla { | |
c5789285 | 419 | side_ptr_t(const struct side_type) elem_type; |
12d787db | 420 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
421 | uint32_t nr_attr; |
422 | } SIDE_PACKED; | |
2e197497 | 423 | side_check_size(struct side_type_vla, 36); |
67337c4a MD |
424 | |
425 | struct side_type_vla_visitor { | |
c5789285 | 426 | side_ptr_t(const struct side_type) elem_type; |
2e197497 | 427 | side_func_ptr_t(side_visitor_func) visitor; |
12d787db | 428 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
429 | uint32_t nr_attr; |
430 | } SIDE_PACKED; | |
2e197497 | 431 | side_check_size(struct side_type_vla_visitor, 52); |
67337c4a MD |
432 | |
433 | struct side_type_enum { | |
64037418 | 434 | side_ptr_t(const struct side_enum_mappings) mappings; |
c5789285 | 435 | side_ptr_t(const struct side_type) elem_type; |
67337c4a | 436 | } SIDE_PACKED; |
2e197497 | 437 | side_check_size(struct side_type_enum, 32); |
67337c4a MD |
438 | |
439 | struct side_type_enum_bitmap { | |
64037418 | 440 | side_ptr_t(const struct side_enum_bitmap_mappings) mappings; |
c5789285 | 441 | side_ptr_t(const struct side_type) elem_type; |
67337c4a | 442 | } SIDE_PACKED; |
2e197497 | 443 | side_check_size(struct side_type_enum_bitmap, 32); |
67337c4a MD |
444 | |
445 | struct side_type_gather_bool { | |
446 | uint64_t offset; /* bytes */ | |
2e197497 | 447 | uint16_t offset_bits; /* bits */ |
67337c4a MD |
448 | uint8_t access_mode; /* enum side_type_gather_access_mode */ |
449 | struct side_type_bool type; | |
67337c4a | 450 | } SIDE_PACKED; |
2e197497 | 451 | side_check_size(struct side_type_gather_bool, 11 + sizeof(struct side_type_bool)); |
67337c4a MD |
452 | |
453 | struct side_type_gather_byte { | |
454 | uint64_t offset; /* bytes */ | |
455 | uint8_t access_mode; /* enum side_type_gather_access_mode */ | |
456 | struct side_type_byte type; | |
457 | } SIDE_PACKED; | |
2e197497 | 458 | side_check_size(struct side_type_gather_byte, 9 + sizeof(struct side_type_byte)); |
67337c4a MD |
459 | |
460 | struct side_type_gather_integer { | |
461 | uint64_t offset; /* bytes */ | |
2e197497 | 462 | uint16_t offset_bits; /* bits */ |
67337c4a MD |
463 | uint8_t access_mode; /* enum side_type_gather_access_mode */ |
464 | struct side_type_integer type; | |
67337c4a | 465 | } SIDE_PACKED; |
2e197497 | 466 | side_check_size(struct side_type_gather_integer, 11 + sizeof(struct side_type_integer)); |
67337c4a MD |
467 | |
468 | struct side_type_gather_float { | |
469 | uint64_t offset; /* bytes */ | |
470 | uint8_t access_mode; /* enum side_type_gather_access_mode */ | |
471 | struct side_type_float type; | |
472 | } SIDE_PACKED; | |
2e197497 | 473 | side_check_size(struct side_type_gather_float, 9 + sizeof(struct side_type_float)); |
67337c4a MD |
474 | |
475 | struct side_type_gather_string { | |
476 | uint64_t offset; /* bytes */ | |
477 | uint8_t access_mode; /* enum side_type_gather_access_mode */ | |
478 | struct side_type_string type; | |
479 | } SIDE_PACKED; | |
2e197497 | 480 | side_check_size(struct side_type_gather_string, 9 + sizeof(struct side_type_string)); |
67337c4a MD |
481 | |
482 | struct side_type_gather_enum { | |
64037418 | 483 | side_ptr_t(const struct side_enum_mappings) mappings; |
c5789285 | 484 | side_ptr_t(const struct side_type) elem_type; |
67337c4a | 485 | } SIDE_PACKED; |
2e197497 | 486 | side_check_size(struct side_type_gather_enum, 32); |
67337c4a MD |
487 | |
488 | struct side_type_gather_struct { | |
2e197497 | 489 | side_ptr_t(const struct side_type_struct) type; |
67337c4a MD |
490 | uint64_t offset; /* bytes */ |
491 | uint8_t access_mode; /* enum side_type_gather_access_mode */ | |
67337c4a MD |
492 | uint32_t size; /* bytes */ |
493 | } SIDE_PACKED; | |
2e197497 | 494 | side_check_size(struct side_type_gather_struct, 29); |
67337c4a MD |
495 | |
496 | struct side_type_gather_array { | |
497 | uint64_t offset; /* bytes */ | |
498 | uint8_t access_mode; /* enum side_type_gather_access_mode */ | |
499 | struct side_type_array type; | |
500 | } SIDE_PACKED; | |
2e197497 | 501 | side_check_size(struct side_type_gather_array, 9 + sizeof(struct side_type_array)); |
67337c4a MD |
502 | |
503 | struct side_type_gather_vla { | |
c5789285 | 504 | side_ptr_t(const struct side_type) length_type; /* side_length() */ |
67337c4a MD |
505 | uint64_t offset; /* bytes */ |
506 | uint8_t access_mode; /* enum side_type_gather_access_mode */ | |
507 | struct side_type_vla type; | |
508 | } SIDE_PACKED; | |
2e197497 | 509 | side_check_size(struct side_type_gather_vla, 25 + sizeof(struct side_type_vla)); |
67337c4a MD |
510 | |
511 | struct side_type_gather { | |
512 | union { | |
513 | struct side_type_gather_bool side_bool; | |
514 | struct side_type_gather_byte side_byte; | |
515 | struct side_type_gather_integer side_integer; | |
516 | struct side_type_gather_float side_float; | |
517 | struct side_type_gather_string side_string; | |
518 | struct side_type_gather_enum side_enum; | |
519 | struct side_type_gather_array side_array; | |
520 | struct side_type_gather_vla side_vla; | |
521 | struct side_type_gather_struct side_struct; | |
2e197497 | 522 | side_padding(61); |
67337c4a MD |
523 | } SIDE_PACKED u; |
524 | } SIDE_PACKED; | |
2e197497 | 525 | side_check_size(struct side_type_gather, 61); |
67337c4a MD |
526 | |
527 | struct side_type { | |
2e197497 | 528 | side_enum_t(enum side_type_label, uint16_t) type; |
67337c4a MD |
529 | union { |
530 | /* Stack-copy basic types */ | |
531 | struct side_type_null side_null; | |
532 | struct side_type_bool side_bool; | |
533 | struct side_type_byte side_byte; | |
534 | struct side_type_string side_string; | |
535 | struct side_type_integer side_integer; | |
536 | struct side_type_float side_float; | |
537 | ||
538 | /* Stack-copy compound types */ | |
539 | struct side_type_array side_array; | |
540 | struct side_type_vla side_vla; | |
541 | struct side_type_vla_visitor side_vla_visitor; | |
c5789285 MD |
542 | side_ptr_t(const struct side_type_struct) side_struct; |
543 | side_ptr_t(const struct side_type_variant) side_variant; | |
67337c4a MD |
544 | |
545 | /* Stack-copy enumeration types */ | |
546 | struct side_type_enum side_enum; | |
547 | struct side_type_enum_bitmap side_enum_bitmap; | |
548 | ||
549 | /* Gather types */ | |
550 | struct side_type_gather side_gather; | |
2e197497 | 551 | side_padding(62); |
67337c4a MD |
552 | } SIDE_PACKED u; |
553 | } SIDE_PACKED; | |
2e197497 | 554 | side_check_size(struct side_type, 64); |
67337c4a | 555 | |
5530345d MD |
556 | struct side_variant_option { |
557 | int64_t range_begin; | |
558 | int64_t range_end; | |
559 | const struct side_type side_type; | |
560 | } SIDE_PACKED; | |
2e197497 | 561 | side_check_size(struct side_variant_option, 16 + sizeof(const struct side_type)); |
5530345d MD |
562 | |
563 | struct side_type_variant { | |
c5789285 | 564 | side_ptr_t(const struct side_variant_option) options; |
12d787db | 565 | side_ptr_t(const struct side_attr) attr; |
5530345d MD |
566 | uint32_t nr_options; |
567 | uint32_t nr_attr; | |
2e197497 | 568 | const struct side_type selector; |
5530345d | 569 | } SIDE_PACKED; |
2e197497 | 570 | side_check_size(struct side_type_variant, 40 + sizeof(const struct side_type)); |
5530345d | 571 | |
67337c4a | 572 | struct side_event_field { |
c5789285 | 573 | side_ptr_t(const char) field_name; |
67337c4a MD |
574 | struct side_type side_type; |
575 | } SIDE_PACKED; | |
2e197497 | 576 | side_check_size(struct side_event_field, 16 + sizeof(struct side_type)); |
67337c4a MD |
577 | |
578 | enum side_event_flags { | |
579 | SIDE_EVENT_FLAG_VARIADIC = (1 << 0), | |
580 | }; | |
581 | ||
09515e04 | 582 | union side_arg_static { |
67337c4a MD |
583 | /* Stack-copy basic types */ |
584 | union side_bool_value bool_value; | |
585 | uint8_t byte_value; | |
6910c28c | 586 | side_ptr_t(const void) string_value; /* const {uint8_t, uint16_t, uint32_t} * */ |
67337c4a MD |
587 | union side_integer_value integer_value; |
588 | union side_float_value float_value; | |
589 | ||
590 | /* Stack-copy compound types */ | |
bac71609 MD |
591 | side_ptr_t(const struct side_arg_vec) side_struct; |
592 | side_ptr_t(const struct side_arg_variant) side_variant; | |
593 | side_ptr_t(const struct side_arg_vec) side_array; | |
594 | side_ptr_t(const struct side_arg_vec) side_vla; | |
67337c4a MD |
595 | void *side_vla_app_visitor_ctx; |
596 | ||
597 | /* Gather basic types */ | |
155b1756 MD |
598 | side_ptr_t(const void) side_bool_gather_ptr; |
599 | side_ptr_t(const void) side_byte_gather_ptr; | |
600 | side_ptr_t(const void) side_integer_gather_ptr; | |
601 | side_ptr_t(const void) side_float_gather_ptr; | |
602 | side_ptr_t(const void) side_string_gather_ptr; | |
67337c4a MD |
603 | |
604 | /* Gather compound types */ | |
155b1756 MD |
605 | side_ptr_t(const void) side_array_gather_ptr; |
606 | side_ptr_t(const void) side_struct_gather_ptr; | |
67337c4a | 607 | struct { |
155b1756 MD |
608 | side_ptr_t(const void) ptr; |
609 | side_ptr_t(const void) length_ptr; | |
67337c4a | 610 | } SIDE_PACKED side_vla_gather; |
2e197497 | 611 | side_padding(32); |
67337c4a | 612 | } SIDE_PACKED; |
2e197497 | 613 | side_check_size(union side_arg_static, 32); |
67337c4a MD |
614 | |
615 | struct side_arg_dynamic_vla { | |
f13253cb | 616 | side_ptr_t(const struct side_arg) sav; |
12d787db | 617 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
618 | uint32_t len; |
619 | uint32_t nr_attr; | |
620 | } SIDE_PACKED; | |
2e197497 | 621 | side_check_size(struct side_arg_dynamic_vla, 40); |
67337c4a MD |
622 | |
623 | struct side_arg_dynamic_struct { | |
f13253cb | 624 | side_ptr_t(const struct side_arg_dynamic_field) fields; |
12d787db | 625 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
626 | uint32_t len; |
627 | uint32_t nr_attr; | |
628 | } SIDE_PACKED; | |
2e197497 | 629 | side_check_size(struct side_arg_dynamic_struct, 40); |
67337c4a MD |
630 | |
631 | struct side_dynamic_struct_visitor { | |
2e197497 MD |
632 | side_func_ptr_t(side_dynamic_struct_visitor_func) visitor; |
633 | side_ptr_t(void) app_ctx; | |
12d787db | 634 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
635 | uint32_t nr_attr; |
636 | } SIDE_PACKED; | |
2e197497 | 637 | side_check_size(struct side_dynamic_struct_visitor, 52); |
67337c4a MD |
638 | |
639 | struct side_dynamic_vla_visitor { | |
2e197497 MD |
640 | side_func_ptr_t(side_visitor_func) visitor; |
641 | side_ptr_t(void) app_ctx; | |
12d787db | 642 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
643 | uint32_t nr_attr; |
644 | } SIDE_PACKED; | |
2e197497 | 645 | side_check_size(struct side_dynamic_vla_visitor, 52); |
67337c4a | 646 | |
09515e04 | 647 | union side_arg_dynamic { |
67337c4a MD |
648 | /* Dynamic basic types */ |
649 | struct side_type_null side_null; | |
650 | struct { | |
651 | struct side_type_bool type; | |
652 | union side_bool_value value; | |
653 | } SIDE_PACKED side_bool; | |
654 | struct { | |
655 | struct side_type_byte type; | |
656 | uint8_t value; | |
657 | } SIDE_PACKED side_byte; | |
658 | struct { | |
659 | struct side_type_string type; | |
660 | uint64_t value; /* const char * */ | |
661 | } SIDE_PACKED side_string; | |
662 | struct { | |
663 | struct side_type_integer type; | |
664 | union side_integer_value value; | |
665 | } SIDE_PACKED side_integer; | |
666 | struct { | |
667 | struct side_type_float type; | |
668 | union side_float_value value; | |
669 | } SIDE_PACKED side_float; | |
670 | ||
671 | /* Dynamic compound types */ | |
f13253cb MD |
672 | side_ptr_t(const struct side_arg_dynamic_struct) side_dynamic_struct; |
673 | side_ptr_t(const struct side_arg_dynamic_vla) side_dynamic_vla; | |
67337c4a MD |
674 | |
675 | struct side_dynamic_struct_visitor side_dynamic_struct_visitor; | |
676 | struct side_dynamic_vla_visitor side_dynamic_vla_visitor; | |
2e197497 MD |
677 | |
678 | side_padding(58); | |
67337c4a | 679 | } SIDE_PACKED; |
2e197497 | 680 | side_check_size(union side_arg_dynamic, 58); |
67337c4a MD |
681 | |
682 | struct side_arg { | |
2e197497 | 683 | side_enum_t(enum side_type_label, uint16_t) type; |
67337c4a | 684 | union { |
09515e04 MD |
685 | union side_arg_static side_static; |
686 | union side_arg_dynamic side_dynamic; | |
2e197497 | 687 | side_padding(62); |
67337c4a MD |
688 | } SIDE_PACKED u; |
689 | } SIDE_PACKED; | |
2e197497 | 690 | side_check_size(struct side_arg, 64); |
67337c4a | 691 | |
5530345d MD |
692 | struct side_arg_variant { |
693 | struct side_arg selector; | |
694 | struct side_arg option; | |
695 | } SIDE_PACKED; | |
2e197497 | 696 | side_check_size(struct side_arg_variant, 128); |
5530345d | 697 | |
67337c4a | 698 | struct side_arg_vec { |
f13253cb | 699 | side_ptr_t(const struct side_arg) sav; |
67337c4a MD |
700 | uint32_t len; |
701 | } SIDE_PACKED; | |
2e197497 | 702 | side_check_size(struct side_arg_vec, 20); |
67337c4a MD |
703 | |
704 | struct side_arg_dynamic_field { | |
f13253cb | 705 | side_ptr_t(const char) field_name; |
67337c4a MD |
706 | const struct side_arg elem; |
707 | } SIDE_PACKED; | |
2e197497 | 708 | side_check_size(struct side_arg_dynamic_field, 16 + sizeof(const struct side_arg)); |
67337c4a MD |
709 | |
710 | struct side_event_description { | |
0b9e59d6 MD |
711 | side_ptr_t(struct side_event_state) state; |
712 | side_ptr_t(const char) provider_name; | |
713 | side_ptr_t(const char) event_name; | |
714 | side_ptr_t(const struct side_event_field) fields; | |
12d787db | 715 | side_ptr_t(const struct side_attr) attr; |
67337c4a MD |
716 | uint64_t flags; |
717 | uint32_t version; | |
1f7aaefb | 718 | side_enum_t(enum side_loglevel, uint32_t) loglevel; |
67337c4a MD |
719 | uint32_t nr_fields; |
720 | uint32_t nr_attr; | |
f8188f94 | 721 | uint32_t nr_callbacks; |
67337c4a MD |
722 | } SIDE_PACKED; |
723 | ||
0d747f98 MD |
724 | /* |
725 | * This structure is _not_ packed to allow atomic operations on its | |
726 | * fields. | |
727 | */ | |
728 | struct side_event_state { | |
729 | uintptr_t enabled; | |
730 | const struct side_callback *callbacks; | |
731 | struct side_event_description *desc; | |
732 | }; | |
733 | ||
67337c4a MD |
734 | /* Event and type attributes */ |
735 | ||
736 | #define side_attr(_key, _value) \ | |
737 | { \ | |
738 | .key = { \ | |
d1251f44 | 739 | .p = SIDE_PTR_INIT(_key), \ |
67337c4a | 740 | .unit_size = sizeof(uint8_t), \ |
3bc9ba43 | 741 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ |
67337c4a MD |
742 | }, \ |
743 | .value = SIDE_PARAM(_value), \ | |
744 | } | |
745 | ||
746 | #define side_attr_list(...) \ | |
747 | SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__) | |
748 | ||
749 | #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL } | |
15f17024 MD |
750 | #define side_attr_bool(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_BOOL), .u = { .bool_value = !!(_val) } } |
751 | #define side_attr_u8(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U8), .u = { .integer_value = { .side_u8 = (_val) } } } | |
752 | #define side_attr_u16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U16), .u = { .integer_value = { .side_u16 = (_val) } } } | |
753 | #define side_attr_u32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U32), .u = { .integer_value = { .side_u32 = (_val) } } } | |
754 | #define side_attr_u64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U64), .u = { .integer_value = { .side_u64 = (_val) } } } | |
755 | #define side_attr_s8(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S8), .u = { .integer_value = { .side_s8 = (_val) } } } | |
756 | #define side_attr_s16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S16), .u = { .integer_value = { .side_s16 = (_val) } } } | |
757 | #define side_attr_s32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S32), .u = { .integer_value = { .side_s32 = (_val) } } } | |
758 | #define side_attr_s64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S64), .u = { .integer_value = { .side_s64 = (_val) } } } | |
759 | #define side_attr_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY16), .u = { .float_value = { .side_float_binary16 = (_val) } } } | |
760 | #define side_attr_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY32), .u = { .float_value = { .side_float_binary32 = (_val) } } } | |
761 | #define side_attr_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY64), .u = { .float_value = { .side_float_binary64 = (_val) } } } | |
762 | #define side_attr_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY128), .u = { .float_value = { .side_float_binary128 = (_val) } } } | |
67337c4a MD |
763 | |
764 | #define _side_attr_string(_val, _byte_order, _unit_size) \ | |
765 | { \ | |
15f17024 | 766 | .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_STRING), \ |
67337c4a MD |
767 | .u = { \ |
768 | .string_value = { \ | |
d1251f44 | 769 | .p = SIDE_PTR_INIT(_val), \ |
67337c4a | 770 | .unit_size = _unit_size, \ |
3bc9ba43 | 771 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
772 | }, \ |
773 | }, \ | |
774 | } | |
775 | ||
776 | #define side_attr_string(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t)) | |
777 | #define side_attr_string16(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t)) | |
778 | #define side_attr_string32(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t)) | |
779 | ||
780 | /* Stack-copy enumeration type definitions */ | |
781 | ||
d5a4e361 | 782 | #define side_define_enum(_identifier, _mappings, _attr...) \ |
67337c4a | 783 | const struct side_enum_mappings _identifier = { \ |
64037418 | 784 | .mappings = SIDE_PTR_INIT(_mappings), \ |
12d787db | 785 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 786 | .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ |
d5a4e361 | 787 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
788 | } |
789 | ||
790 | #define side_enum_mapping_list(...) \ | |
791 | SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__) | |
792 | ||
793 | #define side_enum_mapping_range(_label, _begin, _end) \ | |
794 | { \ | |
795 | .range_begin = _begin, \ | |
796 | .range_end = _end, \ | |
797 | .label = { \ | |
d1251f44 | 798 | .p = SIDE_PTR_INIT(_label), \ |
67337c4a | 799 | .unit_size = sizeof(uint8_t), \ |
3bc9ba43 | 800 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ |
67337c4a MD |
801 | }, \ |
802 | } | |
803 | ||
804 | #define side_enum_mapping_value(_label, _value) \ | |
805 | { \ | |
806 | .range_begin = _value, \ | |
807 | .range_end = _value, \ | |
808 | .label = { \ | |
d1251f44 | 809 | .p = SIDE_PTR_INIT(_label), \ |
67337c4a | 810 | .unit_size = sizeof(uint8_t), \ |
3bc9ba43 | 811 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ |
67337c4a MD |
812 | }, \ |
813 | } | |
814 | ||
d5a4e361 | 815 | #define side_define_enum_bitmap(_identifier, _mappings, _attr...) \ |
67337c4a | 816 | const struct side_enum_bitmap_mappings _identifier = { \ |
64037418 | 817 | .mappings = SIDE_PTR_INIT(_mappings), \ |
12d787db | 818 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 819 | .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ |
d5a4e361 | 820 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
821 | } |
822 | ||
823 | #define side_enum_bitmap_mapping_list(...) \ | |
824 | SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__) | |
825 | ||
826 | #define side_enum_bitmap_mapping_range(_label, _begin, _end) \ | |
827 | { \ | |
828 | .range_begin = _begin, \ | |
829 | .range_end = _end, \ | |
830 | .label = { \ | |
d1251f44 | 831 | .p = SIDE_PTR_INIT(_label), \ |
67337c4a | 832 | .unit_size = sizeof(uint8_t), \ |
3bc9ba43 | 833 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ |
67337c4a MD |
834 | }, \ |
835 | } | |
836 | ||
837 | #define side_enum_bitmap_mapping_value(_label, _value) \ | |
838 | { \ | |
839 | .range_begin = _value, \ | |
840 | .range_end = _value, \ | |
841 | .label = { \ | |
d1251f44 | 842 | .p = SIDE_PTR_INIT(_label), \ |
67337c4a | 843 | .unit_size = sizeof(uint8_t), \ |
3bc9ba43 | 844 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ |
67337c4a MD |
845 | }, \ |
846 | } | |
847 | ||
848 | /* Stack-copy field and type definitions */ | |
849 | ||
d5a4e361 | 850 | #define side_type_null(_attr...) \ |
67337c4a | 851 | { \ |
3ce69bfa | 852 | .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL), \ |
67337c4a MD |
853 | .u = { \ |
854 | .side_null = { \ | |
b313067b | 855 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 856 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
857 | }, \ |
858 | }, \ | |
859 | } | |
860 | ||
d5a4e361 | 861 | #define side_type_bool(_attr...) \ |
67337c4a | 862 | { \ |
3ce69bfa | 863 | .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), \ |
67337c4a MD |
864 | .u = { \ |
865 | .side_bool = { \ | |
db8df9b5 | 866 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 867 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
868 | .bool_size = sizeof(uint8_t), \ |
869 | .len_bits = 0, \ | |
3bc9ba43 | 870 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ |
67337c4a MD |
871 | }, \ |
872 | }, \ | |
873 | } | |
874 | ||
d5a4e361 | 875 | #define side_type_byte(_attr...) \ |
67337c4a | 876 | { \ |
3ce69bfa | 877 | .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), \ |
67337c4a MD |
878 | .u = { \ |
879 | .side_byte = { \ | |
12d787db | 880 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 881 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
882 | }, \ |
883 | }, \ | |
884 | } | |
885 | ||
886 | #define _side_type_string(_type, _byte_order, _unit_size, _attr) \ | |
887 | { \ | |
3ce69bfa | 888 | .type = SIDE_ENUM_INIT(_type), \ |
67337c4a MD |
889 | .u = { \ |
890 | .side_string = { \ | |
12d787db | 891 | .attr = SIDE_PTR_INIT(_attr), \ |
67337c4a MD |
892 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
893 | .unit_size = _unit_size, \ | |
3bc9ba43 | 894 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
895 | }, \ |
896 | }, \ | |
897 | } | |
898 | ||
899 | #define side_type_dynamic() \ | |
900 | { \ | |
3ce69bfa | 901 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC), \ |
67337c4a MD |
902 | } |
903 | ||
904 | #define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \ | |
905 | { \ | |
3ce69bfa | 906 | .type = SIDE_ENUM_INIT(_type), \ |
67337c4a MD |
907 | .u = { \ |
908 | .side_integer = { \ | |
12d787db | 909 | .attr = SIDE_PTR_INIT(_attr), \ |
67337c4a MD |
910 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
911 | .integer_size = _integer_size, \ | |
912 | .len_bits = _len_bits, \ | |
913 | .signedness = _signedness, \ | |
3bc9ba43 | 914 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
915 | }, \ |
916 | }, \ | |
917 | } | |
918 | ||
919 | #define _side_type_float(_type, _byte_order, _float_size, _attr) \ | |
920 | { \ | |
3ce69bfa | 921 | .type = SIDE_ENUM_INIT(_type), \ |
67337c4a MD |
922 | .u = { \ |
923 | .side_float = { \ | |
12d787db | 924 | .attr = SIDE_PTR_INIT(_attr), \ |
67337c4a MD |
925 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ |
926 | .float_size = _float_size, \ | |
3bc9ba43 | 927 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
928 | }, \ |
929 | }, \ | |
930 | } | |
931 | ||
932 | #define _side_field(_name, _type) \ | |
933 | { \ | |
c5789285 | 934 | .field_name = SIDE_PTR_INIT(_name), \ |
67337c4a MD |
935 | .side_type = _type, \ |
936 | } | |
937 | ||
5530345d MD |
938 | #define side_option_range(_range_begin, _range_end, _type) \ |
939 | { \ | |
940 | .range_begin = _range_begin, \ | |
941 | .range_end = _range_end, \ | |
942 | .side_type = _type, \ | |
943 | } | |
944 | ||
945 | #define side_option(_value, _type) \ | |
946 | side_option_range(_value, _value, SIDE_PARAM(_type)) | |
947 | ||
67337c4a | 948 | /* Host endian */ |
d5a4e361 MD |
949 | #define side_type_u8(_attr...) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
950 | #define side_type_u16(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
951 | #define side_type_u32(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
952 | #define side_type_u64(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
953 | #define side_type_s8(_attr...) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
954 | #define side_type_s16(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
955 | #define side_type_s32(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
956 | #define side_type_s64(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
957 | #define side_type_pointer(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
958 | #define side_type_float_binary16(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
959 | #define side_type_float_binary32(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
960 | #define side_type_float_binary64(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
961 | #define side_type_float_binary128(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
962 | #define side_type_string(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF8, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
963 | #define side_type_string16(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
964 | #define side_type_string32(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
965 | ||
966 | #define side_field_null(_name, _attr...) _side_field(_name, side_type_null(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
967 | #define side_field_bool(_name, _attr...) _side_field(_name, side_type_bool(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
968 | #define side_field_u8(_name, _attr...) _side_field(_name, side_type_u8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
969 | #define side_field_u16(_name, _attr...) _side_field(_name, side_type_u16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
970 | #define side_field_u32(_name, _attr...) _side_field(_name, side_type_u32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
971 | #define side_field_u64(_name, _attr...) _side_field(_name, side_type_u64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
972 | #define side_field_s8(_name, _attr...) _side_field(_name, side_type_s8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
973 | #define side_field_s16(_name, _attr...) _side_field(_name, side_type_s16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
974 | #define side_field_s32(_name, _attr...) _side_field(_name, side_type_s32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
975 | #define side_field_s64(_name, _attr...) _side_field(_name, side_type_s64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
976 | #define side_field_byte(_name, _attr...) _side_field(_name, side_type_byte(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
977 | #define side_field_pointer(_name, _attr...) _side_field(_name, side_type_pointer(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
978 | #define side_field_float_binary16(_name, _attr...) _side_field(_name, side_type_float_binary16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
979 | #define side_field_float_binary32(_name, _attr...) _side_field(_name, side_type_float_binary32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
980 | #define side_field_float_binary64(_name, _attr...) _side_field(_name, side_type_float_binary64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
981 | #define side_field_float_binary128(_name, _attr...) _side_field(_name, side_type_float_binary128(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
982 | #define side_field_string(_name, _attr...) _side_field(_name, side_type_string(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
983 | #define side_field_string16(_name, _attr...) _side_field(_name, side_type_string16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
984 | #define side_field_string32(_name, _attr...) _side_field(_name, side_type_string32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a MD |
985 | #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic()) |
986 | ||
987 | /* Little endian */ | |
d5a4e361 MD |
988 | #define side_type_u16_le(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
989 | #define side_type_u32_le(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
990 | #define side_type_u64_le(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
991 | #define side_type_s16_le(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
992 | #define side_type_s32_le(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
993 | #define side_type_s64_le(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
994 | #define side_type_pointer_le(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
995 | #define side_type_float_binary16_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
996 | #define side_type_float_binary32_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
997 | #define side_type_float_binary64_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
998 | #define side_type_float_binary128_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
999 | #define side_type_string16_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1000 | #define side_type_string32_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1001 | ||
1002 | #define side_field_u16_le(_name, _attr...) _side_field(_name, side_type_u16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1003 | #define side_field_u32_le(_name, _attr...) _side_field(_name, side_type_u32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1004 | #define side_field_u64_le(_name, _attr...) _side_field(_name, side_type_u64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1005 | #define side_field_s16_le(_name, _attr...) _side_field(_name, side_type_s16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1006 | #define side_field_s32_le(_name, _attr...) _side_field(_name, side_type_s32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1007 | #define side_field_s64_le(_name, _attr...) _side_field(_name, side_type_s64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1008 | #define side_field_pointer_le(_name, _attr...) _side_field(_name, side_type_pointer_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1009 | #define side_field_float_binary16_le(_name, _attr...) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1010 | #define side_field_float_binary32_le(_name, _attr...) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1011 | #define side_field_float_binary64_le(_name, _attr...) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1012 | #define side_field_float_binary128_le(_name, _attr...) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1013 | #define side_field_string16_le(_name, _attr...) _side_field(_name, side_type_string16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1014 | #define side_field_string32_le(_name, _attr...) _side_field(_name, side_type_string32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a MD |
1015 | |
1016 | /* Big endian */ | |
d5a4e361 MD |
1017 | #define side_type_u16_be(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1018 | #define side_type_u32_be(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1019 | #define side_type_u64_be(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1020 | #define side_type_s16_be(_attr...) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1021 | #define side_type_s32_be(_attr...) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1022 | #define side_type_s64_be(_attr...) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1023 | #define side_type_pointer_be(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1024 | #define side_type_float_binary16_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1025 | #define side_type_float_binary32_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1026 | #define side_type_float_binary64_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1027 | #define side_type_float_binary128_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1028 | #define side_type_string16_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1029 | #define side_type_string32_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1030 | ||
1031 | #define side_field_u16_be(_name, _attr...) _side_field(_name, side_type_u16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1032 | #define side_field_u32_be(_name, _attr...) _side_field(_name, side_type_u32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1033 | #define side_field_u64_be(_name, _attr...) _side_field(_name, side_type_u64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1034 | #define side_field_s16_be(_name, _attr...) _side_field(_name, side_type_s16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1035 | #define side_field_s32_be(_name, _attr...) _side_field(_name, side_type_s32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1036 | #define side_field_s64_be(_name, _attr...) _side_field(_name, side_type_s64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1037 | #define side_field_pointer_be(_name, _attr...) _side_field(_name, side_type_pointer_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1038 | #define side_field_float_binary16_be(_name, _attr...) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1039 | #define side_field_float_binary32_be(_name, _attr...) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1040 | #define side_field_float_binary64_be(_name, _attr...) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1041 | #define side_field_float_binary128_be(_name, _attr...) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1042 | #define side_field_string16_be(_name, _attr...) _side_field(_name, side_type_string16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1043 | #define side_field_string32_be(_name, _attr...) _side_field(_name, side_type_string32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a MD |
1044 | |
1045 | #define side_type_enum(_mappings, _elem_type) \ | |
1046 | { \ | |
3ce69bfa | 1047 | .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM), \ |
67337c4a MD |
1048 | .u = { \ |
1049 | .side_enum = { \ | |
64037418 | 1050 | .mappings = SIDE_PTR_INIT(_mappings), \ |
c5789285 | 1051 | .elem_type = SIDE_PTR_INIT(_elem_type), \ |
67337c4a MD |
1052 | }, \ |
1053 | }, \ | |
1054 | } | |
1055 | #define side_field_enum(_name, _mappings, _elem_type) \ | |
1056 | _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) | |
1057 | ||
1058 | #define side_type_enum_bitmap(_mappings, _elem_type) \ | |
1059 | { \ | |
3ce69bfa | 1060 | .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM_BITMAP), \ |
67337c4a MD |
1061 | .u = { \ |
1062 | .side_enum_bitmap = { \ | |
64037418 | 1063 | .mappings = SIDE_PTR_INIT(_mappings), \ |
c5789285 | 1064 | .elem_type = SIDE_PTR_INIT(_elem_type), \ |
67337c4a MD |
1065 | }, \ |
1066 | }, \ | |
1067 | } | |
1068 | #define side_field_enum_bitmap(_name, _mappings, _elem_type) \ | |
1069 | _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) | |
1070 | ||
1071 | #define side_type_struct(_struct) \ | |
1072 | { \ | |
3ce69bfa | 1073 | .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), \ |
67337c4a | 1074 | .u = { \ |
c5789285 | 1075 | .side_struct = SIDE_PTR_INIT(_struct), \ |
67337c4a MD |
1076 | }, \ |
1077 | } | |
1078 | #define side_field_struct(_name, _struct) \ | |
1079 | _side_field(_name, side_type_struct(SIDE_PARAM(_struct))) | |
1080 | ||
1081 | #define _side_type_struct_define(_fields, _attr) \ | |
1082 | { \ | |
c5789285 | 1083 | .fields = SIDE_PTR_INIT(_fields), \ |
12d787db | 1084 | .attr = SIDE_PTR_INIT(_attr), \ |
67337c4a MD |
1085 | .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ |
1086 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
1087 | } | |
1088 | ||
d5a4e361 MD |
1089 | #define side_define_struct(_identifier, _fields, _attr...) \ |
1090 | const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
67337c4a | 1091 | |
d5a4e361 | 1092 | #define side_struct_literal(_fields, _attr...) \ |
67337c4a | 1093 | SIDE_COMPOUND_LITERAL(const struct side_type_struct, \ |
d5a4e361 | 1094 | _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) |
67337c4a | 1095 | |
5530345d MD |
1096 | #define side_type_variant(_variant) \ |
1097 | { \ | |
3ce69bfa | 1098 | .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \ |
5530345d | 1099 | .u = { \ |
c5789285 | 1100 | .side_variant = SIDE_PTR_INIT(_variant), \ |
5530345d MD |
1101 | }, \ |
1102 | } | |
1103 | #define side_field_variant(_name, _variant) \ | |
1104 | _side_field(_name, side_type_variant(SIDE_PARAM(_variant))) | |
1105 | ||
1106 | #define _side_type_variant_define(_selector, _options, _attr) \ | |
1107 | { \ | |
1108 | .selector = _selector, \ | |
c5789285 | 1109 | .options = SIDE_PTR_INIT(_options), \ |
12d787db | 1110 | .attr = SIDE_PTR_INIT(_attr), \ |
5530345d MD |
1111 | .nr_options = SIDE_ARRAY_SIZE(SIDE_PARAM(_options)), \ |
1112 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ | |
1113 | } | |
1114 | ||
d5a4e361 | 1115 | #define side_define_variant(_identifier, _selector, _options, _attr...) \ |
5530345d | 1116 | const struct side_type_variant _identifier = \ |
d5a4e361 | 1117 | _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
5530345d | 1118 | |
d5a4e361 | 1119 | #define side_variant_literal(_selector, _options, _attr...) \ |
5530345d | 1120 | SIDE_COMPOUND_LITERAL(const struct side_type_variant, \ |
d5a4e361 | 1121 | _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) |
5530345d | 1122 | |
d5a4e361 | 1123 | #define side_type_array(_elem_type, _length, _attr...) \ |
67337c4a | 1124 | { \ |
3ce69bfa | 1125 | .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), \ |
67337c4a MD |
1126 | .u = { \ |
1127 | .side_array = { \ | |
c5789285 | 1128 | .elem_type = SIDE_PTR_INIT(_elem_type), \ |
12d787db | 1129 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1130 | .length = _length, \ |
d5a4e361 | 1131 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1132 | }, \ |
1133 | }, \ | |
1134 | } | |
d5a4e361 MD |
1135 | #define side_field_array(_name, _elem_type, _length, _attr...) \ |
1136 | _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1137 | |
d5a4e361 | 1138 | #define side_type_vla(_elem_type, _attr...) \ |
67337c4a | 1139 | { \ |
3ce69bfa | 1140 | .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), \ |
67337c4a MD |
1141 | .u = { \ |
1142 | .side_vla = { \ | |
c5789285 | 1143 | .elem_type = SIDE_PTR_INIT(_elem_type), \ |
12d787db | 1144 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1145 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1146 | }, \ |
1147 | }, \ | |
1148 | } | |
d5a4e361 MD |
1149 | #define side_field_vla(_name, _elem_type, _attr...) \ |
1150 | _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1151 | |
d5a4e361 | 1152 | #define side_type_vla_visitor(_elem_type, _visitor, _attr...) \ |
67337c4a | 1153 | { \ |
3ce69bfa | 1154 | .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), \ |
67337c4a MD |
1155 | .u = { \ |
1156 | .side_vla_visitor = { \ | |
c5789285 | 1157 | .elem_type = SIDE_PTR_INIT(_elem_type), \ |
2e197497 | 1158 | .visitor = SIDE_PTR_INIT(_visitor), \ |
12d787db | 1159 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1160 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1161 | }, \ |
1162 | }, \ | |
1163 | } | |
d5a4e361 MD |
1164 | #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr...) \ |
1165 | _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a MD |
1166 | |
1167 | /* Gather field and type definitions */ | |
1168 | ||
d5a4e361 | 1169 | #define side_type_gather_byte(_offset, _access_mode, _attr...) \ |
67337c4a | 1170 | { \ |
3ce69bfa | 1171 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), \ |
67337c4a MD |
1172 | .u = { \ |
1173 | .side_gather = { \ | |
1174 | .u = { \ | |
1175 | .side_byte = { \ | |
1176 | .offset = _offset, \ | |
1177 | .access_mode = _access_mode, \ | |
1178 | .type = { \ | |
12d787db | 1179 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1180 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1181 | }, \ |
1182 | }, \ | |
1183 | }, \ | |
1184 | }, \ | |
1185 | }, \ | |
1186 | } | |
d5a4e361 MD |
1187 | #define side_field_gather_byte(_name, _offset, _access_mode, _attr...) \ |
1188 | _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1189 | |
d5a4e361 | 1190 | #define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
67337c4a | 1191 | { \ |
3ce69bfa | 1192 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), \ |
67337c4a MD |
1193 | .u = { \ |
1194 | .side_gather = { \ | |
1195 | .u = { \ | |
1196 | .side_bool = { \ | |
1197 | .offset = _offset, \ | |
1198 | .access_mode = _access_mode, \ | |
1199 | .type = { \ | |
db8df9b5 | 1200 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1201 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1202 | .bool_size = _bool_size, \ |
1203 | .len_bits = _len_bits, \ | |
3bc9ba43 | 1204 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
1205 | }, \ |
1206 | .offset_bits = _offset_bits, \ | |
1207 | }, \ | |
1208 | }, \ | |
1209 | }, \ | |
1210 | }, \ | |
1211 | } | |
d5a4e361 MD |
1212 | #define side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
1213 | _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_HOST, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1214 | #define side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
1215 | _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_LE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1216 | #define side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
1217 | _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_BE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1218 | ||
1219 | #define side_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
1220 | _side_field(_name, side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) | |
1221 | #define side_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
1222 | _side_field(_name, side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) | |
1223 | #define side_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
1224 | _side_field(_name, side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) | |
67337c4a MD |
1225 | |
1226 | #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \ | |
d5a4e361 | 1227 | _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
67337c4a | 1228 | { \ |
3ce69bfa | 1229 | .type = SIDE_ENUM_INIT(_type), \ |
67337c4a MD |
1230 | .u = { \ |
1231 | .side_gather = { \ | |
1232 | .u = { \ | |
1233 | .side_integer = { \ | |
1234 | .offset = _offset, \ | |
1235 | .access_mode = _access_mode, \ | |
1236 | .type = { \ | |
12d787db | 1237 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1238 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1239 | .integer_size = _integer_size, \ |
1240 | .len_bits = _len_bits, \ | |
1241 | .signedness = _signedness, \ | |
3bc9ba43 | 1242 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
1243 | }, \ |
1244 | .offset_bits = _offset_bits, \ | |
1245 | }, \ | |
1246 | }, \ | |
1247 | }, \ | |
1248 | }, \ | |
1249 | } | |
1250 | ||
d5a4e361 | 1251 | #define side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
67337c4a | 1252 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, \ |
d5a4e361 MD |
1253 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1254 | #define side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
67337c4a | 1255 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, \ |
d5a4e361 | 1256 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1257 | |
d5a4e361 | 1258 | #define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
67337c4a | 1259 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_LE, \ |
d5a4e361 MD |
1260 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1261 | #define side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
67337c4a | 1262 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_LE, \ |
d5a4e361 | 1263 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1264 | |
d5a4e361 | 1265 | #define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
67337c4a | 1266 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_BE, \ |
d5a4e361 MD |
1267 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1268 | #define side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
67337c4a | 1269 | _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_BE, \ |
d5a4e361 | 1270 | _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1271 | |
d5a4e361 MD |
1272 | #define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
1273 | _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1274 | #define side_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
1275 | _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1276 | |
d5a4e361 MD |
1277 | #define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
1278 | _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1279 | #define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
1280 | _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1281 | |
d5a4e361 MD |
1282 | #define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ |
1283 | _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1284 | #define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ | |
1285 | _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1286 | |
d5a4e361 | 1287 | #define side_type_gather_pointer(_offset, _access_mode, _attr...) \ |
67337c4a | 1288 | _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, \ |
d5a4e361 MD |
1289 | _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1290 | #define side_field_gather_pointer(_name, _offset, _access_mode, _attr...) \ | |
1291 | _side_field(_name, side_type_gather_pointer(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1292 | |
d5a4e361 | 1293 | #define side_type_gather_pointer_le(_offset, _access_mode, _attr...) \ |
67337c4a | 1294 | _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, \ |
d5a4e361 MD |
1295 | _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1296 | #define side_field_gather_pointer_le(_name, _offset, _access_mode, _attr...) \ | |
1297 | _side_field(_name, side_type_gather_pointer_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1298 | |
d5a4e361 | 1299 | #define side_type_gather_pointer_be(_offset, _access_mode, _attr...) \ |
67337c4a | 1300 | _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, \ |
d5a4e361 MD |
1301 | _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1302 | #define side_field_gather_pointer_be(_name, _offset, _access_mode, _attr...) \ | |
1303 | _side_field(_name, side_type_gather_pointer_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1304 | |
d5a4e361 | 1305 | #define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr...) \ |
67337c4a | 1306 | { \ |
3ce69bfa | 1307 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), \ |
67337c4a MD |
1308 | .u = { \ |
1309 | .side_gather = { \ | |
1310 | .u = { \ | |
1311 | .side_float = { \ | |
1312 | .offset = _offset, \ | |
1313 | .access_mode = _access_mode, \ | |
1314 | .type = { \ | |
12d787db | 1315 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1316 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1317 | .float_size = _float_size, \ |
3bc9ba43 | 1318 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
1319 | }, \ |
1320 | }, \ | |
1321 | }, \ | |
1322 | }, \ | |
1323 | }, \ | |
1324 | } | |
1325 | ||
d5a4e361 MD |
1326 | #define side_type_gather_float(_offset, _float_size, _access_mode, _attr...) \ |
1327 | _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1328 | #define side_type_gather_float_le(_offset, _float_size, _access_mode, _attr...) \ | |
1329 | _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1330 | #define side_type_gather_float_be(_offset, _float_size, _access_mode, _attr...) \ | |
1331 | _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1332 | ||
1333 | #define side_field_gather_float(_name, _offset, _float_size, _access_mode, _attr...) \ | |
1334 | _side_field(_name, side_type_gather_float(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1335 | #define side_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr...) \ | |
1336 | _side_field(_name, side_type_gather_float_le(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1337 | #define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr...) \ | |
1338 | _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1339 | ||
1340 | #define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr...) \ | |
67337c4a | 1341 | { \ |
3ce69bfa | 1342 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), \ |
67337c4a MD |
1343 | .u = { \ |
1344 | .side_gather = { \ | |
1345 | .u = { \ | |
1346 | .side_string = { \ | |
1347 | .offset = _offset, \ | |
1348 | .access_mode = _access_mode, \ | |
1349 | .type = { \ | |
12d787db | 1350 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1351 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1352 | .unit_size = _unit_size, \ |
3bc9ba43 | 1353 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
1354 | }, \ |
1355 | }, \ | |
1356 | }, \ | |
1357 | }, \ | |
1358 | }, \ | |
1359 | } | |
d5a4e361 MD |
1360 | #define side_type_gather_string(_offset, _access_mode, _attr...) \ |
1361 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1362 | #define side_field_gather_string(_name, _offset, _access_mode, _attr...) \ | |
1363 | _side_field(_name, side_type_gather_string(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1364 | ||
1365 | #define side_type_gather_string16(_offset, _access_mode, _attr...) \ | |
1366 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1367 | #define side_type_gather_string16_le(_offset, _access_mode, _attr...) \ | |
1368 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1369 | #define side_type_gather_string16_be(_offset, _access_mode, _attr...) \ | |
1370 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1371 | ||
1372 | #define side_field_gather_string16(_name, _offset, _access_mode, _attr...) \ | |
1373 | _side_field(_name, side_type_gather_string16(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1374 | #define side_field_gather_string16_le(_name, _offset, _access_mode, _attr...) \ | |
1375 | _side_field(_name, side_type_gather_string16_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1376 | #define side_field_gather_string16_be(_name, _offset, _access_mode, _attr...) \ | |
1377 | _side_field(_name, side_type_gather_string16_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1378 | ||
1379 | #define side_type_gather_string32(_offset, _access_mode, _attr...) \ | |
1380 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1381 | #define side_type_gather_string32_le(_offset, _access_mode, _attr...) \ | |
1382 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1383 | #define side_type_gather_string32_be(_offset, _access_mode, _attr...) \ | |
1384 | _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1385 | ||
1386 | #define side_field_gather_string32(_name, _offset, _access_mode, _attr...) \ | |
1387 | _side_field(_name, side_type_gather_string32(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1388 | #define side_field_gather_string32_le(_name, _offset, _access_mode, _attr...) \ | |
1389 | _side_field(_name, side_type_gather_string32_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
1390 | #define side_field_gather_string32_be(_name, _offset, _access_mode, _attr...) \ | |
1391 | _side_field(_name, side_type_gather_string32_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a MD |
1392 | |
1393 | #define side_type_gather_enum(_mappings, _elem_type) \ | |
1394 | { \ | |
3ce69bfa | 1395 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ENUM), \ |
67337c4a MD |
1396 | .u = { \ |
1397 | .side_enum = { \ | |
64037418 | 1398 | .mappings = SIDE_PTR_INIT(_mappings), \ |
c5789285 | 1399 | .elem_type = SIDE_PTR_INIT(_elem_type), \ |
67337c4a MD |
1400 | }, \ |
1401 | }, \ | |
1402 | } | |
1403 | #define side_field_gather_enum(_name, _mappings, _elem_type) \ | |
1404 | _side_field(_name, side_type_gather_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) | |
1405 | ||
1406 | #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \ | |
1407 | { \ | |
3ce69bfa | 1408 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), \ |
67337c4a MD |
1409 | .u = { \ |
1410 | .side_gather = { \ | |
1411 | .u = { \ | |
1412 | .side_struct = { \ | |
1413 | .offset = _offset, \ | |
1414 | .access_mode = _access_mode, \ | |
c5789285 | 1415 | .type = SIDE_PTR_INIT(_struct_gather), \ |
67337c4a MD |
1416 | .size = _size, \ |
1417 | }, \ | |
1418 | }, \ | |
1419 | }, \ | |
1420 | }, \ | |
1421 | } | |
1422 | #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \ | |
1423 | _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode)) | |
1424 | ||
d5a4e361 | 1425 | #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr...) \ |
67337c4a | 1426 | { \ |
3ce69bfa | 1427 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), \ |
67337c4a MD |
1428 | .u = { \ |
1429 | .side_gather = { \ | |
1430 | .u = { \ | |
1431 | .side_array = { \ | |
1432 | .offset = _offset, \ | |
1433 | .access_mode = _access_mode, \ | |
1434 | .type = { \ | |
c5789285 | 1435 | .elem_type = SIDE_PTR_INIT(_elem_type_gather), \ |
12d787db | 1436 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1437 | .length = _length, \ |
d5a4e361 | 1438 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1439 | }, \ |
1440 | }, \ | |
1441 | }, \ | |
1442 | }, \ | |
1443 | }, \ | |
1444 | } | |
d5a4e361 MD |
1445 | #define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr...) \ |
1446 | _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a | 1447 | |
d5a4e361 | 1448 | #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \ |
67337c4a | 1449 | { \ |
3ce69bfa | 1450 | .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), \ |
67337c4a MD |
1451 | .u = { \ |
1452 | .side_gather = { \ | |
1453 | .u = { \ | |
1454 | .side_vla = { \ | |
c5789285 | 1455 | .length_type = SIDE_PTR_INIT(_length_type_gather), \ |
67337c4a MD |
1456 | .offset = _offset, \ |
1457 | .access_mode = _access_mode, \ | |
1458 | .type = { \ | |
c5789285 | 1459 | .elem_type = SIDE_PTR_INIT(_elem_type_gather), \ |
12d787db | 1460 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1461 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1462 | }, \ |
1463 | }, \ | |
1464 | }, \ | |
1465 | }, \ | |
1466 | }, \ | |
1467 | } | |
d5a4e361 MD |
1468 | #define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \ |
1469 | _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) | |
67337c4a MD |
1470 | |
1471 | #define side_elem(...) \ | |
1472 | SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__) | |
1473 | ||
1474 | #define side_length(...) \ | |
1475 | SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__) | |
1476 | ||
1477 | #define side_field_list(...) \ | |
1478 | SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__) | |
1479 | ||
5530345d MD |
1480 | #define side_option_list(...) \ |
1481 | SIDE_COMPOUND_LITERAL(const struct side_variant_option, __VA_ARGS__) | |
1482 | ||
67337c4a MD |
1483 | /* Stack-copy field arguments */ |
1484 | ||
3ce69bfa MD |
1485 | #define side_arg_null(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL) } |
1486 | #define side_arg_bool(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } } | |
1487 | #define side_arg_byte(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), .u = { .side_static = { .byte_value = (_val) } } } | |
1488 | #define side_arg_string(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF8), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } } | |
1489 | #define side_arg_string16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF16), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } } | |
1490 | #define side_arg_string32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF32), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } } | |
1491 | ||
1492 | #define side_arg_u8(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U8), .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } } | |
1493 | #define side_arg_u16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U16), .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } } | |
1494 | #define side_arg_u32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U32), .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } } | |
1495 | #define side_arg_u64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U64), .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } } | |
1496 | #define side_arg_s8(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S8), .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } } | |
1497 | #define side_arg_s16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S16), .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } } | |
1498 | #define side_arg_s32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S32), .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } } | |
1499 | #define side_arg_s64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S64), .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } } | |
1500 | #define side_arg_pointer(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_POINTER), .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } } | |
1501 | #define side_arg_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY16), .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } } | |
1502 | #define side_arg_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY32), .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } } | |
1503 | #define side_arg_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY64), .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } } | |
1504 | #define side_arg_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY128), .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } } | |
1505 | ||
1506 | #define side_arg_struct(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), .u = { .side_static = { .side_struct = SIDE_PTR_INIT(_side_type) } } } | |
5530345d MD |
1507 | |
1508 | #define side_arg_define_variant(_identifier, _selector_val, _option) \ | |
1509 | const struct side_arg_variant _identifier = { \ | |
1510 | .selector = _selector_val, \ | |
1511 | .option = _option, \ | |
1512 | } | |
1513 | #define side_arg_variant(_side_variant) \ | |
1514 | { \ | |
3ce69bfa | 1515 | .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \ |
5530345d MD |
1516 | .u = { \ |
1517 | .side_static = { \ | |
bac71609 | 1518 | .side_variant = SIDE_PTR_INIT(_side_variant), \ |
5530345d MD |
1519 | }, \ |
1520 | }, \ | |
1521 | } | |
1522 | ||
3ce69bfa MD |
1523 | #define side_arg_array(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), .u = { .side_static = { .side_array = SIDE_PTR_INIT(_side_type) } } } |
1524 | #define side_arg_vla(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), .u = { .side_static = { .side_vla = SIDE_PTR_INIT(_side_type) } } } | |
1525 | #define side_arg_vla_visitor(_ctx) { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } } | |
67337c4a MD |
1526 | |
1527 | /* Gather field arguments */ | |
1528 | ||
3ce69bfa MD |
1529 | #define side_arg_gather_bool(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), .u = { .side_static = { .side_bool_gather_ptr = SIDE_PTR_INIT(_ptr) } } } |
1530 | #define side_arg_gather_byte(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), .u = { .side_static = { .side_byte_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
1531 | #define side_arg_gather_pointer(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_POINTER), .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
1532 | #define side_arg_gather_integer(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_INTEGER), .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
1533 | #define side_arg_gather_float(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), .u = { .side_static = { .side_float_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
1534 | #define side_arg_gather_string(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), .u = { .side_static = { .side_string_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
1535 | #define side_arg_gather_struct(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), .u = { .side_static = { .side_struct_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
1536 | #define side_arg_gather_array(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), .u = { .side_static = { .side_array_gather_ptr = SIDE_PTR_INIT(_ptr) } } } | |
1537 | #define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), .u = { .side_static = { .side_vla_gather = { .ptr = SIDE_PTR_INIT(_ptr), .length_ptr = SIDE_PTR_INIT(_length_ptr) } } } } | |
67337c4a MD |
1538 | |
1539 | /* Dynamic field arguments */ | |
1540 | ||
d5a4e361 | 1541 | #define side_arg_dynamic_null(_attr...) \ |
67337c4a | 1542 | { \ |
3ce69bfa | 1543 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_NULL), \ |
67337c4a MD |
1544 | .u = { \ |
1545 | .side_dynamic = { \ | |
1546 | .side_null = { \ | |
b313067b | 1547 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1548 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1549 | }, \ |
1550 | }, \ | |
1551 | }, \ | |
1552 | } | |
1553 | ||
d5a4e361 | 1554 | #define side_arg_dynamic_bool(_val, _attr...) \ |
67337c4a | 1555 | { \ |
3ce69bfa | 1556 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BOOL), \ |
67337c4a MD |
1557 | .u = { \ |
1558 | .side_dynamic = { \ | |
1559 | .side_bool = { \ | |
1560 | .type = { \ | |
db8df9b5 | 1561 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1562 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1563 | .bool_size = sizeof(uint8_t), \ |
1564 | .len_bits = 0, \ | |
3bc9ba43 | 1565 | .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \ |
67337c4a MD |
1566 | }, \ |
1567 | .value = { \ | |
1568 | .side_bool8 = !!(_val), \ | |
1569 | }, \ | |
1570 | }, \ | |
1571 | }, \ | |
1572 | }, \ | |
1573 | } | |
1574 | ||
d5a4e361 | 1575 | #define side_arg_dynamic_byte(_val, _attr...) \ |
67337c4a | 1576 | { \ |
3ce69bfa | 1577 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BYTE), \ |
67337c4a MD |
1578 | .u = { \ |
1579 | .side_dynamic = { \ | |
1580 | .side_byte = { \ | |
1581 | .type = { \ | |
12d787db | 1582 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1583 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1584 | }, \ |
1585 | .value = (_val), \ | |
1586 | }, \ | |
1587 | }, \ | |
1588 | }, \ | |
1589 | } | |
d5a4e361 MD |
1590 | |
1591 | #define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr...) \ | |
67337c4a | 1592 | { \ |
3ce69bfa | 1593 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRING), \ |
67337c4a MD |
1594 | .u = { \ |
1595 | .side_dynamic = { \ | |
1596 | .side_string = { \ | |
1597 | .type = { \ | |
12d787db | 1598 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1599 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1600 | .unit_size = _unit_size, \ |
3bc9ba43 | 1601 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
1602 | }, \ |
1603 | .value = (uintptr_t) (_val), \ | |
1604 | }, \ | |
1605 | }, \ | |
1606 | }, \ | |
1607 | } | |
d5a4e361 MD |
1608 | #define side_arg_dynamic_string(_val, _attr...) \ |
1609 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1610 | #define side_arg_dynamic_string16(_val, _attr...) \ | |
1611 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1612 | #define side_arg_dynamic_string16_le(_val, _attr...) \ | |
1613 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1614 | #define side_arg_dynamic_string16_be(_val, _attr...) \ | |
1615 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1616 | #define side_arg_dynamic_string32(_val, _attr...) \ | |
1617 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1618 | #define side_arg_dynamic_string32_le(_val, _attr...) \ | |
1619 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1620 | #define side_arg_dynamic_string32_be(_val, _attr...) \ | |
1621 | _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1622 | ||
1623 | #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr...) \ | |
67337c4a | 1624 | { \ |
3ce69bfa | 1625 | .type = SIDE_ENUM_INIT(_type), \ |
67337c4a MD |
1626 | .u = { \ |
1627 | .side_dynamic = { \ | |
1628 | .side_integer = { \ | |
1629 | .type = { \ | |
12d787db | 1630 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1631 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1632 | .integer_size = _integer_size, \ |
1633 | .len_bits = _len_bits, \ | |
1634 | .signedness = _signedness, \ | |
3bc9ba43 | 1635 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
1636 | }, \ |
1637 | .value = { \ | |
1638 | _field = (_val), \ | |
1639 | }, \ | |
1640 | }, \ | |
1641 | }, \ | |
1642 | }, \ | |
1643 | } | |
1644 | ||
d5a4e361 MD |
1645 | #define side_arg_dynamic_u8(_val, _attr...) \ |
1646 | _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1647 | #define side_arg_dynamic_s8(_val, _attr...) \ | |
1648 | _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1649 | ||
1650 | #define _side_arg_dynamic_u16(_val, _byte_order, _attr...) \ | |
1651 | _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1652 | #define _side_arg_dynamic_u32(_val, _byte_order, _attr...) \ | |
1653 | _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1654 | #define _side_arg_dynamic_u64(_val, _byte_order, _attr...) \ | |
1655 | _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1656 | ||
1657 | #define _side_arg_dynamic_s16(_val, _byte_order, _attr...) \ | |
1658 | _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1659 | #define _side_arg_dynamic_s32(_val, _byte_order, _attr...) \ | |
1660 | _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1661 | #define _side_arg_dynamic_s64(_val, _byte_order, _attr...) \ | |
1662 | _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1663 | ||
1664 | #define _side_arg_dynamic_pointer(_val, _byte_order, _attr...) \ | |
67337c4a | 1665 | _side_arg_dynamic_integer(.side_uptr, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER, false, _byte_order, \ |
d5a4e361 | 1666 | sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1667 | |
d5a4e361 | 1668 | #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr...) \ |
67337c4a | 1669 | { \ |
3ce69bfa | 1670 | .type = SIDE_ENUM_INIT(_type), \ |
67337c4a MD |
1671 | .u = { \ |
1672 | .side_dynamic = { \ | |
1673 | .side_float = { \ | |
1674 | .type = { \ | |
12d787db | 1675 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1676 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1677 | .float_size = _float_size, \ |
3bc9ba43 | 1678 | .byte_order = SIDE_ENUM_INIT(_byte_order), \ |
67337c4a MD |
1679 | }, \ |
1680 | .value = { \ | |
1681 | _field = (_val), \ | |
1682 | }, \ | |
1683 | }, \ | |
1684 | }, \ | |
1685 | }, \ | |
1686 | } | |
1687 | ||
d5a4e361 MD |
1688 | #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr...) \ |
1689 | _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1690 | #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr...) \ | |
1691 | _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1692 | #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr...) \ | |
1693 | _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1694 | #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr...) \ | |
1695 | _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
67337c4a MD |
1696 | |
1697 | /* Host endian */ | |
d5a4e361 MD |
1698 | #define side_arg_dynamic_u16(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1699 | #define side_arg_dynamic_u32(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1700 | #define side_arg_dynamic_u64(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1701 | #define side_arg_dynamic_s16(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1702 | #define side_arg_dynamic_s32(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1703 | #define side_arg_dynamic_s64(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1704 | #define side_arg_dynamic_pointer(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1705 | #define side_arg_dynamic_float_binary16(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1706 | #define side_arg_dynamic_float_binary32(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1707 | #define side_arg_dynamic_float_binary64(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1708 | #define side_arg_dynamic_float_binary128(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
67337c4a MD |
1709 | |
1710 | /* Little endian */ | |
d5a4e361 MD |
1711 | #define side_arg_dynamic_u16_le(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1712 | #define side_arg_dynamic_u32_le(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1713 | #define side_arg_dynamic_u64_le(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1714 | #define side_arg_dynamic_s16_le(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1715 | #define side_arg_dynamic_s32_le(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1716 | #define side_arg_dynamic_s64_le(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1717 | #define side_arg_dynamic_pointer_le(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1718 | #define side_arg_dynamic_float_binary16_le(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1719 | #define side_arg_dynamic_float_binary32_le(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1720 | #define side_arg_dynamic_float_binary64_le(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1721 | #define side_arg_dynamic_float_binary128_le(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
67337c4a MD |
1722 | |
1723 | /* Big endian */ | |
d5a4e361 MD |
1724 | #define side_arg_dynamic_u16_be(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
1725 | #define side_arg_dynamic_u32_be(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1726 | #define side_arg_dynamic_u64_be(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1727 | #define side_arg_dynamic_s16_be(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1728 | #define side_arg_dynamic_s32_be(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1729 | #define side_arg_dynamic_s64_be(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1730 | #define side_arg_dynamic_pointer_be(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1731 | #define side_arg_dynamic_float_binary16_be(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1732 | #define side_arg_dynamic_float_binary32_be(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1733 | #define side_arg_dynamic_float_binary64_be(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
1734 | #define side_arg_dynamic_float_binary128_be(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) | |
67337c4a MD |
1735 | |
1736 | #define side_arg_dynamic_vla(_vla) \ | |
1737 | { \ | |
3ce69bfa | 1738 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA), \ |
67337c4a MD |
1739 | .u = { \ |
1740 | .side_dynamic = { \ | |
f13253cb | 1741 | .side_dynamic_vla = SIDE_PTR_INIT(_vla), \ |
67337c4a MD |
1742 | }, \ |
1743 | }, \ | |
1744 | } | |
1745 | ||
d5a4e361 | 1746 | #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr...) \ |
67337c4a | 1747 | { \ |
3ce69bfa | 1748 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA_VISITOR), \ |
67337c4a MD |
1749 | .u = { \ |
1750 | .side_dynamic = { \ | |
1751 | .side_dynamic_vla_visitor = { \ | |
2e197497 MD |
1752 | .app_ctx = SIDE_PTR_INIT(_ctx), \ |
1753 | .visitor = SIDE_PTR_INIT(_dynamic_vla_visitor), \ | |
12d787db | 1754 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1755 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1756 | }, \ |
1757 | }, \ | |
1758 | }, \ | |
1759 | } | |
1760 | ||
1761 | #define side_arg_dynamic_struct(_struct) \ | |
1762 | { \ | |
3ce69bfa | 1763 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT), \ |
67337c4a MD |
1764 | .u = { \ |
1765 | .side_dynamic = { \ | |
f13253cb | 1766 | .side_dynamic_struct = SIDE_PTR_INIT(_struct), \ |
67337c4a MD |
1767 | }, \ |
1768 | }, \ | |
1769 | } | |
1770 | ||
d5a4e361 | 1771 | #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr...) \ |
67337c4a | 1772 | { \ |
3ce69bfa | 1773 | .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT_VISITOR), \ |
67337c4a MD |
1774 | .u = { \ |
1775 | .side_dynamic = { \ | |
1776 | .side_dynamic_struct_visitor = { \ | |
2e197497 MD |
1777 | .app_ctx = SIDE_PTR_INIT(_ctx), \ |
1778 | .visitor = SIDE_PTR_INIT(_dynamic_struct_visitor), \ | |
12d787db | 1779 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
d5a4e361 | 1780 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1781 | }, \ |
1782 | }, \ | |
1783 | }, \ | |
1784 | } | |
1785 | ||
d5a4e361 | 1786 | #define side_arg_dynamic_define_vec(_identifier, _sav, _attr...) \ |
67337c4a MD |
1787 | const struct side_arg _identifier##_vec[] = { _sav }; \ |
1788 | const struct side_arg_dynamic_vla _identifier = { \ | |
f13253cb | 1789 | .sav = SIDE_PTR_INIT(_identifier##_vec), \ |
12d787db | 1790 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1791 | .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ |
d5a4e361 | 1792 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1793 | } |
1794 | ||
d5a4e361 | 1795 | #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr...) \ |
67337c4a MD |
1796 | const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \ |
1797 | const struct side_arg_dynamic_struct _identifier = { \ | |
f13253cb | 1798 | .fields = SIDE_PTR_INIT(_identifier##_fields), \ |
12d787db | 1799 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1800 | .len = SIDE_ARRAY_SIZE(_identifier##_fields), \ |
d5a4e361 | 1801 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1802 | } |
1803 | ||
1804 | #define side_arg_define_vec(_identifier, _sav) \ | |
1805 | const struct side_arg _identifier##_vec[] = { _sav }; \ | |
1806 | const struct side_arg_vec _identifier = { \ | |
f13253cb | 1807 | .sav = SIDE_PTR_INIT(_identifier##_vec), \ |
67337c4a MD |
1808 | .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ |
1809 | } | |
1810 | ||
1811 | #define side_arg_dynamic_field(_name, _elem) \ | |
1812 | { \ | |
f13253cb | 1813 | .field_name = SIDE_PTR_INIT(_name), \ |
67337c4a MD |
1814 | .elem = _elem, \ |
1815 | } | |
1816 | ||
1817 | /* | |
1818 | * Event instrumentation description registration, runtime enabled state | |
1819 | * check, and instrumentation invocation. | |
1820 | */ | |
1821 | ||
1822 | #define side_arg_list(...) __VA_ARGS__ | |
1823 | ||
1824 | #define side_event_cond(_identifier) \ | |
6c12af2c | 1825 | if (side_unlikely(__atomic_load_n(&side_event_state__##_identifier.enabled, \ |
67337c4a MD |
1826 | __ATOMIC_RELAXED))) |
1827 | ||
1828 | #define side_event_call(_identifier, _sav) \ | |
1829 | { \ | |
1830 | const struct side_arg side_sav[] = { _sav }; \ | |
1831 | const struct side_arg_vec side_arg_vec = { \ | |
f13253cb | 1832 | .sav = SIDE_PTR_INIT(side_sav), \ |
67337c4a MD |
1833 | .len = SIDE_ARRAY_SIZE(side_sav), \ |
1834 | }; \ | |
0d747f98 | 1835 | side_call(&(side_event_state__##_identifier), &side_arg_vec); \ |
67337c4a MD |
1836 | } |
1837 | ||
1838 | #define side_event(_identifier, _sav) \ | |
1839 | side_event_cond(_identifier) \ | |
1840 | side_event_call(_identifier, SIDE_PARAM(_sav)) | |
1841 | ||
d5a4e361 | 1842 | #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr...) \ |
67337c4a MD |
1843 | { \ |
1844 | const struct side_arg side_sav[] = { _sav }; \ | |
1845 | const struct side_arg_vec side_arg_vec = { \ | |
f13253cb | 1846 | .sav = SIDE_PTR_INIT(side_sav), \ |
67337c4a MD |
1847 | .len = SIDE_ARRAY_SIZE(side_sav), \ |
1848 | }; \ | |
1849 | const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \ | |
1850 | const struct side_arg_dynamic_struct var_struct = { \ | |
f13253cb | 1851 | .fields = SIDE_PTR_INIT(side_fields), \ |
12d787db | 1852 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1853 | .len = SIDE_ARRAY_SIZE(side_fields), \ |
d5a4e361 | 1854 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a | 1855 | }; \ |
0d747f98 | 1856 | side_call_variadic(&(side_event_state__##_identifier), &side_arg_vec, &var_struct); \ |
67337c4a MD |
1857 | } |
1858 | ||
d5a4e361 | 1859 | #define side_event_variadic(_identifier, _sav, _var, _attr...) \ |
67337c4a | 1860 | side_event_cond(_identifier) \ |
d5a4e361 | 1861 | side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1862 | |
d5a4e361 | 1863 | #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _flags, _attr...) \ |
0d747f98 MD |
1864 | _linkage struct side_event_description __attribute__((section("side_event_description"))) \ |
1865 | _identifier; \ | |
6c12af2c MD |
1866 | _linkage struct side_event_state __attribute__((section("side_event_state"))) \ |
1867 | side_event_state__##_identifier = { \ | |
1868 | .enabled = 0, \ | |
1869 | .callbacks = &side_empty_callback, \ | |
39fe9c03 | 1870 | .desc = &(_identifier), \ |
6c12af2c | 1871 | }; \ |
67337c4a MD |
1872 | _linkage struct side_event_description __attribute__((section("side_event_description"))) \ |
1873 | _identifier = { \ | |
0b9e59d6 MD |
1874 | .state = SIDE_PTR_INIT(&(side_event_state__##_identifier)), \ |
1875 | .provider_name = SIDE_PTR_INIT(_provider), \ | |
1876 | .event_name = SIDE_PTR_INIT(_event), \ | |
1877 | .fields = SIDE_PTR_INIT(_fields), \ | |
12d787db | 1878 | .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
67337c4a MD |
1879 | .flags = (_flags), \ |
1880 | .version = 0, \ | |
1f7aaefb | 1881 | .loglevel = SIDE_ENUM_INIT(_loglevel), \ |
67337c4a | 1882 | .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ |
d5a4e361 | 1883 | .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ |
f8188f94 | 1884 | .nr_callbacks = 0, \ |
67337c4a MD |
1885 | }; \ |
1886 | static const struct side_event_description *side_event_ptr__##_identifier \ | |
1887 | __attribute__((section("side_event_description_ptr"), used)) = &(_identifier); | |
1888 | ||
d5a4e361 | 1889 | #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ |
67337c4a | 1890 | _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ |
d5a4e361 | 1891 | 0, ##_attr) |
67337c4a | 1892 | |
d5a4e361 | 1893 | #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ |
67337c4a | 1894 | _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ |
d5a4e361 | 1895 | SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1896 | |
d5a4e361 | 1897 | #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ |
67337c4a | 1898 | _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \ |
d5a4e361 | 1899 | _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1900 | |
d5a4e361 | 1901 | #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ |
67337c4a | 1902 | _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \ |
d5a4e361 | 1903 | _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1904 | |
d5a4e361 | 1905 | #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ |
67337c4a | 1906 | _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \ |
d5a4e361 | 1907 | _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a | 1908 | |
d5a4e361 | 1909 | #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ |
67337c4a | 1910 | _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \ |
d5a4e361 | 1911 | _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) |
67337c4a MD |
1912 | |
1913 | #define side_declare_event(_identifier) \ | |
6c12af2c | 1914 | extern struct side_event_state side_event_state_##_identifier; \ |
67337c4a MD |
1915 | extern struct side_event_description _identifier |
1916 | ||
1917 | #ifdef __cplusplus | |
1918 | extern "C" { | |
1919 | #endif | |
1920 | ||
2e197497 MD |
1921 | struct side_callback { |
1922 | union { | |
1923 | void (*call)(const struct side_event_description *desc, | |
1924 | const struct side_arg_vec *side_arg_vec, | |
1925 | void *priv); | |
1926 | void (*call_variadic)(const struct side_event_description *desc, | |
1927 | const struct side_arg_vec *side_arg_vec, | |
1928 | const struct side_arg_dynamic_struct *var_struct, | |
1929 | void *priv); | |
1930 | } SIDE_PACKED u; | |
1931 | void *priv; | |
1932 | } SIDE_PACKED; | |
1933 | ||
1934 | /* The visitor pattern is a double-dispatch visitor. */ | |
1935 | struct side_tracer_visitor_ctx { | |
1936 | side_write_elem_func write_elem; | |
1937 | void *priv; /* Private tracer context. */ | |
1938 | } SIDE_PACKED; | |
1939 | ||
1940 | struct side_tracer_dynamic_struct_visitor_ctx { | |
1941 | side_write_field_func write_field; | |
1942 | void *priv; /* Private tracer context. */ | |
1943 | } SIDE_PACKED; | |
1944 | ||
67337c4a MD |
1945 | extern const struct side_callback side_empty_callback; |
1946 | ||
0d747f98 | 1947 | void side_call(const struct side_event_state *state, |
67337c4a | 1948 | const struct side_arg_vec *side_arg_vec); |
0d747f98 | 1949 | void side_call_variadic(const struct side_event_state *state, |
67337c4a MD |
1950 | const struct side_arg_vec *side_arg_vec, |
1951 | const struct side_arg_dynamic_struct *var_struct); | |
1952 | ||
1953 | struct side_events_register_handle *side_events_register(struct side_event_description **events, | |
1954 | uint32_t nr_events); | |
1955 | void side_events_unregister(struct side_events_register_handle *handle); | |
1956 | ||
1957 | /* | |
1958 | * Userspace tracer registration API. This allows userspace tracers to | |
1959 | * register event notification callbacks to be notified of the currently | |
1960 | * registered instrumentation, and to register their callbacks to | |
1961 | * specific events. | |
1962 | */ | |
1963 | typedef void (*side_tracer_callback_func)(const struct side_event_description *desc, | |
1964 | const struct side_arg_vec *side_arg_vec, | |
1965 | void *priv); | |
1966 | typedef void (*side_tracer_callback_variadic_func)(const struct side_event_description *desc, | |
1967 | const struct side_arg_vec *side_arg_vec, | |
1968 | const struct side_arg_dynamic_struct *var_struct, | |
1969 | void *priv); | |
1970 | ||
1971 | int side_tracer_callback_register(struct side_event_description *desc, | |
1972 | side_tracer_callback_func call, | |
1973 | void *priv); | |
1974 | int side_tracer_callback_variadic_register(struct side_event_description *desc, | |
1975 | side_tracer_callback_variadic_func call_variadic, | |
1976 | void *priv); | |
1977 | int side_tracer_callback_unregister(struct side_event_description *desc, | |
1978 | side_tracer_callback_func call, | |
1979 | void *priv); | |
1980 | int side_tracer_callback_variadic_unregister(struct side_event_description *desc, | |
1981 | side_tracer_callback_variadic_func call_variadic, | |
1982 | void *priv); | |
1983 | ||
1984 | enum side_tracer_notification { | |
1985 | SIDE_TRACER_NOTIFICATION_INSERT_EVENTS, | |
1986 | SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS, | |
1987 | }; | |
1988 | ||
1989 | /* Callback is invoked with side library internal lock held. */ | |
1990 | struct side_tracer_handle *side_tracer_event_notification_register( | |
1991 | void (*cb)(enum side_tracer_notification notif, | |
1992 | struct side_event_description **events, uint32_t nr_events, void *priv), | |
1993 | void *priv); | |
1994 | void side_tracer_event_notification_unregister(struct side_tracer_handle *handle); | |
1995 | ||
1996 | /* | |
1997 | * Explicit hooks to initialize/finalize the side instrumentation | |
1998 | * library. Those are also library constructor/destructor. | |
1999 | */ | |
2000 | void side_init(void) __attribute__((constructor)); | |
2001 | void side_exit(void) __attribute__((destructor)); | |
2002 | ||
2003 | /* | |
2004 | * The following constructors/destructors perform automatic registration | |
2005 | * of the declared side events. Those may have to be called explicitly | |
2006 | * in a statically linked library. | |
2007 | */ | |
2008 | ||
2009 | /* | |
2010 | * These weak symbols, the constructor, and destructor take care of | |
2011 | * registering only _one_ instance of the side instrumentation per | |
2012 | * shared-ojbect (or for the whole main program). | |
2013 | */ | |
2014 | extern struct side_event_description * __start_side_event_description_ptr[] | |
2015 | __attribute__((weak, visibility("hidden"))); | |
2016 | extern struct side_event_description * __stop_side_event_description_ptr[] | |
2017 | __attribute__((weak, visibility("hidden"))); | |
2018 | int side_event_description_ptr_registered | |
2019 | __attribute__((weak, visibility("hidden"))); | |
2020 | struct side_events_register_handle *side_events_handle | |
2021 | __attribute__((weak, visibility("hidden"))); | |
2022 | ||
2023 | static void | |
2024 | side_event_description_ptr_init(void) | |
2025 | __attribute__((no_instrument_function)) | |
2026 | __attribute__((constructor)); | |
2027 | static void | |
2028 | side_event_description_ptr_init(void) | |
2029 | { | |
2030 | if (side_event_description_ptr_registered++) | |
2031 | return; | |
2032 | side_events_handle = side_events_register(__start_side_event_description_ptr, | |
2033 | __stop_side_event_description_ptr - __start_side_event_description_ptr); | |
2034 | } | |
2035 | ||
2036 | static void | |
2037 | side_event_description_ptr_exit(void) | |
2038 | __attribute__((no_instrument_function)) | |
2039 | __attribute__((destructor)); | |
2040 | static void | |
2041 | side_event_description_ptr_exit(void) | |
2042 | { | |
2043 | if (--side_event_description_ptr_registered) | |
2044 | return; | |
2045 | side_events_unregister(side_events_handle); | |
2046 | side_events_handle = NULL; | |
2047 | } | |
2048 | ||
2049 | #ifdef __cplusplus | |
2050 | } | |
2051 | #endif | |
2052 | ||
2053 | #endif /* _SIDE_TRACE_H */ |