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