1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 #include <side/macros.h>
15 #include <side/endian.h>
18 * SIDE stands for "Static Instrumentation Dynamically Enabled"
20 * This is an instrumentation API for Linux user-space, which exposes an
21 * instrumentation type system and facilities allowing a kernel or
22 * user-space tracer to consume user-space instrumentation.
24 * This instrumentation API exposes 3 type systems:
26 * * Stack-copy type system: This is the core type system which can
27 * represent all supported types and into which all other type systems
28 * can be nested. This type system requires that every type is
29 * statically or dynamically declared and then registered, thus giving
30 * tracers a complete description of the events and their associated
31 * fields before the associated instrumentation is invoked. The
32 * application needs to copy each argument (side_arg_...()) onto the
33 * stack when calling the instrumentation.
35 * This is the most expressive of the 3 type systems, althrough not the
36 * fastest due to the extra copy of the arguments.
38 * * Data-gathering type system: This type system requires every type to
39 * be statically or dynamically declared and registered, but does not
40 * require the application to copy its arguments onto the stack.
41 * Instead, the type description contains all the required information
42 * to fetch the data from the application memory. The only argument
43 * required from the instrumentation is the base pointer from which
44 * the data should be fetched.
46 * This type system can be used as an event field, or nested within
47 * the stack-copy type system. Nesting of gather-vla within
48 * gather-array and gather-vla types is not allowed.
50 * This type system is has the least overhead of the 3 type systems.
52 * * Dynamic type system: This type system receives both type
53 * description and actual data onto the stack at runtime. It has more
54 * overhead that the 2 other type systems, but does not require a
55 * prior registration of event field description. This makes it useful
56 * for seldom used types which are not performance critical, but for
57 * which registering each individual events would needlessly grow the
58 * number of events to declare and register.
60 * Another use-case for this type system is for use by dynamically
61 * typed language runtimes, where the field type is only known when
62 * the instrumentation is called.
64 * Those dynamic types can be either used as arguments to a variadic
65 * field list, or as on-stack instrumentation argument for a static
66 * type SIDE_TYPE_DYNAMIC place holder in the stack-copy type system.
69 //TODO: as those structures will be ABI, we need to either consider them
70 //fixed forever, or think of a scheme that would allow their binary
71 //representation to be extended if need be.
75 struct side_arg_dynamic
;
76 struct side_arg_dynamic_field
;
77 struct side_arg_dynamic_vla
;
79 struct side_event_field
;
80 struct side_tracer_visitor_ctx
;
81 struct side_tracer_dynamic_struct_visitor_ctx
;
82 struct side_event_description
;
83 struct side_arg_dynamic_struct
;
84 struct side_events_register_handle
;
86 enum side_type_label
{
87 /* Stack-copy basic types */
100 SIDE_TYPE_FLOAT_BINARY16
,
101 SIDE_TYPE_FLOAT_BINARY32
,
102 SIDE_TYPE_FLOAT_BINARY64
,
103 SIDE_TYPE_FLOAT_BINARY128
,
104 SIDE_TYPE_STRING_UTF8
,
105 SIDE_TYPE_STRING_UTF16
,
106 SIDE_TYPE_STRING_UTF32
,
108 /* Stack-copy compound types */
112 SIDE_TYPE_VLA_VISITOR
,
114 /* Stack-copy enumeration types */
116 SIDE_TYPE_ENUM_BITMAP
,
118 /* Stack-copy place holder for dynamic types */
121 /* Gather basic types */
122 SIDE_TYPE_GATHER_BOOL
,
123 SIDE_TYPE_GATHER_INTEGER
,
124 SIDE_TYPE_GATHER_BYTE
,
125 SIDE_TYPE_GATHER_POINTER
,
126 SIDE_TYPE_GATHER_FLOAT
,
127 SIDE_TYPE_GATHER_STRING
,
129 /* Gather compound types */
130 SIDE_TYPE_GATHER_STRUCT
,
131 SIDE_TYPE_GATHER_ARRAY
,
132 SIDE_TYPE_GATHER_VLA
,
134 /* Gather enumeration types */
135 SIDE_TYPE_GATHER_ENUM
,
137 /* Dynamic basic types */
138 SIDE_TYPE_DYNAMIC_NULL
,
139 SIDE_TYPE_DYNAMIC_BOOL
,
140 SIDE_TYPE_DYNAMIC_INTEGER
,
141 SIDE_TYPE_DYNAMIC_BYTE
,
142 SIDE_TYPE_DYNAMIC_POINTER
,
143 SIDE_TYPE_DYNAMIC_FLOAT
,
144 SIDE_TYPE_DYNAMIC_STRING
,
146 /* Dynamic compound types */
147 SIDE_TYPE_DYNAMIC_STRUCT
,
148 SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
,
149 SIDE_TYPE_DYNAMIC_VLA
,
150 SIDE_TYPE_DYNAMIC_VLA_VISITOR
,
153 enum side_attr_type
{
164 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
165 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
166 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
167 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
168 SIDE_ATTR_TYPE_STRING_UTF8
,
169 SIDE_ATTR_TYPE_STRING_UTF16
,
170 SIDE_ATTR_TYPE_STRING_UTF32
,
174 SIDE_LOGLEVEL_EMERG
= 0,
175 SIDE_LOGLEVEL_ALERT
= 1,
176 SIDE_LOGLEVEL_CRIT
= 2,
177 SIDE_LOGLEVEL_ERR
= 3,
178 SIDE_LOGLEVEL_WARNING
= 4,
179 SIDE_LOGLEVEL_NOTICE
= 5,
180 SIDE_LOGLEVEL_INFO
= 6,
181 SIDE_LOGLEVEL_DEBUG
= 7,
184 enum side_visitor_status
{
185 SIDE_VISITOR_STATUS_OK
= 0,
186 SIDE_VISITOR_STATUS_ERROR
= -1,
191 SIDE_ERROR_INVAL
= 1,
192 SIDE_ERROR_EXIST
= 2,
193 SIDE_ERROR_NOMEM
= 3,
194 SIDE_ERROR_NOENT
= 4,
195 SIDE_ERROR_EXITING
= 5,
198 enum side_type_label_byte_order
{
199 SIDE_TYPE_BYTE_ORDER_LE
= 0,
200 SIDE_TYPE_BYTE_ORDER_BE
= 1,
203 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
204 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
206 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
209 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
210 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
212 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
215 enum side_type_gather_access_mode
{
216 SIDE_TYPE_GATHER_ACCESS_DIRECT
,
217 SIDE_TYPE_GATHER_ACCESS_POINTER
, /* Pointer dereference */
220 typedef enum side_visitor_status (*side_visitor_func
)(
221 const struct side_tracer_visitor_ctx
*tracer_ctx
,
223 typedef enum side_visitor_status (*side_dynamic_struct_visitor_func
)(
224 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
227 union side_integer_value
{
239 union side_bool_value
{
241 uint16_t side_bool16
;
242 uint32_t side_bool32
;
243 uint64_t side_bool64
;
246 union side_float_value
{
248 _Float16 side_float_binary16
;
251 _Float32 side_float_binary32
;
254 _Float64 side_float_binary64
;
257 _Float128 side_float_binary128
;
261 struct side_attr_value
{
262 uint32_t type
; /* enum side_attr_type */
265 uint64_t string_value
; /* const { uint8_t, uint16_t, uint32_t } * */
266 union side_integer_value integer_value
;
267 union side_float_value float_value
;
271 struct side_type_raw_string
{
272 const void *p
; /* pointer to string */
273 uint8_t unit_size
; /* 1, 2, or 4 bytes */
274 uint8_t byte_order
; /* enum side_type_label_byte_order */
277 /* User attributes. */
279 const struct side_type_raw_string key
;
280 const struct side_attr_value value
;
283 /* Type descriptions */
284 struct side_type_null
{
285 const struct side_attr
*attr
;
289 struct side_type_bool
{
290 const struct side_attr
*attr
;
292 uint16_t bool_size
; /* bytes */
293 uint16_t len_bits
; /* bits. 0 for (bool_size * CHAR_BITS) */
294 uint8_t byte_order
; /* enum side_type_label_byte_order */
297 struct side_type_byte
{
298 const struct side_attr
*attr
;
302 struct side_type_string
{
303 const struct side_attr
*attr
;
305 uint8_t unit_size
; /* 1, 2, or 4 bytes */
306 uint8_t byte_order
; /* enum side_type_label_byte_order */
309 struct side_type_integer
{
310 const struct side_attr
*attr
;
312 uint16_t integer_size
; /* bytes */
313 uint16_t len_bits
; /* bits. 0 for (integer_size * CHAR_BITS) */
314 uint8_t signedness
; /* true/false */
315 uint8_t byte_order
; /* enum side_type_label_byte_order */
318 struct side_type_float
{
319 const struct side_attr
*attr
;
321 uint16_t float_size
; /* bytes */
322 uint8_t byte_order
; /* enum side_type_label_byte_order */
325 struct side_enum_mapping
{
331 struct side_enum_mappings
{
332 const struct side_enum_mapping
*mappings
;
333 const struct side_attr
*attr
;
334 uint32_t nr_mappings
;
338 struct side_enum_bitmap_mapping
{
339 uint64_t range_begin
;
344 struct side_enum_bitmap_mappings
{
345 const struct side_enum_bitmap_mapping
*mappings
;
346 const struct side_attr
*attr
;
347 uint32_t nr_mappings
;
351 struct side_type_struct
{
352 const struct side_event_field
*fields
;
353 const struct side_attr
*attr
;
358 struct side_type_array
{
359 const struct side_type
*elem_type
;
360 const struct side_attr
*attr
;
365 struct side_type_vla
{
366 const struct side_type
*elem_type
;
367 const struct side_attr
*attr
;
371 struct side_type_vla_visitor
{
372 const struct side_type
*elem_type
;
373 side_visitor_func visitor
;
374 const struct side_attr
*attr
;
378 struct side_type_enum
{
379 const struct side_enum_mappings
*mappings
;
380 const struct side_type
*elem_type
;
383 struct side_type_enum_bitmap
{
384 const struct side_enum_bitmap_mappings
*mappings
;
385 const struct side_type
*elem_type
;
388 struct side_type_gather_bool
{
389 uint64_t offset
; /* bytes */
390 uint8_t access_mode
; /* enum side_type_gather_access_mode */
391 struct side_type_bool type
;
392 uint16_t offset_bits
; /* bits */
395 struct side_type_gather_byte
{
396 uint64_t offset
; /* bytes */
397 uint8_t access_mode
; /* enum side_type_gather_access_mode */
398 struct side_type_byte type
;
401 struct side_type_gather_integer
{
402 uint64_t offset
; /* bytes */
403 uint8_t access_mode
; /* enum side_type_gather_access_mode */
404 struct side_type_integer type
;
405 uint16_t offset_bits
; /* bits */
408 struct side_type_gather_float
{
409 uint64_t offset
; /* bytes */
410 uint8_t access_mode
; /* enum side_type_gather_access_mode */
411 struct side_type_float type
;
414 struct side_type_gather_string
{
415 uint64_t offset
; /* bytes */
416 uint8_t access_mode
; /* enum side_type_gather_access_mode */
417 struct side_type_string type
;
420 struct side_type_gather_enum
{
421 const struct side_enum_mappings
*mappings
;
422 const struct side_type
*elem_type
;
425 struct side_type_gather_struct
{
426 uint64_t offset
; /* bytes */
427 uint8_t access_mode
; /* enum side_type_gather_access_mode */
428 const struct side_type_struct
*type
;
429 uint32_t size
; /* bytes */
432 struct side_type_gather_array
{
433 uint64_t offset
; /* bytes */
434 uint8_t access_mode
; /* enum side_type_gather_access_mode */
435 struct side_type_array type
;
438 struct side_type_gather_vla
{
439 const struct side_type
*length_type
; /* side_length() */
441 uint64_t offset
; /* bytes */
442 uint8_t access_mode
; /* enum side_type_gather_access_mode */
443 struct side_type_vla type
;
446 struct side_type_gather
{
448 struct side_type_gather_bool side_bool
;
449 struct side_type_gather_byte side_byte
;
450 struct side_type_gather_integer side_integer
;
451 struct side_type_gather_float side_float
;
452 struct side_type_gather_string side_string
;
453 struct side_type_gather_enum side_enum
;
454 struct side_type_gather_array side_array
;
455 struct side_type_gather_vla side_vla
;
456 struct side_type_gather_struct side_struct
;
461 uint32_t type
; /* enum side_type_label */
463 /* Stack-copy basic types */
464 struct side_type_null side_null
;
465 struct side_type_bool side_bool
;
466 struct side_type_byte side_byte
;
467 struct side_type_string side_string
;
468 struct side_type_integer side_integer
;
469 struct side_type_float side_float
;
471 /* Stack-copy compound types */
472 struct side_type_array side_array
;
473 struct side_type_vla side_vla
;
474 struct side_type_vla_visitor side_vla_visitor
;
475 const struct side_type_struct
*side_struct
;
477 /* Stack-copy enumeration types */
478 struct side_type_enum side_enum
;
479 struct side_type_enum_bitmap side_enum_bitmap
;
482 struct side_type_gather side_gather
;
486 struct side_event_field
{
487 const char *field_name
;
488 struct side_type side_type
;
491 enum side_event_flags
{
492 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
495 struct side_callback
{
497 void (*call
)(const struct side_event_description
*desc
,
498 const struct side_arg_vec
*side_arg_vec
,
500 void (*call_variadic
)(const struct side_event_description
*desc
,
501 const struct side_arg_vec
*side_arg_vec
,
502 const struct side_arg_dynamic_struct
*var_struct
,
508 struct side_arg_static
{
509 /* Stack-copy basic types */
510 union side_bool_value bool_value
;
512 uint64_t string_value
; /* const {uint8_t, uint16_t, uint32_t} * */
513 union side_integer_value integer_value
;
514 union side_float_value float_value
;
516 /* Stack-copy compound types */
517 const struct side_arg_vec
*side_struct
;
518 const struct side_arg_vec
*side_array
;
519 const struct side_arg_vec
*side_vla
;
520 void *side_vla_app_visitor_ctx
;
522 /* Gather basic types */
523 void *side_bool_gather_ptr
;
524 void *side_byte_gather_ptr
;
525 void *side_integer_gather_ptr
;
526 void *side_float_gather_ptr
;
527 void *side_string_gather_ptr
;
529 /* Gather compound types */
530 void *side_array_gather_ptr
;
531 void *side_struct_gather_ptr
;
535 } SIDE_PACKED side_vla_gather
;
538 struct side_arg_dynamic_vla
{
539 const struct side_arg
*sav
;
540 const struct side_attr
*attr
;
545 struct side_arg_dynamic_struct
{
546 const struct side_arg_dynamic_field
*fields
;
547 const struct side_attr
*attr
;
552 struct side_dynamic_struct_visitor
{
554 side_dynamic_struct_visitor_func visitor
;
555 const struct side_attr
*attr
;
559 struct side_dynamic_vla_visitor
{
561 side_visitor_func visitor
;
562 const struct side_attr
*attr
;
566 struct side_arg_dynamic
{
567 /* Dynamic basic types */
568 struct side_type_null side_null
;
570 struct side_type_bool type
;
571 union side_bool_value value
;
572 } SIDE_PACKED side_bool
;
574 struct side_type_byte type
;
576 } SIDE_PACKED side_byte
;
578 struct side_type_string type
;
579 uint64_t value
; /* const char * */
580 } SIDE_PACKED side_string
;
582 struct side_type_integer type
;
583 union side_integer_value value
;
584 } SIDE_PACKED side_integer
;
586 struct side_type_float type
;
587 union side_float_value value
;
588 } SIDE_PACKED side_float
;
590 /* Dynamic compound types */
591 const struct side_arg_dynamic_struct
*side_dynamic_struct
;
592 const struct side_arg_dynamic_vla
*side_dynamic_vla
;
594 struct side_dynamic_struct_visitor side_dynamic_struct_visitor
;
595 struct side_dynamic_vla_visitor side_dynamic_vla_visitor
;
599 uint32_t type
; /* enum side_type_label */
601 struct side_arg_static side_static
;
602 struct side_arg_dynamic side_dynamic
;
606 struct side_arg_vec
{
607 const struct side_arg
*sav
;
611 struct side_arg_dynamic_field
{
612 const char *field_name
;
613 const struct side_arg elem
;
616 /* The visitor pattern is a double-dispatch visitor. */
617 struct side_tracer_visitor_ctx
{
618 enum side_visitor_status (*write_elem
)(
619 const struct side_tracer_visitor_ctx
*tracer_ctx
,
620 const struct side_arg
*elem
);
621 void *priv
; /* Private tracer context. */
624 struct side_tracer_dynamic_struct_visitor_ctx
{
625 enum side_visitor_status (*write_field
)(
626 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
627 const struct side_arg_dynamic_field
*dynamic_field
);
628 void *priv
; /* Private tracer context. */
631 struct side_event_description
{
633 const char *provider_name
;
634 const char *event_name
;
635 const struct side_event_field
*fields
;
636 const struct side_attr
*attr
;
637 const struct side_callback
*callbacks
;
640 uint32_t loglevel
; /* enum side_loglevel */
643 uint32_t nr_callbacks
;
646 /* Event and type attributes */
648 #define side_attr(_key, _value) \
652 .unit_size = sizeof(uint8_t), \
653 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
655 .value = SIDE_PARAM(_value), \
658 #define side_attr_list(...) \
659 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
661 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
662 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
663 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
664 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
665 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
666 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
667 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
668 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
669 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
670 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
671 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
672 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
673 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
674 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
675 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING_UTF8, .u = { .string_value = (uintptr_t) (_val) } }
676 #define side_attr_string16(_val) { .type = SIDE_ATTR_TYPE_STRING_UTF16, .u = { .string_value = (uintptr_t) (_val) } }
677 #define side_attr_string32(_val) { .type = SIDE_ATTR_TYPE_STRING_UTF32, .u = { .string_value = (uintptr_t) (_val) } }
679 /* Stack-copy enumeration type definitions */
681 #define side_define_enum(_identifier, _mappings, _attr) \
682 const struct side_enum_mappings _identifier = { \
683 .mappings = _mappings, \
685 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
686 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
689 #define side_enum_mapping_list(...) \
690 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
692 #define side_enum_mapping_range(_label, _begin, _end) \
694 .range_begin = _begin, \
699 #define side_enum_mapping_value(_label, _value) \
701 .range_begin = _value, \
702 .range_end = _value, \
706 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
707 const struct side_enum_bitmap_mappings _identifier = { \
708 .mappings = _mappings, \
710 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
711 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
714 #define side_enum_bitmap_mapping_list(...) \
715 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
717 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
719 .range_begin = _begin, \
724 #define side_enum_bitmap_mapping_value(_label, _value) \
726 .range_begin = _value, \
727 .range_end = _value, \
731 /* Stack-copy field and type definitions */
733 #define side_type_null(_attr) \
735 .type = SIDE_TYPE_NULL, \
739 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
744 #define side_type_bool(_attr) \
746 .type = SIDE_TYPE_BOOL, \
750 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
751 .bool_size = sizeof(uint8_t), \
753 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
758 #define side_type_byte(_attr) \
760 .type = SIDE_TYPE_BYTE, \
764 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
769 #define _side_type_string(_type, _byte_order, _unit_size, _attr) \
775 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
776 .unit_size = _unit_size, \
777 .byte_order = _byte_order, \
782 #define side_type_dynamic() \
784 .type = SIDE_TYPE_DYNAMIC, \
787 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
793 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
794 .integer_size = _integer_size, \
795 .len_bits = _len_bits, \
796 .signedness = _signedness, \
797 .byte_order = _byte_order, \
802 #define _side_type_float(_type, _byte_order, _float_size, _attr) \
808 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
809 .float_size = _float_size, \
810 .byte_order = _byte_order, \
815 #define _side_field(_name, _type) \
817 .field_name = _name, \
818 .side_type = _type, \
822 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM(_attr))
823 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
824 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), 0, SIDE_PARAM(_attr))
825 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint64_t), 0, SIDE_PARAM(_attr))
826 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM(_attr))
827 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int16_t), 0, SIDE_PARAM(_attr))
828 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int32_t), 0, SIDE_PARAM(_attr))
829 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int64_t), 0, SIDE_PARAM(_attr))
830 #define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uintptr_t), 0, SIDE_PARAM(_attr))
831 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float16), SIDE_PARAM(_attr))
832 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), SIDE_PARAM(_attr))
833 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), SIDE_PARAM(_attr))
834 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), SIDE_PARAM(_attr))
835 #define side_type_string(_attr) _side_type_string(SIDE_TYPE_STRING_UTF8, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM(_attr))
836 #define side_type_string16(_attr) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM(_attr))
837 #define side_type_string32(_attr) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM(_attr))
839 #define side_field_null(_name, _attr) _side_field(_name, side_type_null(SIDE_PARAM(_attr)))
840 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
841 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
842 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
843 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
844 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
845 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
846 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
847 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
848 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
849 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
850 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
851 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
852 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
853 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
854 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
855 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
856 #define side_field_string16(_name, _attr) _side_field(_name, side_type_string16(SIDE_PARAM(_attr)))
857 #define side_field_string32(_name, _attr) _side_field(_name, side_type_string32(SIDE_PARAM(_attr)))
858 #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic())
861 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
862 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), 0, SIDE_PARAM(_attr))
863 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint64_t), 0, SIDE_PARAM(_attr))
864 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int16_t), 0, SIDE_PARAM(_attr))
865 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int32_t), 0, SIDE_PARAM(_attr))
866 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int64_t), 0, SIDE_PARAM(_attr))
867 #define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uintptr_t), 0, SIDE_PARAM(_attr))
868 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float16), SIDE_PARAM(_attr))
869 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float32), SIDE_PARAM(_attr))
870 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float64), SIDE_PARAM(_attr))
871 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float128), SIDE_PARAM(_attr))
872 #define side_type_string16_le(_attr) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM(_attr))
873 #define side_type_string32_le(_attr) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM(_attr))
875 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
876 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
877 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
878 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
879 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
880 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
881 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
882 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
883 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
884 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
885 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
886 #define side_field_string16_le(_name, _attr) _side_field(_name, side_type_string16_le(SIDE_PARAM(_attr)))
887 #define side_field_string32_le(_name, _attr) _side_field(_name, side_type_string32_le(SIDE_PARAM(_attr)))
890 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
891 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), 0, SIDE_PARAM(_attr))
892 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint64_t), 0, SIDE_PARAM(_attr))
893 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int16_t), 0, SIDE_PARAM(_attr))
894 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int32_t), 0, SIDE_PARAM(_attr))
895 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int64_t), 0, SIDE_PARAM(_attr))
896 #define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uintptr_t), 0, SIDE_PARAM(_attr))
897 #define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float16), SIDE_PARAM(_attr))
898 #define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float32), SIDE_PARAM(_attr))
899 #define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float64), SIDE_PARAM(_attr))
900 #define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float128), SIDE_PARAM(_attr))
901 #define side_type_string16_be(_attr) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM(_attr))
902 #define side_type_string32_be(_attr) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM(_attr))
904 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
905 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
906 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
907 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
908 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
909 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
910 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
911 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
912 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
913 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
914 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
915 #define side_field_string16_be(_name, _attr) _side_field(_name, side_type_string16_be(SIDE_PARAM(_attr)))
916 #define side_field_string32_be(_name, _attr) _side_field(_name, side_type_string32_be(SIDE_PARAM(_attr)))
918 #define side_type_enum(_mappings, _elem_type) \
920 .type = SIDE_TYPE_ENUM, \
923 .mappings = _mappings, \
924 .elem_type = _elem_type, \
928 #define side_field_enum(_name, _mappings, _elem_type) \
929 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
931 #define side_type_enum_bitmap(_mappings, _elem_type) \
933 .type = SIDE_TYPE_ENUM_BITMAP, \
935 .side_enum_bitmap = { \
936 .mappings = _mappings, \
937 .elem_type = _elem_type, \
941 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
942 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
944 #define side_type_struct(_struct) \
946 .type = SIDE_TYPE_STRUCT, \
948 .side_struct = _struct, \
951 #define side_field_struct(_name, _struct) \
952 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
954 #define _side_type_struct_define(_fields, _attr) \
958 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
959 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
962 #define side_define_struct(_identifier, _fields, _attr) \
963 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
965 #define side_struct_literal(_fields, _attr) \
966 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
967 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
969 #define side_type_array(_elem_type, _length, _attr) \
971 .type = SIDE_TYPE_ARRAY, \
974 .elem_type = _elem_type, \
977 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
981 #define side_field_array(_name, _elem_type, _length, _attr) \
982 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
984 #define side_type_vla(_elem_type, _attr) \
986 .type = SIDE_TYPE_VLA, \
989 .elem_type = _elem_type, \
991 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
995 #define side_field_vla(_name, _elem_type, _attr) \
996 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
998 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
1000 .type = SIDE_TYPE_VLA_VISITOR, \
1002 .side_vla_visitor = { \
1003 .elem_type = SIDE_PARAM(_elem_type), \
1004 .visitor = _visitor, \
1006 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1010 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
1011 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
1013 /* Gather field and type definitions */
1015 #define side_type_gather_byte(_offset, _access_mode, _attr) \
1017 .type = SIDE_TYPE_GATHER_BYTE, \
1022 .offset = _offset, \
1023 .access_mode = _access_mode, \
1026 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1033 #define side_field_gather_byte(_name, _offset, _access_mode, _attr) \
1034 _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM(_attr)))
1036 #define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1038 .type = SIDE_TYPE_GATHER_BOOL, \
1043 .offset = _offset, \
1044 .access_mode = _access_mode, \
1047 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1048 .bool_size = _bool_size, \
1049 .len_bits = _len_bits, \
1050 .byte_order = _byte_order, \
1052 .offset_bits = _offset_bits, \
1058 #define side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1059 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_HOST, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1060 #define side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1061 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_LE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1062 #define side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1063 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_BE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1065 #define side_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1066 _side_field(_name, side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1067 #define side_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1068 _side_field(_name, side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1069 #define side_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1070 _side_field(_name, side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1072 #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
1073 _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1080 .offset = _offset, \
1081 .access_mode = _access_mode, \
1084 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1085 .integer_size = _integer_size, \
1086 .len_bits = _len_bits, \
1087 .signedness = _signedness, \
1088 .byte_order = _byte_order, \
1090 .offset_bits = _offset_bits, \
1097 #define side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1098 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1099 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1100 #define side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1101 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, \
1102 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1104 #define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1105 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_LE, \
1106 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1107 #define side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1108 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_LE, \
1109 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1111 #define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1112 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_BE, \
1113 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1114 #define side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1115 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_BE, \
1116 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1118 #define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1119 _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1120 #define side_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1121 _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1123 #define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1124 _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1125 #define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1126 _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1128 #define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1129 _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1130 #define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1131 _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1133 #define side_type_gather_pointer(_offset, _access_mode, _attr) \
1134 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1135 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM(_attr))
1136 #define side_field_gather_pointer(_name, _offset, _access_mode, _attr) \
1137 _side_field(_name, side_type_gather_pointer(_offset, _access_mode, SIDE_PARAM(_attr)))
1139 #define side_type_gather_pointer_le(_offset, _access_mode, _attr) \
1140 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, \
1141 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM(_attr))
1142 #define side_field_gather_pointer_le(_name, _offset, _access_mode, _attr) \
1143 _side_field(_name, side_type_gather_pointer_le(_offset, _access_mode, SIDE_PARAM(_attr)))
1145 #define side_type_gather_pointer_be(_offset, _access_mode, _attr) \
1146 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, \
1147 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM(_attr))
1148 #define side_field_gather_pointer_be(_name, _offset, _access_mode, _attr) \
1149 _side_field(_name, side_type_gather_pointer_be(_offset, _access_mode, SIDE_PARAM(_attr)))
1151 #define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr) \
1153 .type = SIDE_TYPE_GATHER_FLOAT, \
1158 .offset = _offset, \
1159 .access_mode = _access_mode, \
1162 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1163 .float_size = _float_size, \
1164 .byte_order = _byte_order, \
1172 #define side_type_gather_float(_offset, _float_size, _access_mode, _attr) \
1173 _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, _attr)
1174 #define side_type_gather_float_le(_offset, _float_size, _access_mode, _attr) \
1175 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, _attr)
1176 #define side_type_gather_float_be(_offset, _float_size, _access_mode, _attr) \
1177 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, _attr)
1179 #define side_field_gather_float(_name, _offset, _float_size, _access_mode, _attr) \
1180 _side_field(_name, side_type_gather_float(_offset, _float_size, _access_mode, _attr))
1181 #define side_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr) \
1182 _side_field(_name, side_type_gather_float_le(_offset, _float_size, _access_mode, _attr))
1183 #define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr) \
1184 _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, _attr))
1186 #define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr) \
1188 .type = SIDE_TYPE_GATHER_STRING, \
1193 .offset = _offset, \
1194 .access_mode = _access_mode, \
1197 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1198 .unit_size = _unit_size, \
1199 .byte_order = _byte_order, \
1206 #define side_type_gather_string(_offset, _access_mode, _attr) \
1207 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, SIDE_PARAM(_attr))
1208 #define side_field_gather_string(_name, _offset, _access_mode, _attr) \
1209 _side_field(_name, side_type_gather_string(_offset, _access_mode, SIDE_PARAM(_attr)))
1211 #define side_type_gather_string16(_offset, _access_mode, _attr) \
1212 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, SIDE_PARAM(_attr))
1213 #define side_type_gather_string16_le(_offset, _access_mode, _attr) \
1214 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, SIDE_PARAM(_attr))
1215 #define side_type_gather_string16_be(_offset, _access_mode, _attr) \
1216 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, SIDE_PARAM(_attr))
1218 #define side_field_gather_string16(_name, _offset, _access_mode, _attr) \
1219 _side_field(_name, side_type_gather_string16(_offset, _access_mode, SIDE_PARAM(_attr)))
1220 #define side_field_gather_string16_le(_name, _offset, _access_mode, _attr) \
1221 _side_field(_name, side_type_gather_string16_le(_offset, _access_mode, SIDE_PARAM(_attr)))
1222 #define side_field_gather_string16_be(_name, _offset, _access_mode, _attr) \
1223 _side_field(_name, side_type_gather_string16_be(_offset, _access_mode, SIDE_PARAM(_attr)))
1225 #define side_type_gather_string32(_offset, _access_mode, _attr) \
1226 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, SIDE_PARAM(_attr))
1227 #define side_type_gather_string32_le(_offset, _access_mode, _attr) \
1228 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, SIDE_PARAM(_attr))
1229 #define side_type_gather_string32_be(_offset, _access_mode, _attr) \
1230 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, SIDE_PARAM(_attr))
1232 #define side_field_gather_string32(_name, _offset, _access_mode, _attr) \
1233 _side_field(_name, side_type_gather_string32(_offset, _access_mode, SIDE_PARAM(_attr)))
1234 #define side_field_gather_string32_le(_name, _offset, _access_mode, _attr) \
1235 _side_field(_name, side_type_gather_string32_le(_offset, _access_mode, SIDE_PARAM(_attr)))
1236 #define side_field_gather_string32_be(_name, _offset, _access_mode, _attr) \
1237 _side_field(_name, side_type_gather_string32_be(_offset, _access_mode, SIDE_PARAM(_attr)))
1239 #define side_type_gather_enum(_mappings, _elem_type) \
1241 .type = SIDE_TYPE_GATHER_ENUM, \
1244 .mappings = _mappings, \
1245 .elem_type = _elem_type, \
1249 #define side_field_gather_enum(_name, _mappings, _elem_type) \
1250 _side_field(_name, side_type_gather_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1252 #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
1254 .type = SIDE_TYPE_GATHER_STRUCT, \
1259 .offset = _offset, \
1260 .access_mode = _access_mode, \
1261 .type = _struct_gather, \
1268 #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \
1269 _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode))
1271 #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr) \
1273 .type = SIDE_TYPE_GATHER_ARRAY, \
1278 .offset = _offset, \
1279 .access_mode = _access_mode, \
1281 .elem_type = _elem_type_gather, \
1283 .length = _length, \
1284 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1291 #define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr) \
1292 _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM(_attr)))
1294 #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1296 .type = SIDE_TYPE_GATHER_VLA, \
1301 .length_type = _length_type_gather, \
1302 .offset = _offset, \
1303 .access_mode = _access_mode, \
1305 .elem_type = _elem_type_gather, \
1307 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1314 #define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1315 _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM(_attr)))
1317 #define side_elem(...) \
1318 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1320 #define side_length(...) \
1321 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1323 #define side_field_list(...) \
1324 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
1326 /* Stack-copy field arguments */
1328 #define side_arg_null(_val) { .type = SIDE_TYPE_NULL }
1329 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } }
1330 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_static = { .byte_value = (_val) } } }
1331 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING_UTF8, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1332 #define side_arg_string16(_val) { .type = SIDE_TYPE_STRING_UTF16, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1333 #define side_arg_string32(_val) { .type = SIDE_TYPE_STRING_UTF32, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1335 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1336 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1337 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1338 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1339 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
1340 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
1341 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
1342 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
1343 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER, .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } }
1344 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
1345 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
1346 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
1347 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
1349 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = (_side_type) } } }
1350 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
1351 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
1352 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
1354 /* Gather field arguments */
1356 #define side_arg_gather_bool(_ptr) { .type = SIDE_TYPE_GATHER_BOOL, .u = { .side_static = { .side_bool_gather_ptr = (_ptr) } } }
1357 #define side_arg_gather_byte(_ptr) { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = (_ptr) } } }
1358 #define side_arg_gather_pointer(_ptr) { .type = SIDE_TYPE_GATHER_POINTER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1359 #define side_arg_gather_integer(_ptr) { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1360 #define side_arg_gather_float(_ptr) { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = (_ptr) } } }
1361 #define side_arg_gather_string(_ptr) { .type = SIDE_TYPE_GATHER_STRING, .u = { .side_static = { .side_string_gather_ptr = (_ptr) } } }
1362 #define side_arg_gather_struct(_ptr) { .type = SIDE_TYPE_GATHER_STRUCT, .u = { .side_static = { .side_struct_gather_ptr = (_ptr) } } }
1363 #define side_arg_gather_array(_ptr) { .type = SIDE_TYPE_GATHER_ARRAY, .u = { .side_static = { .side_array_gather_ptr = (_ptr) } } }
1364 #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) } } } }
1366 /* Dynamic field arguments */
1368 #define side_arg_dynamic_null(_attr) \
1370 .type = SIDE_TYPE_DYNAMIC_NULL, \
1375 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1381 #define side_arg_dynamic_bool(_val, _attr) \
1383 .type = SIDE_TYPE_DYNAMIC_BOOL, \
1389 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1390 .bool_size = sizeof(uint8_t), \
1392 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
1395 .side_bool8 = !!(_val), \
1402 #define side_arg_dynamic_byte(_val, _attr) \
1404 .type = SIDE_TYPE_DYNAMIC_BYTE, \
1410 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1417 #define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr) \
1419 .type = SIDE_TYPE_DYNAMIC_STRING, \
1425 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1426 .unit_size = _unit_size, \
1427 .byte_order = _byte_order, \
1429 .value = (uintptr_t) (_val), \
1434 #define side_arg_dynamic_string(_val, _attr) \
1435 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM(_attr))
1436 #define side_arg_dynamic_string16(_val, _attr) \
1437 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM(_attr))
1438 #define side_arg_dynamic_string16_le(_val, _attr) \
1439 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM(_attr))
1440 #define side_arg_dynamic_string16_be(_val, _attr) \
1441 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM(_attr))
1442 #define side_arg_dynamic_string32(_val, _attr) \
1443 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM(_attr))
1444 #define side_arg_dynamic_string32_le(_val, _attr) \
1445 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM(_attr))
1446 #define side_arg_dynamic_string32_be(_val, _attr) \
1447 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM(_attr))
1449 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
1457 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1458 .integer_size = _integer_size, \
1459 .len_bits = _len_bits, \
1460 .signedness = _signedness, \
1461 .byte_order = _byte_order, \
1471 #define side_arg_dynamic_u8(_val, _attr) \
1472 _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM(_attr))
1473 #define side_arg_dynamic_s8(_val, _attr) \
1474 _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM(_attr))
1476 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1477 _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
1478 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1479 _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint32_t), 0, SIDE_PARAM(_attr))
1480 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1481 _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint64_t), 0, SIDE_PARAM(_attr))
1483 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1484 _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int16_t), 0, SIDE_PARAM(_attr))
1485 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1486 _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int32_t), 0, SIDE_PARAM(_attr))
1487 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1488 _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int64_t), 0, SIDE_PARAM(_attr))
1490 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1491 _side_arg_dynamic_integer(.side_uptr, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER, false, _byte_order, \
1492 sizeof(uintptr_t), 0, SIDE_PARAM(_attr))
1494 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr) \
1502 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1503 .float_size = _float_size, \
1504 .byte_order = _byte_order, \
1514 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1515 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), SIDE_PARAM(_attr))
1516 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1517 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), SIDE_PARAM(_attr))
1518 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1519 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), SIDE_PARAM(_attr))
1520 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1521 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), SIDE_PARAM(_attr))
1524 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1525 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1526 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1527 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1528 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1529 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1530 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1531 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1532 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1533 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1534 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1537 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1538 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1539 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1540 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1541 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1542 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1543 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1544 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1545 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1546 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1547 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1550 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1551 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1552 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1553 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1554 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1555 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1556 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1557 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1558 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1559 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1560 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1562 #define side_arg_dynamic_vla(_vla) \
1564 .type = SIDE_TYPE_DYNAMIC_VLA, \
1567 .side_dynamic_vla = (_vla), \
1572 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1574 .type = SIDE_TYPE_DYNAMIC_VLA_VISITOR, \
1577 .side_dynamic_vla_visitor = { \
1579 .visitor = _dynamic_vla_visitor, \
1581 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1587 #define side_arg_dynamic_struct(_struct) \
1589 .type = SIDE_TYPE_DYNAMIC_STRUCT, \
1592 .side_dynamic_struct = (_struct), \
1597 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1599 .type = SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, \
1602 .side_dynamic_struct_visitor = { \
1604 .visitor = _dynamic_struct_visitor, \
1606 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1612 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1613 const struct side_arg _identifier##_vec[] = { _sav }; \
1614 const struct side_arg_dynamic_vla _identifier = { \
1615 .sav = _identifier##_vec, \
1617 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1618 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1621 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1622 const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \
1623 const struct side_arg_dynamic_struct _identifier = { \
1624 .fields = _identifier##_fields, \
1626 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1627 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1630 #define side_arg_define_vec(_identifier, _sav) \
1631 const struct side_arg _identifier##_vec[] = { _sav }; \
1632 const struct side_arg_vec _identifier = { \
1633 .sav = _identifier##_vec, \
1634 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1637 #define side_arg_dynamic_field(_name, _elem) \
1639 .field_name = _name, \
1644 * Event instrumentation description registration, runtime enabled state
1645 * check, and instrumentation invocation.
1648 #define side_arg_list(...) __VA_ARGS__
1650 #define side_event_cond(_identifier) \
1651 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1654 #define side_event_call(_identifier, _sav) \
1656 const struct side_arg side_sav[] = { _sav }; \
1657 const struct side_arg_vec side_arg_vec = { \
1659 .len = SIDE_ARRAY_SIZE(side_sav), \
1661 side_call(&(_identifier), &side_arg_vec); \
1664 #define side_event(_identifier, _sav) \
1665 side_event_cond(_identifier) \
1666 side_event_call(_identifier, SIDE_PARAM(_sav))
1668 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1670 const struct side_arg side_sav[] = { _sav }; \
1671 const struct side_arg_vec side_arg_vec = { \
1673 .len = SIDE_ARRAY_SIZE(side_sav), \
1675 const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \
1676 const struct side_arg_dynamic_struct var_struct = { \
1677 .fields = side_fields, \
1679 .len = SIDE_ARRAY_SIZE(side_fields), \
1680 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1682 side_call_variadic(&(_identifier), &side_arg_vec, &var_struct); \
1685 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1686 side_event_cond(_identifier) \
1687 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1689 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1690 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1691 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1693 .enabled = &(side_event_enable__##_identifier), \
1694 .provider_name = _provider, \
1695 .event_name = _event, \
1696 .fields = _fields, \
1698 .callbacks = &side_empty_callback, \
1699 .flags = (_flags), \
1701 .loglevel = _loglevel, \
1702 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1703 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1704 .nr_callbacks = 0, \
1706 static const struct side_event_description *side_event_ptr__##_identifier \
1707 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1709 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1710 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1711 SIDE_PARAM(_attr), 0)
1713 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1714 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1715 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1717 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1718 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1719 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0)
1721 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1722 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1723 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1725 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1726 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1727 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0)
1729 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1730 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1731 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1733 #define side_declare_event(_identifier) \
1734 extern uintptr_t side_event_enable_##_identifier; \
1735 extern struct side_event_description _identifier
1741 extern const struct side_callback side_empty_callback
;
1743 void side_call(const struct side_event_description
*desc
,
1744 const struct side_arg_vec
*side_arg_vec
);
1745 void side_call_variadic(const struct side_event_description
*desc
,
1746 const struct side_arg_vec
*side_arg_vec
,
1747 const struct side_arg_dynamic_struct
*var_struct
);
1749 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
,
1750 uint32_t nr_events
);
1751 void side_events_unregister(struct side_events_register_handle
*handle
);
1754 * Userspace tracer registration API. This allows userspace tracers to
1755 * register event notification callbacks to be notified of the currently
1756 * registered instrumentation, and to register their callbacks to
1759 typedef void (*side_tracer_callback_func
)(const struct side_event_description
*desc
,
1760 const struct side_arg_vec
*side_arg_vec
,
1762 typedef void (*side_tracer_callback_variadic_func
)(const struct side_event_description
*desc
,
1763 const struct side_arg_vec
*side_arg_vec
,
1764 const struct side_arg_dynamic_struct
*var_struct
,
1767 int side_tracer_callback_register(struct side_event_description
*desc
,
1768 side_tracer_callback_func call
,
1770 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1771 side_tracer_callback_variadic_func call_variadic
,
1773 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1774 side_tracer_callback_func call
,
1776 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1777 side_tracer_callback_variadic_func call_variadic
,
1780 enum side_tracer_notification
{
1781 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1782 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1785 /* Callback is invoked with side library internal lock held. */
1786 struct side_tracer_handle
*side_tracer_event_notification_register(
1787 void (*cb
)(enum side_tracer_notification notif
,
1788 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1790 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1793 * Explicit hooks to initialize/finalize the side instrumentation
1794 * library. Those are also library constructor/destructor.
1796 void side_init(void);
1797 void side_exit(void);
1800 * The following constructors/destructors perform automatic registration
1801 * of the declared side events. Those may have to be called explicitly
1802 * in a statically linked library.
1806 * These weak symbols, the constructor, and destructor take care of
1807 * registering only _one_ instance of the side instrumentation per
1808 * shared-ojbect (or for the whole main program).
1810 extern struct side_event_description
* __start_side_event_description_ptr
[]
1811 __attribute__((weak
, visibility("hidden")));
1812 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1813 __attribute__((weak
, visibility("hidden")));
1814 int side_event_description_ptr_registered
1815 __attribute__((weak
, visibility("hidden")));
1816 struct side_events_register_handle
*side_events_handle
1817 __attribute__((weak
, visibility("hidden")));
1820 side_event_description_ptr_init(void)
1821 __attribute__((no_instrument_function
))
1822 __attribute__((constructor
));
1824 side_event_description_ptr_init(void)
1826 if (side_event_description_ptr_registered
++)
1828 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1829 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1833 side_event_description_ptr_exit(void)
1834 __attribute__((no_instrument_function
))
1835 __attribute__((destructor
));
1837 side_event_description_ptr_exit(void)
1839 if (--side_event_description_ptr_registered
)
1841 side_events_unregister(side_events_handle
);
1842 side_events_handle
= NULL
;
1849 #endif /* _SIDE_TRACE_H */