1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
15 #include <side/macros.h>
16 #include <side/endian.h>
19 * SIDE stands for "Software Instrumentation Dynamically Enabled"
21 * This is an instrumentation API for Linux user-space, which exposes an
22 * instrumentation type system and facilities allowing a kernel or
23 * user-space tracer to consume user-space instrumentation.
25 * This instrumentation API exposes 3 type systems:
27 * * Stack-copy type system: This is the core type system which can
28 * represent all supported types and into which all other type systems
29 * can be nested. This type system requires that every type is
30 * statically or dynamically declared and then registered, thus giving
31 * tracers a complete description of the events and their associated
32 * fields before the associated instrumentation is invoked. The
33 * application needs to copy each argument (side_arg_...()) onto the
34 * stack when calling the instrumentation.
36 * This is the most expressive of the 3 type systems, althrough not the
37 * fastest due to the extra copy of the arguments.
39 * * Data-gathering type system: This type system requires every type to
40 * be statically or dynamically declared and registered, but does not
41 * require the application to copy its arguments onto the stack.
42 * Instead, the type description contains all the required information
43 * to fetch the data from the application memory. The only argument
44 * required from the instrumentation is the base pointer from which
45 * the data should be fetched.
47 * This type system can be used as an event field, or nested within
48 * the stack-copy type system. Nesting of gather-vla within
49 * gather-array and gather-vla types is not allowed.
51 * This type system is has the least overhead of the 3 type systems.
53 * * Dynamic type system: This type system receives both type
54 * description and actual data onto the stack at runtime. It has more
55 * overhead that the 2 other type systems, but does not require a
56 * prior registration of event field description. This makes it useful
57 * for seldom used types which are not performance critical, but for
58 * which registering each individual events would needlessly grow the
59 * number of events to declare and register.
61 * Another use-case for this type system is for use by dynamically
62 * typed language runtimes, where the field type is only known when
63 * the instrumentation is called.
65 * Those dynamic types can be either used as arguments to a variadic
66 * field list, or as on-stack instrumentation argument for a static
67 * type SIDE_TYPE_DYNAMIC place holder in the stack-copy type system.
70 //TODO: as those structures will be ABI, we need to either consider them
71 //fixed forever, or think of a scheme that would allow their binary
72 //representation to be extended if need be.
76 union side_arg_dynamic
;
77 struct side_arg_dynamic_field
;
78 struct side_arg_dynamic_vla
;
80 struct side_event_field
;
81 struct side_tracer_visitor_ctx
;
82 struct side_tracer_dynamic_struct_visitor_ctx
;
83 struct side_event_description
;
84 struct side_arg_dynamic_struct
;
85 struct side_events_register_handle
;
86 struct side_arg_variant
;
88 enum side_type_label
{
89 /* Stack-copy basic types */
102 SIDE_TYPE_FLOAT_BINARY16
,
103 SIDE_TYPE_FLOAT_BINARY32
,
104 SIDE_TYPE_FLOAT_BINARY64
,
105 SIDE_TYPE_FLOAT_BINARY128
,
106 SIDE_TYPE_STRING_UTF8
,
107 SIDE_TYPE_STRING_UTF16
,
108 SIDE_TYPE_STRING_UTF32
,
110 /* Stack-copy compound types */
115 SIDE_TYPE_VLA_VISITOR
,
117 /* Stack-copy enumeration types */
119 SIDE_TYPE_ENUM_BITMAP
,
121 /* Stack-copy place holder for dynamic types */
124 /* Gather basic types */
125 SIDE_TYPE_GATHER_BOOL
,
126 SIDE_TYPE_GATHER_INTEGER
,
127 SIDE_TYPE_GATHER_BYTE
,
128 SIDE_TYPE_GATHER_POINTER
,
129 SIDE_TYPE_GATHER_FLOAT
,
130 SIDE_TYPE_GATHER_STRING
,
132 /* Gather compound types */
133 SIDE_TYPE_GATHER_STRUCT
,
134 SIDE_TYPE_GATHER_ARRAY
,
135 SIDE_TYPE_GATHER_VLA
,
137 /* Gather enumeration types */
138 SIDE_TYPE_GATHER_ENUM
,
140 /* Dynamic basic types */
141 SIDE_TYPE_DYNAMIC_NULL
,
142 SIDE_TYPE_DYNAMIC_BOOL
,
143 SIDE_TYPE_DYNAMIC_INTEGER
,
144 SIDE_TYPE_DYNAMIC_BYTE
,
145 SIDE_TYPE_DYNAMIC_POINTER
,
146 SIDE_TYPE_DYNAMIC_FLOAT
,
147 SIDE_TYPE_DYNAMIC_STRING
,
149 /* Dynamic compound types */
150 SIDE_TYPE_DYNAMIC_STRUCT
,
151 SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
,
152 SIDE_TYPE_DYNAMIC_VLA
,
153 SIDE_TYPE_DYNAMIC_VLA_VISITOR
,
156 enum side_attr_type
{
167 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
168 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
169 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
170 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
171 SIDE_ATTR_TYPE_STRING
,
175 SIDE_LOGLEVEL_EMERG
= 0,
176 SIDE_LOGLEVEL_ALERT
= 1,
177 SIDE_LOGLEVEL_CRIT
= 2,
178 SIDE_LOGLEVEL_ERR
= 3,
179 SIDE_LOGLEVEL_WARNING
= 4,
180 SIDE_LOGLEVEL_NOTICE
= 5,
181 SIDE_LOGLEVEL_INFO
= 6,
182 SIDE_LOGLEVEL_DEBUG
= 7,
185 enum side_visitor_status
{
186 SIDE_VISITOR_STATUS_OK
= 0,
187 SIDE_VISITOR_STATUS_ERROR
= -1,
192 SIDE_ERROR_INVAL
= 1,
193 SIDE_ERROR_EXIST
= 2,
194 SIDE_ERROR_NOMEM
= 3,
195 SIDE_ERROR_NOENT
= 4,
196 SIDE_ERROR_EXITING
= 5,
199 enum side_type_label_byte_order
{
200 SIDE_TYPE_BYTE_ORDER_LE
= 0,
201 SIDE_TYPE_BYTE_ORDER_BE
= 1,
204 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
205 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
207 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
210 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
211 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
213 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
216 enum side_type_gather_access_mode
{
217 SIDE_TYPE_GATHER_ACCESS_DIRECT
,
218 SIDE_TYPE_GATHER_ACCESS_POINTER
, /* Pointer dereference */
221 typedef enum side_visitor_status (*side_visitor_func
)(
222 const struct side_tracer_visitor_ctx
*tracer_ctx
,
224 typedef enum side_visitor_status (*side_dynamic_struct_visitor_func
)(
225 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
228 union side_integer_value
{
240 union side_bool_value
{
242 uint16_t side_bool16
;
243 uint32_t side_bool32
;
244 uint64_t side_bool64
;
247 union side_float_value
{
249 _Float16 side_float_binary16
;
252 _Float32 side_float_binary32
;
255 _Float64 side_float_binary64
;
258 _Float128 side_float_binary128
;
262 struct side_type_raw_string
{
263 side_ptr_t(const void) p
; /* pointer to string */
264 uint8_t unit_size
; /* 1, 2, or 4 bytes */
265 uint8_t byte_order
; /* enum side_type_label_byte_order */
268 struct side_attr_value
{
269 uint32_t type
; /* enum side_attr_type */
272 struct side_type_raw_string string_value
;
273 union side_integer_value integer_value
;
274 union side_float_value float_value
;
278 /* User attributes. */
280 const struct side_type_raw_string key
;
281 const struct side_attr_value value
;
284 /* Type descriptions */
285 struct side_type_null
{
286 side_ptr_t(const struct side_attr
) attr
;
290 struct side_type_bool
{
291 side_ptr_t(const struct side_attr
) attr
;
293 uint16_t bool_size
; /* bytes */
294 uint16_t len_bits
; /* bits. 0 for (bool_size * CHAR_BITS) */
295 uint8_t byte_order
; /* enum side_type_label_byte_order */
298 struct side_type_byte
{
299 const struct side_attr
*attr
;
303 struct side_type_string
{
304 const struct side_attr
*attr
;
306 uint8_t unit_size
; /* 1, 2, or 4 bytes */
307 uint8_t byte_order
; /* enum side_type_label_byte_order */
310 struct side_type_integer
{
311 const struct side_attr
*attr
;
313 uint16_t integer_size
; /* bytes */
314 uint16_t len_bits
; /* bits. 0 for (integer_size * CHAR_BITS) */
315 uint8_t signedness
; /* true/false */
316 uint8_t byte_order
; /* enum side_type_label_byte_order */
319 struct side_type_float
{
320 const struct side_attr
*attr
;
322 uint16_t float_size
; /* bytes */
323 uint8_t byte_order
; /* enum side_type_label_byte_order */
326 struct side_enum_mapping
{
329 struct side_type_raw_string label
;
332 struct side_enum_mappings
{
333 const struct side_enum_mapping
*mappings
;
334 const struct side_attr
*attr
;
335 uint32_t nr_mappings
;
339 struct side_enum_bitmap_mapping
{
340 uint64_t range_begin
;
342 struct side_type_raw_string label
;
345 struct side_enum_bitmap_mappings
{
346 const struct side_enum_bitmap_mapping
*mappings
;
347 const struct side_attr
*attr
;
348 uint32_t nr_mappings
;
352 struct side_type_struct
{
353 const struct side_event_field
*fields
;
354 const struct side_attr
*attr
;
359 struct side_type_array
{
360 const struct side_type
*elem_type
;
361 const struct side_attr
*attr
;
366 struct side_type_vla
{
367 const struct side_type
*elem_type
;
368 const struct side_attr
*attr
;
372 struct side_type_vla_visitor
{
373 const struct side_type
*elem_type
;
374 side_visitor_func visitor
;
375 const struct side_attr
*attr
;
379 struct side_type_enum
{
380 const struct side_enum_mappings
*mappings
;
381 const struct side_type
*elem_type
;
384 struct side_type_enum_bitmap
{
385 const struct side_enum_bitmap_mappings
*mappings
;
386 const struct side_type
*elem_type
;
389 struct side_type_gather_bool
{
390 uint64_t offset
; /* bytes */
391 uint8_t access_mode
; /* enum side_type_gather_access_mode */
392 struct side_type_bool type
;
393 uint16_t offset_bits
; /* bits */
396 struct side_type_gather_byte
{
397 uint64_t offset
; /* bytes */
398 uint8_t access_mode
; /* enum side_type_gather_access_mode */
399 struct side_type_byte type
;
402 struct side_type_gather_integer
{
403 uint64_t offset
; /* bytes */
404 uint8_t access_mode
; /* enum side_type_gather_access_mode */
405 struct side_type_integer type
;
406 uint16_t offset_bits
; /* bits */
409 struct side_type_gather_float
{
410 uint64_t offset
; /* bytes */
411 uint8_t access_mode
; /* enum side_type_gather_access_mode */
412 struct side_type_float type
;
415 struct side_type_gather_string
{
416 uint64_t offset
; /* bytes */
417 uint8_t access_mode
; /* enum side_type_gather_access_mode */
418 struct side_type_string type
;
421 struct side_type_gather_enum
{
422 const struct side_enum_mappings
*mappings
;
423 const struct side_type
*elem_type
;
426 struct side_type_gather_struct
{
427 uint64_t offset
; /* bytes */
428 uint8_t access_mode
; /* enum side_type_gather_access_mode */
429 const struct side_type_struct
*type
;
430 uint32_t size
; /* bytes */
433 struct side_type_gather_array
{
434 uint64_t offset
; /* bytes */
435 uint8_t access_mode
; /* enum side_type_gather_access_mode */
436 struct side_type_array type
;
439 struct side_type_gather_vla
{
440 const struct side_type
*length_type
; /* side_length() */
442 uint64_t offset
; /* bytes */
443 uint8_t access_mode
; /* enum side_type_gather_access_mode */
444 struct side_type_vla type
;
447 struct side_type_gather
{
449 struct side_type_gather_bool side_bool
;
450 struct side_type_gather_byte side_byte
;
451 struct side_type_gather_integer side_integer
;
452 struct side_type_gather_float side_float
;
453 struct side_type_gather_string side_string
;
454 struct side_type_gather_enum side_enum
;
455 struct side_type_gather_array side_array
;
456 struct side_type_gather_vla side_vla
;
457 struct side_type_gather_struct side_struct
;
462 uint32_t type
; /* enum side_type_label */
464 /* Stack-copy basic types */
465 struct side_type_null side_null
;
466 struct side_type_bool side_bool
;
467 struct side_type_byte side_byte
;
468 struct side_type_string side_string
;
469 struct side_type_integer side_integer
;
470 struct side_type_float side_float
;
472 /* Stack-copy compound types */
473 struct side_type_array side_array
;
474 struct side_type_vla side_vla
;
475 struct side_type_vla_visitor side_vla_visitor
;
476 const struct side_type_struct
*side_struct
;
477 const struct side_type_variant
*side_variant
;
479 /* Stack-copy enumeration types */
480 struct side_type_enum side_enum
;
481 struct side_type_enum_bitmap side_enum_bitmap
;
484 struct side_type_gather side_gather
;
488 struct side_variant_option
{
491 const struct side_type side_type
;
494 struct side_type_variant
{
495 const struct side_type selector
;
496 const struct side_variant_option
*options
;
497 const struct side_attr
*attr
;
502 struct side_event_field
{
503 const char *field_name
;
504 struct side_type side_type
;
507 enum side_event_flags
{
508 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
511 struct side_callback
{
513 void (*call
)(const struct side_event_description
*desc
,
514 const struct side_arg_vec
*side_arg_vec
,
516 void (*call_variadic
)(const struct side_event_description
*desc
,
517 const struct side_arg_vec
*side_arg_vec
,
518 const struct side_arg_dynamic_struct
*var_struct
,
524 union side_arg_static
{
525 /* Stack-copy basic types */
526 union side_bool_value bool_value
;
528 uint64_t string_value
; /* const {uint8_t, uint16_t, uint32_t} * */
529 union side_integer_value integer_value
;
530 union side_float_value float_value
;
532 /* Stack-copy compound types */
533 const struct side_arg_vec
*side_struct
;
534 const struct side_arg_variant
*side_variant
;
535 const struct side_arg_vec
*side_array
;
536 const struct side_arg_vec
*side_vla
;
537 void *side_vla_app_visitor_ctx
;
539 /* Gather basic types */
540 const void *side_bool_gather_ptr
;
541 const void *side_byte_gather_ptr
;
542 const void *side_integer_gather_ptr
;
543 const void *side_float_gather_ptr
;
544 const void *side_string_gather_ptr
;
546 /* Gather compound types */
547 const void *side_array_gather_ptr
;
548 const void *side_struct_gather_ptr
;
551 const void *length_ptr
;
552 } SIDE_PACKED side_vla_gather
;
555 struct side_arg_dynamic_vla
{
556 const struct side_arg
*sav
;
557 const struct side_attr
*attr
;
562 struct side_arg_dynamic_struct
{
563 const struct side_arg_dynamic_field
*fields
;
564 const struct side_attr
*attr
;
569 struct side_dynamic_struct_visitor
{
571 side_dynamic_struct_visitor_func visitor
;
572 const struct side_attr
*attr
;
576 struct side_dynamic_vla_visitor
{
578 side_visitor_func visitor
;
579 const struct side_attr
*attr
;
583 union side_arg_dynamic
{
584 /* Dynamic basic types */
585 struct side_type_null side_null
;
587 struct side_type_bool type
;
588 union side_bool_value value
;
589 } SIDE_PACKED side_bool
;
591 struct side_type_byte type
;
593 } SIDE_PACKED side_byte
;
595 struct side_type_string type
;
596 uint64_t value
; /* const char * */
597 } SIDE_PACKED side_string
;
599 struct side_type_integer type
;
600 union side_integer_value value
;
601 } SIDE_PACKED side_integer
;
603 struct side_type_float type
;
604 union side_float_value value
;
605 } SIDE_PACKED side_float
;
607 /* Dynamic compound types */
608 const struct side_arg_dynamic_struct
*side_dynamic_struct
;
609 const struct side_arg_dynamic_vla
*side_dynamic_vla
;
611 struct side_dynamic_struct_visitor side_dynamic_struct_visitor
;
612 struct side_dynamic_vla_visitor side_dynamic_vla_visitor
;
616 uint32_t type
; /* enum side_type_label */
618 union side_arg_static side_static
;
619 union side_arg_dynamic side_dynamic
;
623 struct side_arg_variant
{
624 struct side_arg selector
;
625 struct side_arg option
;
628 struct side_arg_vec
{
629 const struct side_arg
*sav
;
633 struct side_arg_dynamic_field
{
634 const char *field_name
;
635 const struct side_arg elem
;
638 /* The visitor pattern is a double-dispatch visitor. */
639 struct side_tracer_visitor_ctx
{
640 enum side_visitor_status (*write_elem
)(
641 const struct side_tracer_visitor_ctx
*tracer_ctx
,
642 const struct side_arg
*elem
);
643 void *priv
; /* Private tracer context. */
646 struct side_tracer_dynamic_struct_visitor_ctx
{
647 enum side_visitor_status (*write_field
)(
648 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
649 const struct side_arg_dynamic_field
*dynamic_field
);
650 void *priv
; /* Private tracer context. */
654 * This structure is _not_ packed to allow atomic operations on its
657 struct side_event_state
{
659 const struct side_callback
*callbacks
;
660 uint32_t nr_callbacks
;
663 struct side_event_description
{
664 struct side_event_state
*state
;
665 const char *provider_name
;
666 const char *event_name
;
667 const struct side_event_field
*fields
;
668 const struct side_attr
*attr
;
671 uint32_t loglevel
; /* enum side_loglevel */
676 /* Event and type attributes */
678 #define side_attr(_key, _value) \
681 .p = SIDE_PTR_INIT(_key), \
682 .unit_size = sizeof(uint8_t), \
683 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
685 .value = SIDE_PARAM(_value), \
688 #define side_attr_list(...) \
689 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
691 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
692 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
693 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
694 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
695 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
696 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
697 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
698 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
699 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
700 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
701 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
702 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
703 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
704 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
706 #define _side_attr_string(_val, _byte_order, _unit_size) \
708 .type = SIDE_ATTR_TYPE_STRING, \
711 .p = SIDE_PTR_INIT(_val), \
712 .unit_size = _unit_size, \
713 .byte_order = _byte_order, \
718 #define side_attr_string(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t))
719 #define side_attr_string16(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t))
720 #define side_attr_string32(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t))
722 /* Stack-copy enumeration type definitions */
724 #define side_define_enum(_identifier, _mappings, _attr...) \
725 const struct side_enum_mappings _identifier = { \
726 .mappings = _mappings, \
727 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
728 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
729 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
732 #define side_enum_mapping_list(...) \
733 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
735 #define side_enum_mapping_range(_label, _begin, _end) \
737 .range_begin = _begin, \
740 .p = SIDE_PTR_INIT(_label), \
741 .unit_size = sizeof(uint8_t), \
742 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
746 #define side_enum_mapping_value(_label, _value) \
748 .range_begin = _value, \
749 .range_end = _value, \
751 .p = SIDE_PTR_INIT(_label), \
752 .unit_size = sizeof(uint8_t), \
753 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
757 #define side_define_enum_bitmap(_identifier, _mappings, _attr...) \
758 const struct side_enum_bitmap_mappings _identifier = { \
759 .mappings = _mappings, \
760 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
761 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
762 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
765 #define side_enum_bitmap_mapping_list(...) \
766 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
768 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
770 .range_begin = _begin, \
773 .p = SIDE_PTR_INIT(_label), \
774 .unit_size = sizeof(uint8_t), \
775 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
779 #define side_enum_bitmap_mapping_value(_label, _value) \
781 .range_begin = _value, \
782 .range_end = _value, \
784 .p = SIDE_PTR_INIT(_label), \
785 .unit_size = sizeof(uint8_t), \
786 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
790 /* Stack-copy field and type definitions */
792 #define side_type_null(_attr...) \
794 .type = SIDE_TYPE_NULL, \
797 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
798 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
803 #define side_type_bool(_attr...) \
805 .type = SIDE_TYPE_BOOL, \
808 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
809 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
810 .bool_size = sizeof(uint8_t), \
812 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
817 #define side_type_byte(_attr...) \
819 .type = SIDE_TYPE_BYTE, \
822 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
823 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
828 #define _side_type_string(_type, _byte_order, _unit_size, _attr) \
834 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
835 .unit_size = _unit_size, \
836 .byte_order = _byte_order, \
841 #define side_type_dynamic() \
843 .type = SIDE_TYPE_DYNAMIC, \
846 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
852 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
853 .integer_size = _integer_size, \
854 .len_bits = _len_bits, \
855 .signedness = _signedness, \
856 .byte_order = _byte_order, \
861 #define _side_type_float(_type, _byte_order, _float_size, _attr) \
867 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
868 .float_size = _float_size, \
869 .byte_order = _byte_order, \
874 #define _side_field(_name, _type) \
876 .field_name = _name, \
877 .side_type = _type, \
880 #define side_option_range(_range_begin, _range_end, _type) \
882 .range_begin = _range_begin, \
883 .range_end = _range_end, \
884 .side_type = _type, \
887 #define side_option(_value, _type) \
888 side_option_range(_value, _value, SIDE_PARAM(_type))
891 #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()))
892 #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()))
893 #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()))
894 #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()))
895 #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()))
896 #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()))
897 #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()))
898 #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()))
899 #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()))
900 #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()))
901 #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()))
902 #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()))
903 #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()))
904 #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()))
905 #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()))
906 #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()))
908 #define side_field_null(_name, _attr...) _side_field(_name, side_type_null(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
909 #define side_field_bool(_name, _attr...) _side_field(_name, side_type_bool(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
910 #define side_field_u8(_name, _attr...) _side_field(_name, side_type_u8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
911 #define side_field_u16(_name, _attr...) _side_field(_name, side_type_u16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
912 #define side_field_u32(_name, _attr...) _side_field(_name, side_type_u32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
913 #define side_field_u64(_name, _attr...) _side_field(_name, side_type_u64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
914 #define side_field_s8(_name, _attr...) _side_field(_name, side_type_s8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
915 #define side_field_s16(_name, _attr...) _side_field(_name, side_type_s16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
916 #define side_field_s32(_name, _attr...) _side_field(_name, side_type_s32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
917 #define side_field_s64(_name, _attr...) _side_field(_name, side_type_s64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
918 #define side_field_byte(_name, _attr...) _side_field(_name, side_type_byte(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
919 #define side_field_pointer(_name, _attr...) _side_field(_name, side_type_pointer(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
920 #define side_field_float_binary16(_name, _attr...) _side_field(_name, side_type_float_binary16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
921 #define side_field_float_binary32(_name, _attr...) _side_field(_name, side_type_float_binary32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
922 #define side_field_float_binary64(_name, _attr...) _side_field(_name, side_type_float_binary64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
923 #define side_field_float_binary128(_name, _attr...) _side_field(_name, side_type_float_binary128(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
924 #define side_field_string(_name, _attr...) _side_field(_name, side_type_string(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
925 #define side_field_string16(_name, _attr...) _side_field(_name, side_type_string16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
926 #define side_field_string32(_name, _attr...) _side_field(_name, side_type_string32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
927 #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic())
930 #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()))
931 #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()))
932 #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()))
933 #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()))
934 #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()))
935 #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()))
936 #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()))
937 #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()))
938 #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()))
939 #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()))
940 #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()))
941 #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()))
942 #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()))
944 #define side_field_u16_le(_name, _attr...) _side_field(_name, side_type_u16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
945 #define side_field_u32_le(_name, _attr...) _side_field(_name, side_type_u32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
946 #define side_field_u64_le(_name, _attr...) _side_field(_name, side_type_u64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
947 #define side_field_s16_le(_name, _attr...) _side_field(_name, side_type_s16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
948 #define side_field_s32_le(_name, _attr...) _side_field(_name, side_type_s32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
949 #define side_field_s64_le(_name, _attr...) _side_field(_name, side_type_s64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
950 #define side_field_pointer_le(_name, _attr...) _side_field(_name, side_type_pointer_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
951 #define side_field_float_binary16_le(_name, _attr...) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
952 #define side_field_float_binary32_le(_name, _attr...) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
953 #define side_field_float_binary64_le(_name, _attr...) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
954 #define side_field_float_binary128_le(_name, _attr...) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
955 #define side_field_string16_le(_name, _attr...) _side_field(_name, side_type_string16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
956 #define side_field_string32_le(_name, _attr...) _side_field(_name, side_type_string32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
959 #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()))
960 #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()))
961 #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()))
962 #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()))
963 #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()))
964 #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()))
965 #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()))
966 #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()))
967 #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()))
968 #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()))
969 #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()))
970 #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()))
971 #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()))
973 #define side_field_u16_be(_name, _attr...) _side_field(_name, side_type_u16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
974 #define side_field_u32_be(_name, _attr...) _side_field(_name, side_type_u32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
975 #define side_field_u64_be(_name, _attr...) _side_field(_name, side_type_u64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
976 #define side_field_s16_be(_name, _attr...) _side_field(_name, side_type_s16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
977 #define side_field_s32_be(_name, _attr...) _side_field(_name, side_type_s32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
978 #define side_field_s64_be(_name, _attr...) _side_field(_name, side_type_s64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
979 #define side_field_pointer_be(_name, _attr...) _side_field(_name, side_type_pointer_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
980 #define side_field_float_binary16_be(_name, _attr...) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
981 #define side_field_float_binary32_be(_name, _attr...) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
982 #define side_field_float_binary64_be(_name, _attr...) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
983 #define side_field_float_binary128_be(_name, _attr...) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
984 #define side_field_string16_be(_name, _attr...) _side_field(_name, side_type_string16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
985 #define side_field_string32_be(_name, _attr...) _side_field(_name, side_type_string32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
987 #define side_type_enum(_mappings, _elem_type) \
989 .type = SIDE_TYPE_ENUM, \
992 .mappings = _mappings, \
993 .elem_type = _elem_type, \
997 #define side_field_enum(_name, _mappings, _elem_type) \
998 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1000 #define side_type_enum_bitmap(_mappings, _elem_type) \
1002 .type = SIDE_TYPE_ENUM_BITMAP, \
1004 .side_enum_bitmap = { \
1005 .mappings = _mappings, \
1006 .elem_type = _elem_type, \
1010 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
1011 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1013 #define side_type_struct(_struct) \
1015 .type = SIDE_TYPE_STRUCT, \
1017 .side_struct = _struct, \
1020 #define side_field_struct(_name, _struct) \
1021 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
1023 #define _side_type_struct_define(_fields, _attr) \
1025 .fields = _fields, \
1027 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1028 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1031 #define side_define_struct(_identifier, _fields, _attr...) \
1032 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1034 #define side_struct_literal(_fields, _attr...) \
1035 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
1036 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1038 #define side_type_variant(_variant) \
1040 .type = SIDE_TYPE_VARIANT, \
1042 .side_variant = _variant, \
1045 #define side_field_variant(_name, _variant) \
1046 _side_field(_name, side_type_variant(SIDE_PARAM(_variant)))
1048 #define _side_type_variant_define(_selector, _options, _attr) \
1050 .selector = _selector, \
1051 .options = _options, \
1053 .nr_options = SIDE_ARRAY_SIZE(SIDE_PARAM(_options)), \
1054 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1057 #define side_define_variant(_identifier, _selector, _options, _attr...) \
1058 const struct side_type_variant _identifier = \
1059 _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1061 #define side_variant_literal(_selector, _options, _attr...) \
1062 SIDE_COMPOUND_LITERAL(const struct side_type_variant, \
1063 _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1065 #define side_type_array(_elem_type, _length, _attr...) \
1067 .type = SIDE_TYPE_ARRAY, \
1070 .elem_type = _elem_type, \
1071 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1072 .length = _length, \
1073 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1077 #define side_field_array(_name, _elem_type, _length, _attr...) \
1078 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1080 #define side_type_vla(_elem_type, _attr...) \
1082 .type = SIDE_TYPE_VLA, \
1085 .elem_type = _elem_type, \
1086 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1087 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1091 #define side_field_vla(_name, _elem_type, _attr...) \
1092 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1094 #define side_type_vla_visitor(_elem_type, _visitor, _attr...) \
1096 .type = SIDE_TYPE_VLA_VISITOR, \
1098 .side_vla_visitor = { \
1099 .elem_type = SIDE_PARAM(_elem_type), \
1100 .visitor = _visitor, \
1101 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1102 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1106 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr...) \
1107 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1109 /* Gather field and type definitions */
1111 #define side_type_gather_byte(_offset, _access_mode, _attr...) \
1113 .type = SIDE_TYPE_GATHER_BYTE, \
1118 .offset = _offset, \
1119 .access_mode = _access_mode, \
1121 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1122 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1129 #define side_field_gather_byte(_name, _offset, _access_mode, _attr...) \
1130 _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1132 #define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1134 .type = SIDE_TYPE_GATHER_BOOL, \
1139 .offset = _offset, \
1140 .access_mode = _access_mode, \
1142 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1143 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1144 .bool_size = _bool_size, \
1145 .len_bits = _len_bits, \
1146 .byte_order = _byte_order, \
1148 .offset_bits = _offset_bits, \
1154 #define side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1155 _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()))
1156 #define side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1157 _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()))
1158 #define side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1159 _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()))
1161 #define side_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1162 _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()))))
1163 #define side_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1164 _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()))))
1165 #define side_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1166 _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()))))
1168 #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
1169 _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1176 .offset = _offset, \
1177 .access_mode = _access_mode, \
1179 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1180 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1181 .integer_size = _integer_size, \
1182 .len_bits = _len_bits, \
1183 .signedness = _signedness, \
1184 .byte_order = _byte_order, \
1186 .offset_bits = _offset_bits, \
1193 #define side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1194 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1195 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1196 #define side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1197 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, \
1198 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1200 #define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1201 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_LE, \
1202 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1203 #define side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1204 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_LE, \
1205 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1207 #define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1208 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_BE, \
1209 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1210 #define side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1211 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_BE, \
1212 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1214 #define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1215 _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())))
1216 #define side_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1217 _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())))
1219 #define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1220 _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())))
1221 #define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1222 _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())))
1224 #define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1225 _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())))
1226 #define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1227 _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())))
1229 #define side_type_gather_pointer(_offset, _access_mode, _attr...) \
1230 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1231 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1232 #define side_field_gather_pointer(_name, _offset, _access_mode, _attr...) \
1233 _side_field(_name, side_type_gather_pointer(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1235 #define side_type_gather_pointer_le(_offset, _access_mode, _attr...) \
1236 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, \
1237 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1238 #define side_field_gather_pointer_le(_name, _offset, _access_mode, _attr...) \
1239 _side_field(_name, side_type_gather_pointer_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1241 #define side_type_gather_pointer_be(_offset, _access_mode, _attr...) \
1242 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, \
1243 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1244 #define side_field_gather_pointer_be(_name, _offset, _access_mode, _attr...) \
1245 _side_field(_name, side_type_gather_pointer_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1247 #define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr...) \
1249 .type = SIDE_TYPE_GATHER_FLOAT, \
1254 .offset = _offset, \
1255 .access_mode = _access_mode, \
1257 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1258 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1259 .float_size = _float_size, \
1260 .byte_order = _byte_order, \
1268 #define side_type_gather_float(_offset, _float_size, _access_mode, _attr...) \
1269 _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1270 #define side_type_gather_float_le(_offset, _float_size, _access_mode, _attr...) \
1271 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1272 #define side_type_gather_float_be(_offset, _float_size, _access_mode, _attr...) \
1273 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1275 #define side_field_gather_float(_name, _offset, _float_size, _access_mode, _attr...) \
1276 _side_field(_name, side_type_gather_float(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1277 #define side_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr...) \
1278 _side_field(_name, side_type_gather_float_le(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1279 #define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr...) \
1280 _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1282 #define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr...) \
1284 .type = SIDE_TYPE_GATHER_STRING, \
1289 .offset = _offset, \
1290 .access_mode = _access_mode, \
1292 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1293 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1294 .unit_size = _unit_size, \
1295 .byte_order = _byte_order, \
1302 #define side_type_gather_string(_offset, _access_mode, _attr...) \
1303 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1304 #define side_field_gather_string(_name, _offset, _access_mode, _attr...) \
1305 _side_field(_name, side_type_gather_string(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1307 #define side_type_gather_string16(_offset, _access_mode, _attr...) \
1308 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1309 #define side_type_gather_string16_le(_offset, _access_mode, _attr...) \
1310 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1311 #define side_type_gather_string16_be(_offset, _access_mode, _attr...) \
1312 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1314 #define side_field_gather_string16(_name, _offset, _access_mode, _attr...) \
1315 _side_field(_name, side_type_gather_string16(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1316 #define side_field_gather_string16_le(_name, _offset, _access_mode, _attr...) \
1317 _side_field(_name, side_type_gather_string16_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1318 #define side_field_gather_string16_be(_name, _offset, _access_mode, _attr...) \
1319 _side_field(_name, side_type_gather_string16_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1321 #define side_type_gather_string32(_offset, _access_mode, _attr...) \
1322 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1323 #define side_type_gather_string32_le(_offset, _access_mode, _attr...) \
1324 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1325 #define side_type_gather_string32_be(_offset, _access_mode, _attr...) \
1326 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1328 #define side_field_gather_string32(_name, _offset, _access_mode, _attr...) \
1329 _side_field(_name, side_type_gather_string32(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1330 #define side_field_gather_string32_le(_name, _offset, _access_mode, _attr...) \
1331 _side_field(_name, side_type_gather_string32_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1332 #define side_field_gather_string32_be(_name, _offset, _access_mode, _attr...) \
1333 _side_field(_name, side_type_gather_string32_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1335 #define side_type_gather_enum(_mappings, _elem_type) \
1337 .type = SIDE_TYPE_GATHER_ENUM, \
1340 .mappings = _mappings, \
1341 .elem_type = _elem_type, \
1345 #define side_field_gather_enum(_name, _mappings, _elem_type) \
1346 _side_field(_name, side_type_gather_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1348 #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
1350 .type = SIDE_TYPE_GATHER_STRUCT, \
1355 .offset = _offset, \
1356 .access_mode = _access_mode, \
1357 .type = _struct_gather, \
1364 #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \
1365 _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode))
1367 #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr...) \
1369 .type = SIDE_TYPE_GATHER_ARRAY, \
1374 .offset = _offset, \
1375 .access_mode = _access_mode, \
1377 .elem_type = _elem_type_gather, \
1378 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1379 .length = _length, \
1380 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1387 #define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr...) \
1388 _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1390 #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \
1392 .type = SIDE_TYPE_GATHER_VLA, \
1397 .length_type = _length_type_gather, \
1398 .offset = _offset, \
1399 .access_mode = _access_mode, \
1401 .elem_type = _elem_type_gather, \
1402 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1403 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1410 #define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \
1411 _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())))
1413 #define side_elem(...) \
1414 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1416 #define side_length(...) \
1417 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1419 #define side_field_list(...) \
1420 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
1422 #define side_option_list(...) \
1423 SIDE_COMPOUND_LITERAL(const struct side_variant_option, __VA_ARGS__)
1425 /* Stack-copy field arguments */
1427 #define side_arg_null(_val) { .type = SIDE_TYPE_NULL }
1428 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } }
1429 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_static = { .byte_value = (_val) } } }
1430 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING_UTF8, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1431 #define side_arg_string16(_val) { .type = SIDE_TYPE_STRING_UTF16, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1432 #define side_arg_string32(_val) { .type = SIDE_TYPE_STRING_UTF32, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1434 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1435 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1436 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1437 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1438 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
1439 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
1440 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
1441 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
1442 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER, .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } }
1443 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
1444 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
1445 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
1446 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
1448 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = (_side_type) } } }
1450 #define side_arg_define_variant(_identifier, _selector_val, _option) \
1451 const struct side_arg_variant _identifier = { \
1452 .selector = _selector_val, \
1453 .option = _option, \
1455 #define side_arg_variant(_side_variant) \
1457 .type = SIDE_TYPE_VARIANT, \
1460 .side_variant = (_side_variant), \
1465 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
1466 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
1467 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
1469 /* Gather field arguments */
1471 #define side_arg_gather_bool(_ptr) { .type = SIDE_TYPE_GATHER_BOOL, .u = { .side_static = { .side_bool_gather_ptr = (_ptr) } } }
1472 #define side_arg_gather_byte(_ptr) { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = (_ptr) } } }
1473 #define side_arg_gather_pointer(_ptr) { .type = SIDE_TYPE_GATHER_POINTER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1474 #define side_arg_gather_integer(_ptr) { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1475 #define side_arg_gather_float(_ptr) { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = (_ptr) } } }
1476 #define side_arg_gather_string(_ptr) { .type = SIDE_TYPE_GATHER_STRING, .u = { .side_static = { .side_string_gather_ptr = (_ptr) } } }
1477 #define side_arg_gather_struct(_ptr) { .type = SIDE_TYPE_GATHER_STRUCT, .u = { .side_static = { .side_struct_gather_ptr = (_ptr) } } }
1478 #define side_arg_gather_array(_ptr) { .type = SIDE_TYPE_GATHER_ARRAY, .u = { .side_static = { .side_array_gather_ptr = (_ptr) } } }
1479 #define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_TYPE_GATHER_VLA, .u = { .side_static = { .side_vla_gather = { .ptr = (_ptr), .length_ptr = (_length_ptr) } } } }
1481 /* Dynamic field arguments */
1483 #define side_arg_dynamic_null(_attr...) \
1485 .type = SIDE_TYPE_DYNAMIC_NULL, \
1489 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1490 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1496 #define side_arg_dynamic_bool(_val, _attr...) \
1498 .type = SIDE_TYPE_DYNAMIC_BOOL, \
1503 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1504 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1505 .bool_size = sizeof(uint8_t), \
1507 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
1510 .side_bool8 = !!(_val), \
1517 #define side_arg_dynamic_byte(_val, _attr...) \
1519 .type = SIDE_TYPE_DYNAMIC_BYTE, \
1524 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1525 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1533 #define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr...) \
1535 .type = SIDE_TYPE_DYNAMIC_STRING, \
1540 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1541 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1542 .unit_size = _unit_size, \
1543 .byte_order = _byte_order, \
1545 .value = (uintptr_t) (_val), \
1550 #define side_arg_dynamic_string(_val, _attr...) \
1551 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1552 #define side_arg_dynamic_string16(_val, _attr...) \
1553 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1554 #define side_arg_dynamic_string16_le(_val, _attr...) \
1555 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1556 #define side_arg_dynamic_string16_be(_val, _attr...) \
1557 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1558 #define side_arg_dynamic_string32(_val, _attr...) \
1559 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1560 #define side_arg_dynamic_string32_le(_val, _attr...) \
1561 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1562 #define side_arg_dynamic_string32_be(_val, _attr...) \
1563 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1565 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr...) \
1572 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1573 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1574 .integer_size = _integer_size, \
1575 .len_bits = _len_bits, \
1576 .signedness = _signedness, \
1577 .byte_order = _byte_order, \
1587 #define side_arg_dynamic_u8(_val, _attr...) \
1588 _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()))
1589 #define side_arg_dynamic_s8(_val, _attr...) \
1590 _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()))
1592 #define _side_arg_dynamic_u16(_val, _byte_order, _attr...) \
1593 _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()))
1594 #define _side_arg_dynamic_u32(_val, _byte_order, _attr...) \
1595 _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()))
1596 #define _side_arg_dynamic_u64(_val, _byte_order, _attr...) \
1597 _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()))
1599 #define _side_arg_dynamic_s16(_val, _byte_order, _attr...) \
1600 _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()))
1601 #define _side_arg_dynamic_s32(_val, _byte_order, _attr...) \
1602 _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()))
1603 #define _side_arg_dynamic_s64(_val, _byte_order, _attr...) \
1604 _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()))
1606 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr...) \
1607 _side_arg_dynamic_integer(.side_uptr, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER, false, _byte_order, \
1608 sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1610 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr...) \
1617 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1618 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1619 .float_size = _float_size, \
1620 .byte_order = _byte_order, \
1630 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr...) \
1631 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1632 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr...) \
1633 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1634 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr...) \
1635 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1636 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr...) \
1637 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1640 #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()))
1641 #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()))
1642 #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()))
1643 #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()))
1644 #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()))
1645 #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()))
1646 #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()))
1647 #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()))
1648 #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()))
1649 #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()))
1650 #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()))
1653 #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()))
1654 #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()))
1655 #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()))
1656 #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()))
1657 #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()))
1658 #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()))
1659 #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()))
1660 #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()))
1661 #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()))
1662 #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()))
1663 #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()))
1666 #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()))
1667 #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()))
1668 #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()))
1669 #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()))
1670 #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()))
1671 #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()))
1672 #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()))
1673 #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()))
1674 #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()))
1675 #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()))
1676 #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()))
1678 #define side_arg_dynamic_vla(_vla) \
1680 .type = SIDE_TYPE_DYNAMIC_VLA, \
1683 .side_dynamic_vla = (_vla), \
1688 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr...) \
1690 .type = SIDE_TYPE_DYNAMIC_VLA_VISITOR, \
1693 .side_dynamic_vla_visitor = { \
1695 .visitor = _dynamic_vla_visitor, \
1696 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1697 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1703 #define side_arg_dynamic_struct(_struct) \
1705 .type = SIDE_TYPE_DYNAMIC_STRUCT, \
1708 .side_dynamic_struct = (_struct), \
1713 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr...) \
1715 .type = SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, \
1718 .side_dynamic_struct_visitor = { \
1720 .visitor = _dynamic_struct_visitor, \
1721 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1722 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1728 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr...) \
1729 const struct side_arg _identifier##_vec[] = { _sav }; \
1730 const struct side_arg_dynamic_vla _identifier = { \
1731 .sav = _identifier##_vec, \
1732 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1733 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1734 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1737 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr...) \
1738 const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \
1739 const struct side_arg_dynamic_struct _identifier = { \
1740 .fields = _identifier##_fields, \
1741 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1742 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1743 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1746 #define side_arg_define_vec(_identifier, _sav) \
1747 const struct side_arg _identifier##_vec[] = { _sav }; \
1748 const struct side_arg_vec _identifier = { \
1749 .sav = _identifier##_vec, \
1750 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1753 #define side_arg_dynamic_field(_name, _elem) \
1755 .field_name = _name, \
1760 * Event instrumentation description registration, runtime enabled state
1761 * check, and instrumentation invocation.
1764 #define side_arg_list(...) __VA_ARGS__
1766 #define side_event_cond(_identifier) \
1767 if (side_unlikely(__atomic_load_n(&side_event_state__##_identifier.enabled, \
1770 #define side_event_call(_identifier, _sav) \
1772 const struct side_arg side_sav[] = { _sav }; \
1773 const struct side_arg_vec side_arg_vec = { \
1775 .len = SIDE_ARRAY_SIZE(side_sav), \
1777 side_call(&(_identifier), &side_arg_vec); \
1780 #define side_event(_identifier, _sav) \
1781 side_event_cond(_identifier) \
1782 side_event_call(_identifier, SIDE_PARAM(_sav))
1784 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr...) \
1786 const struct side_arg side_sav[] = { _sav }; \
1787 const struct side_arg_vec side_arg_vec = { \
1789 .len = SIDE_ARRAY_SIZE(side_sav), \
1791 const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \
1792 const struct side_arg_dynamic_struct var_struct = { \
1793 .fields = side_fields, \
1794 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1795 .len = SIDE_ARRAY_SIZE(side_fields), \
1796 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1798 side_call_variadic(&(_identifier), &side_arg_vec, &var_struct); \
1801 #define side_event_variadic(_identifier, _sav, _var, _attr...) \
1802 side_event_cond(_identifier) \
1803 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1805 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _flags, _attr...) \
1806 _linkage struct side_event_state __attribute__((section("side_event_state"))) \
1807 side_event_state__##_identifier = { \
1809 .callbacks = &side_empty_callback, \
1810 .nr_callbacks = 0, \
1812 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1814 .state = &(side_event_state__##_identifier), \
1815 .provider_name = _provider, \
1816 .event_name = _event, \
1817 .fields = _fields, \
1818 .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \
1819 .flags = (_flags), \
1821 .loglevel = _loglevel, \
1822 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1823 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1825 static const struct side_event_description *side_event_ptr__##_identifier \
1826 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1828 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1829 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1832 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1833 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1834 SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1836 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1837 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1838 _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1840 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1841 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1842 _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1844 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1845 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1846 _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1848 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1849 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1850 _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1852 #define side_declare_event(_identifier) \
1853 extern struct side_event_state side_event_state_##_identifier; \
1854 extern struct side_event_description _identifier
1860 extern const struct side_callback side_empty_callback
;
1862 void side_call(const struct side_event_description
*desc
,
1863 const struct side_arg_vec
*side_arg_vec
);
1864 void side_call_variadic(const struct side_event_description
*desc
,
1865 const struct side_arg_vec
*side_arg_vec
,
1866 const struct side_arg_dynamic_struct
*var_struct
);
1868 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
,
1869 uint32_t nr_events
);
1870 void side_events_unregister(struct side_events_register_handle
*handle
);
1873 * Userspace tracer registration API. This allows userspace tracers to
1874 * register event notification callbacks to be notified of the currently
1875 * registered instrumentation, and to register their callbacks to
1878 typedef void (*side_tracer_callback_func
)(const struct side_event_description
*desc
,
1879 const struct side_arg_vec
*side_arg_vec
,
1881 typedef void (*side_tracer_callback_variadic_func
)(const struct side_event_description
*desc
,
1882 const struct side_arg_vec
*side_arg_vec
,
1883 const struct side_arg_dynamic_struct
*var_struct
,
1886 int side_tracer_callback_register(struct side_event_description
*desc
,
1887 side_tracer_callback_func call
,
1889 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1890 side_tracer_callback_variadic_func call_variadic
,
1892 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1893 side_tracer_callback_func call
,
1895 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1896 side_tracer_callback_variadic_func call_variadic
,
1899 enum side_tracer_notification
{
1900 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1901 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1904 /* Callback is invoked with side library internal lock held. */
1905 struct side_tracer_handle
*side_tracer_event_notification_register(
1906 void (*cb
)(enum side_tracer_notification notif
,
1907 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1909 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1912 * Explicit hooks to initialize/finalize the side instrumentation
1913 * library. Those are also library constructor/destructor.
1915 void side_init(void) __attribute__((constructor
));
1916 void side_exit(void) __attribute__((destructor
));
1919 * The following constructors/destructors perform automatic registration
1920 * of the declared side events. Those may have to be called explicitly
1921 * in a statically linked library.
1925 * These weak symbols, the constructor, and destructor take care of
1926 * registering only _one_ instance of the side instrumentation per
1927 * shared-ojbect (or for the whole main program).
1929 extern struct side_event_description
* __start_side_event_description_ptr
[]
1930 __attribute__((weak
, visibility("hidden")));
1931 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1932 __attribute__((weak
, visibility("hidden")));
1933 int side_event_description_ptr_registered
1934 __attribute__((weak
, visibility("hidden")));
1935 struct side_events_register_handle
*side_events_handle
1936 __attribute__((weak
, visibility("hidden")));
1939 side_event_description_ptr_init(void)
1940 __attribute__((no_instrument_function
))
1941 __attribute__((constructor
));
1943 side_event_description_ptr_init(void)
1945 if (side_event_description_ptr_registered
++)
1947 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1948 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1952 side_event_description_ptr_exit(void)
1953 __attribute__((no_instrument_function
))
1954 __attribute__((destructor
));
1956 side_event_description_ptr_exit(void)
1958 if (--side_event_description_ptr_registered
)
1960 side_events_unregister(side_events_handle
);
1961 side_events_handle
= NULL
;
1968 #endif /* _SIDE_TRACE_H */