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