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 */
101 SIDE_TYPE_FLOAT_BINARY16
,
102 SIDE_TYPE_FLOAT_BINARY32
,
103 SIDE_TYPE_FLOAT_BINARY64
,
104 SIDE_TYPE_FLOAT_BINARY128
,
107 /* Stack-copy compound types */
111 SIDE_TYPE_VLA_VISITOR
,
121 SIDE_TYPE_ARRAY_BYTE
,
122 SIDE_TYPE_ARRAY_POINTER32
,
123 SIDE_TYPE_ARRAY_POINTER64
,
134 SIDE_TYPE_VLA_POINTER32
,
135 SIDE_TYPE_VLA_POINTER64
,
137 /* Stack-copy enumeration types */
139 SIDE_TYPE_ENUM_BITMAP
,
141 /* Stack-copy place holder for dynamic types */
144 /* Gather basic types */
145 SIDE_TYPE_GATHER_BOOL
,
146 SIDE_TYPE_GATHER_UNSIGNED_INT
,
147 SIDE_TYPE_GATHER_SIGNED_INT
,
148 SIDE_TYPE_GATHER_BYTE
,
149 SIDE_TYPE_GATHER_FLOAT
,
151 /* Gather compound types */
152 SIDE_TYPE_GATHER_STRUCT
,
153 SIDE_TYPE_GATHER_ARRAY
,
154 SIDE_TYPE_GATHER_VLA
,
156 /* Dynamic basic types */
157 SIDE_TYPE_DYNAMIC_NULL
,
158 SIDE_TYPE_DYNAMIC_BOOL
,
159 SIDE_TYPE_DYNAMIC_U8
,
160 SIDE_TYPE_DYNAMIC_U16
,
161 SIDE_TYPE_DYNAMIC_U32
,
162 SIDE_TYPE_DYNAMIC_U64
,
163 SIDE_TYPE_DYNAMIC_S8
,
164 SIDE_TYPE_DYNAMIC_S16
,
165 SIDE_TYPE_DYNAMIC_S32
,
166 SIDE_TYPE_DYNAMIC_S64
,
167 SIDE_TYPE_DYNAMIC_BYTE
,
168 SIDE_TYPE_DYNAMIC_POINTER32
,
169 SIDE_TYPE_DYNAMIC_POINTER64
,
170 SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
,
171 SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
,
172 SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
,
173 SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
,
174 SIDE_TYPE_DYNAMIC_STRING
,
176 /* Dynamic compound types */
177 SIDE_TYPE_DYNAMIC_STRUCT
,
178 SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
,
179 SIDE_TYPE_DYNAMIC_VLA
,
180 SIDE_TYPE_DYNAMIC_VLA_VISITOR
,
183 enum side_attr_type
{
194 SIDE_ATTR_TYPE_POINTER32
,
195 SIDE_ATTR_TYPE_POINTER64
,
196 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
197 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
198 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
199 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
200 SIDE_ATTR_TYPE_STRING
,
204 SIDE_LOGLEVEL_EMERG
= 0,
205 SIDE_LOGLEVEL_ALERT
= 1,
206 SIDE_LOGLEVEL_CRIT
= 2,
207 SIDE_LOGLEVEL_ERR
= 3,
208 SIDE_LOGLEVEL_WARNING
= 4,
209 SIDE_LOGLEVEL_NOTICE
= 5,
210 SIDE_LOGLEVEL_INFO
= 6,
211 SIDE_LOGLEVEL_DEBUG
= 7,
214 enum side_visitor_status
{
215 SIDE_VISITOR_STATUS_OK
= 0,
216 SIDE_VISITOR_STATUS_ERROR
= -1,
221 SIDE_ERROR_INVAL
= 1,
222 SIDE_ERROR_EXIST
= 2,
223 SIDE_ERROR_NOMEM
= 3,
224 SIDE_ERROR_NOENT
= 4,
225 SIDE_ERROR_EXITING
= 5,
228 enum side_type_label_byte_order
{
229 SIDE_TYPE_BYTE_ORDER_LE
= 0,
230 SIDE_TYPE_BYTE_ORDER_BE
= 1,
233 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
234 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
236 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
239 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
240 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
242 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
245 enum side_type_gather_access_mode
{
246 SIDE_TYPE_GATHER_ACCESS_DIRECT
,
247 SIDE_TYPE_GATHER_ACCESS_POINTER
, /* Pointer dereference */
250 typedef enum side_visitor_status (*side_visitor_func
)(
251 const struct side_tracer_visitor_ctx
*tracer_ctx
,
253 typedef enum side_visitor_status (*side_dynamic_struct_visitor_func
)(
254 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
257 union side_integer_value
{
268 union side_float_value
{
270 _Float16 side_float_binary16
;
273 _Float32 side_float_binary32
;
276 _Float64 side_float_binary64
;
279 _Float128 side_float_binary128
;
283 struct side_attr_value
{
284 uint32_t type
; /* enum side_attr_type */
287 uint64_t string_value
; /* const char * */
288 union side_integer_value integer_value
;
289 union side_float_value float_value
;
293 /* User attributes. */
296 const struct side_attr_value value
;
299 /* Type descriptions */
300 struct side_type_null
{
301 const struct side_attr
*attr
;
305 struct side_type_bool
{
306 const struct side_attr
*attr
;
308 uint16_t bool_size_bits
; /* bits */
309 uint16_t len_bits
; /* bits */
310 uint8_t byte_order
; /* enum side_type_label_byte_order */
313 struct side_type_byte
{
314 const struct side_attr
*attr
;
318 struct side_type_string
{
319 const struct side_attr
*attr
;
323 struct side_type_integer
{
324 const struct side_attr
*attr
;
326 uint16_t integer_size_bits
; /* bits */
327 uint16_t len_bits
; /* bits */
328 uint8_t signedness
; /* true/false */
329 uint8_t byte_order
; /* enum side_type_label_byte_order */
332 struct side_type_float
{
333 const struct side_attr
*attr
;
335 uint16_t float_size_bits
; /* bits */
336 uint8_t byte_order
; /* enum side_type_label_byte_order */
339 struct side_enum_mapping
{
345 struct side_enum_mappings
{
346 const struct side_enum_mapping
*mappings
;
347 const struct side_attr
*attr
;
348 uint32_t nr_mappings
;
352 struct side_enum_bitmap_mapping
{
353 uint64_t range_begin
;
358 struct side_enum_bitmap_mappings
{
359 const struct side_enum_bitmap_mapping
*mappings
;
360 const struct side_attr
*attr
;
361 uint32_t nr_mappings
;
365 struct side_type_struct
{
366 const struct side_event_field
*fields
;
367 const struct side_attr
*attr
;
372 struct side_type_array
{
373 const struct side_type
*elem_type
;
374 const struct side_attr
*attr
;
379 struct side_type_vla
{
380 const struct side_type
*elem_type
;
381 const struct side_attr
*attr
;
385 struct side_type_vla_visitor
{
386 const struct side_type
*elem_type
;
387 side_visitor_func visitor
;
388 const struct side_attr
*attr
;
392 struct side_type_enum
{
393 const struct side_enum_mappings
*mappings
;
394 const struct side_type
*elem_type
;
397 struct side_type_enum_bitmap
{
398 const struct side_enum_bitmap_mappings
*mappings
;
399 const struct side_type
*elem_type
;
402 struct side_type_gather_bool
{
403 uint64_t offset
; /* bytes */
404 uint8_t access_mode
; /* enum side_type_gather_access_mode */
405 struct side_type_bool type
;
406 uint16_t offset_bits
; /* bits */
409 struct side_type_gather_byte
{
410 uint64_t offset
; /* bytes */
411 uint8_t access_mode
; /* enum side_type_gather_access_mode */
412 struct side_type_byte type
;
415 struct side_type_gather_integer
{
416 uint64_t offset
; /* bytes */
417 uint8_t access_mode
; /* enum side_type_gather_access_mode */
418 struct side_type_integer type
;
419 uint16_t offset_bits
; /* bits */
422 struct side_type_gather_float
{
423 uint64_t offset
; /* bytes */
424 uint8_t access_mode
; /* enum side_type_gather_access_mode */
425 struct side_type_float type
;
428 struct side_type_gather_struct
{
429 uint64_t offset
; /* bytes */
430 uint8_t access_mode
; /* enum side_type_gather_access_mode */
431 const struct side_type_struct
*type
;
432 uint32_t size
; /* bytes */
435 struct side_type_gather_array
{
436 uint64_t offset
; /* bytes */
437 uint8_t access_mode
; /* enum side_type_gather_access_mode */
438 struct side_type_array type
;
441 struct side_type_gather_vla
{
442 const struct side_type
*length_type
; /* side_length() */
444 uint64_t offset
; /* bytes */
445 uint8_t access_mode
; /* enum side_type_gather_access_mode */
446 struct side_type_vla type
;
449 struct side_type_gather
{
451 struct side_type_gather_bool side_bool
;
452 struct side_type_gather_byte side_byte
;
453 struct side_type_gather_integer side_integer
;
454 struct side_type_gather_float side_float
;
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
;
478 /* Stack-copy enumeration types */
479 struct side_type_enum side_enum
;
480 struct side_type_enum_bitmap side_enum_bitmap
;
483 struct side_type_gather side_gather
;
487 struct side_event_field
{
488 const char *field_name
;
489 struct side_type side_type
;
492 enum side_event_flags
{
493 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
496 struct side_callback
{
498 void (*call
)(const struct side_event_description
*desc
,
499 const struct side_arg_vec
*side_arg_vec
,
501 void (*call_variadic
)(const struct side_event_description
*desc
,
502 const struct side_arg_vec
*side_arg_vec
,
503 const struct side_arg_dynamic_struct
*var_struct
,
509 struct side_arg_static
{
510 /* Stack-copy basic types */
513 uint64_t string_value
; /* const char * */
514 union side_integer_value integer_value
;
515 union side_float_value float_value
;
517 /* Stack-copy compound types */
518 const struct side_arg_vec
*side_struct
;
519 const struct side_arg_vec
*side_array
;
520 const struct side_arg_vec
*side_vla
;
521 void *side_vla_app_visitor_ctx
;
522 void *side_array_fixint
;
526 } SIDE_PACKED side_vla_fixint
;
528 /* Gather basic types */
529 void *side_bool_gather_ptr
;
530 void *side_byte_gather_ptr
;
531 void *side_integer_gather_ptr
;
532 void *side_float_gather_ptr
;
534 /* Gather compound types */
535 void *side_array_gather_ptr
;
536 void *side_struct_gather_ptr
;
540 } SIDE_PACKED side_vla_gather
;
543 struct side_arg_dynamic_vla
{
544 const struct side_arg
*sav
;
545 const struct side_attr
*attr
;
550 struct side_arg_dynamic_struct
{
551 const struct side_arg_dynamic_field
*fields
;
552 const struct side_attr
*attr
;
557 struct side_dynamic_struct_visitor
{
559 side_dynamic_struct_visitor_func visitor
;
560 const struct side_attr
*attr
;
564 struct side_dynamic_vla_visitor
{
566 side_visitor_func visitor
;
567 const struct side_attr
*attr
;
571 struct side_arg_dynamic
{
572 /* Dynamic basic types */
573 struct side_type_null side_null
;
575 struct side_type_bool type
;
577 } SIDE_PACKED side_bool
;
579 struct side_type_byte type
;
581 } SIDE_PACKED side_byte
;
583 struct side_type_string type
;
584 uint64_t value
; /* const char * */
585 } SIDE_PACKED side_string
;
587 struct side_type_integer type
;
588 union side_integer_value value
;
589 } SIDE_PACKED side_integer
;
591 struct side_type_float type
;
592 union side_float_value value
;
593 } SIDE_PACKED side_float
;
595 /* Dynamic compound types */
596 const struct side_arg_dynamic_struct
*side_dynamic_struct
;
597 const struct side_arg_dynamic_vla
*side_dynamic_vla
;
599 struct side_dynamic_struct_visitor side_dynamic_struct_visitor
;
600 struct side_dynamic_vla_visitor side_dynamic_vla_visitor
;
604 enum side_type_label type
;
606 struct side_arg_static side_static
;
607 struct side_arg_dynamic side_dynamic
;
611 struct side_arg_vec
{
612 const struct side_arg
*sav
;
616 struct side_arg_dynamic_field
{
617 const char *field_name
;
618 const struct side_arg elem
;
621 /* The visitor pattern is a double-dispatch visitor. */
622 struct side_tracer_visitor_ctx
{
623 enum side_visitor_status (*write_elem
)(
624 const struct side_tracer_visitor_ctx
*tracer_ctx
,
625 const struct side_arg
*elem
);
626 void *priv
; /* Private tracer context. */
629 struct side_tracer_dynamic_struct_visitor_ctx
{
630 enum side_visitor_status (*write_field
)(
631 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
632 const struct side_arg_dynamic_field
*dynamic_field
);
633 void *priv
; /* Private tracer context. */
636 struct side_event_description
{
638 const char *provider_name
;
639 const char *event_name
;
640 const struct side_event_field
*fields
;
641 const struct side_attr
*attr
;
642 const struct side_callback
*callbacks
;
645 uint32_t loglevel
; /* enum side_loglevel */
648 uint32_t nr_callbacks
;
651 /* Event and type attributes */
653 #if SIDE_BITS_PER_LONG == 64
654 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
655 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
656 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
657 # define SIDE_TYPE_DYNAMIC_POINTER_HOST SIDE_TYPE_DYNAMIC_POINTER64
658 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
659 # define SIDE_PTR_HOST .side_u64
661 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
662 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
663 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
664 # define SIDE_TYPE_DYNAMIC_POINTER_HOST SIDE_TYPE_DYNAMIC_POINTER32
665 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
666 # define SIDE_PTR_HOST .side_u32
669 #define side_attr(_key, _value) \
672 .value = SIDE_PARAM(_value), \
675 #define side_attr_list(...) \
676 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
678 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
679 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
680 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
681 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
682 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
683 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
684 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
685 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
686 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
687 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
688 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
689 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
690 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
691 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
692 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
693 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string_value = (uintptr_t) (_val) } }
695 /* Stack-copy enumeration type definitions */
697 #define side_define_enum(_identifier, _mappings, _attr) \
698 const struct side_enum_mappings _identifier = { \
699 .mappings = _mappings, \
701 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
702 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
705 #define side_enum_mapping_list(...) \
706 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
708 #define side_enum_mapping_range(_label, _begin, _end) \
710 .range_begin = _begin, \
715 #define side_enum_mapping_value(_label, _value) \
717 .range_begin = _value, \
718 .range_end = _value, \
722 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
723 const struct side_enum_bitmap_mappings _identifier = { \
724 .mappings = _mappings, \
726 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
727 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
730 #define side_enum_bitmap_mapping_list(...) \
731 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
733 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
735 .range_begin = _begin, \
740 #define side_enum_bitmap_mapping_value(_label, _value) \
742 .range_begin = _value, \
743 .range_end = _value, \
747 /* Stack-copy field and type definitions */
749 #define side_type_null(_attr) \
751 .type = SIDE_TYPE_NULL, \
755 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
760 #define side_type_bool(_attr) \
762 .type = SIDE_TYPE_BOOL, \
766 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
767 .bool_size_bits = 8, \
769 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
774 #define side_type_byte(_attr) \
776 .type = SIDE_TYPE_BYTE, \
780 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
785 #define side_type_string(_attr) \
787 .type = SIDE_TYPE_STRING, \
791 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
796 #define side_type_dynamic() \
798 .type = SIDE_TYPE_DYNAMIC, \
801 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
807 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
808 .integer_size_bits = _integer_size_bits, \
809 .len_bits = _len_bits, \
810 .signedness = _signedness, \
811 .byte_order = _byte_order, \
816 #define _side_type_float(_type, _byte_order, _float_size_bits, _attr) \
822 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
823 .float_size_bits = _float_size_bits, \
824 .byte_order = _byte_order, \
829 #define _side_field(_name, _type) \
831 .field_name = _name, \
832 .side_type = _type, \
836 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
837 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
838 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
839 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
840 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
841 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
842 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
843 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
844 #define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_BITS_PER_LONG, \
845 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
846 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 16, SIDE_PARAM(_attr))
847 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 32, SIDE_PARAM(_attr))
848 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 64, SIDE_PARAM(_attr))
849 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 128, SIDE_PARAM(_attr))
851 #define side_field_null(_name, _attr) _side_field(_name, side_type_null(SIDE_PARAM(_attr)))
852 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
853 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
854 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
855 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
856 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
857 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
858 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
859 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
860 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
861 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
862 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
863 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
864 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
865 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
866 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
867 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
868 #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic())
871 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
872 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
873 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
874 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
875 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
876 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
877 #define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_LE, SIDE_BITS_PER_LONG, \
878 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
879 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, 16, SIDE_PARAM(_attr))
880 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, 32, SIDE_PARAM(_attr))
881 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, 64, SIDE_PARAM(_attr))
882 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 128, SIDE_PARAM(_attr))
884 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
885 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
886 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
887 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
888 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
889 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
890 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
891 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
892 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
893 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
894 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
897 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
898 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
899 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
900 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
901 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
902 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
903 #define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_BE, SIDE_BITS_PER_LONG, \
904 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
905 #define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, 16, SIDE_PARAM(_attr))
906 #define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, 32, SIDE_PARAM(_attr))
907 #define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, 64, SIDE_PARAM(_attr))
908 #define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, 128, SIDE_PARAM(_attr))
910 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
911 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
912 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
913 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
914 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
915 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
916 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
917 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
918 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
919 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
920 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
922 #define side_type_enum(_mappings, _elem_type) \
924 .type = SIDE_TYPE_ENUM, \
927 .mappings = _mappings, \
928 .elem_type = _elem_type, \
932 #define side_field_enum(_name, _mappings, _elem_type) \
933 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
935 #define side_type_enum_bitmap(_mappings, _elem_type) \
937 .type = SIDE_TYPE_ENUM_BITMAP, \
939 .side_enum_bitmap = { \
940 .mappings = _mappings, \
941 .elem_type = _elem_type, \
945 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
946 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
948 #define side_type_struct(_struct) \
950 .type = SIDE_TYPE_STRUCT, \
952 .side_struct = _struct, \
955 #define side_field_struct(_name, _struct) \
956 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
958 #define _side_type_struct_define(_fields, _attr) \
962 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
963 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
966 #define side_define_struct(_identifier, _fields, _attr) \
967 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
969 #define side_struct_literal(_fields, _attr) \
970 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
971 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
973 #define side_type_array(_elem_type, _length, _attr) \
975 .type = SIDE_TYPE_ARRAY, \
978 .elem_type = _elem_type, \
981 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
985 #define side_field_array(_name, _elem_type, _length, _attr) \
986 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
988 #define side_type_vla(_elem_type, _attr) \
990 .type = SIDE_TYPE_VLA, \
993 .elem_type = _elem_type, \
995 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
999 #define side_field_vla(_name, _elem_type, _attr) \
1000 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
1002 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
1004 .type = SIDE_TYPE_VLA_VISITOR, \
1006 .side_vla_visitor = { \
1007 .elem_type = SIDE_PARAM(_elem_type), \
1008 .visitor = _visitor, \
1010 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1014 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
1015 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
1017 /* Gather field and type definitions */
1019 #define side_type_gather_byte(_offset, _access_mode, _attr) \
1021 .type = SIDE_TYPE_GATHER_BYTE, \
1026 .offset = _offset, \
1027 .access_mode = _access_mode, \
1030 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1037 #define side_field_gather_byte(_name, _offset, _access_mode, _attr) \
1038 _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM(_attr)))
1040 #define _side_type_gather_bool(_byte_order, _offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1042 .type = SIDE_TYPE_GATHER_BOOL, \
1047 .offset = _offset, \
1048 .access_mode = _access_mode, \
1051 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1052 .bool_size_bits = _bool_size_bits, \
1053 .len_bits = _len_bits, \
1054 .byte_order = _byte_order, \
1056 .offset_bits = _offset_bits, \
1062 #define side_type_gather_bool(_offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1063 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_HOST, _offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr)
1064 #define side_type_gather_bool_le(_offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1065 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_LE, _offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr)
1066 #define side_type_gather_bool_be(_offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1067 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_BE, _offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr)
1069 #define side_field_gather_bool(_name, _offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1070 _side_field(_name, side_type_gather_bool(_offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1071 #define side_field_gather_bool_le(_name, _offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1072 _side_field(_name, side_type_gather_bool_le(_offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1073 #define side_field_gather_bool_be(_name, _offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1074 _side_field(_name, side_type_gather_bool_be(_offset, _bool_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1076 #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
1077 _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1084 .offset = _offset, \
1085 .access_mode = _access_mode, \
1088 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1089 .integer_size_bits = _integer_size_bits, \
1090 .len_bits = _len_bits, \
1091 .signedness = _signedness, \
1092 .byte_order = _byte_order, \
1094 .offset_bits = _offset_bits, \
1101 #define side_type_gather_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1102 _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1103 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1104 #define side_type_gather_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1105 _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_HOST, \
1106 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1108 #define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1109 _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_LE, \
1110 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1111 #define side_type_gather_signed_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1112 _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_LE, \
1113 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1115 #define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1116 _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_BE, \
1117 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1118 #define side_type_gather_signed_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1119 _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_BE, \
1120 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1122 #define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1123 _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1124 #define side_field_gather_signed_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1125 _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1127 #define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1128 _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1129 #define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1130 _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1132 #define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1133 _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1134 #define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1135 _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1137 #define _side_type_gather_float(_byte_order, _offset, _float_size_bits, _access_mode, _attr) \
1139 .type = SIDE_TYPE_GATHER_FLOAT, \
1144 .offset = _offset, \
1145 .access_mode = _access_mode, \
1148 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1149 .float_size_bits = _float_size_bits, \
1150 .byte_order = _byte_order, \
1158 #define side_type_gather_float(_offset, _float_size_bits, _access_mode, _attr) \
1159 _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size_bits, _access_mode, _attr)
1160 #define side_type_gather_float_le(_offset, _float_size_bits, _access_mode, _attr) \
1161 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size_bits, _access_mode, _attr)
1162 #define side_type_gather_float_be(_offset, _float_size_bits, _access_mode, _attr) \
1163 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size_bits, _access_mode, _attr)
1165 #define side_field_gather_float(_name, _offset, _float_size_bits, _access_mode, _attr) \
1166 _side_field(_name, side_type_gather_float(_offset, _float_size_bits, _access_mode, _attr))
1167 #define side_field_gather_float_le(_name, _offset, _float_size_bits, _access_mode, _attr) \
1168 _side_field(_name, side_type_gather_float_le(_offset, _float_size_bits, _access_mode, _attr))
1169 #define side_field_gather_float_be(_name, _offset, _float_size_bits, _access_mode, _attr) \
1170 _side_field(_name, side_type_gather_float_be(_offset, _float_size_bits, _access_mode, _attr))
1172 #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
1174 .type = SIDE_TYPE_GATHER_STRUCT, \
1179 .offset = _offset, \
1180 .access_mode = _access_mode, \
1181 .type = _struct_gather, \
1188 #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \
1189 _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode))
1191 #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr) \
1193 .type = SIDE_TYPE_GATHER_ARRAY, \
1198 .offset = _offset, \
1199 .access_mode = _access_mode, \
1201 .elem_type = _elem_type_gather, \
1203 .length = _length, \
1204 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1211 #define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr) \
1212 _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM(_attr)))
1214 #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1216 .type = SIDE_TYPE_GATHER_VLA, \
1221 .offset = _offset, \
1222 .access_mode = _access_mode, \
1224 .elem_type = _elem_type_gather, \
1226 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1228 .length_type = _length_type_gather, \
1234 #define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1235 _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM(_attr)))
1237 #define side_elem(...) \
1238 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1240 #define side_length(...) \
1241 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1243 #define side_field_list(...) \
1244 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
1246 /* Stack-copy field arguments */
1248 #define side_arg_null(_val) { .type = SIDE_TYPE_NULL }
1249 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = !!(_val) } } }
1250 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_static = { .byte_value = (_val) } } }
1251 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1253 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1254 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1255 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1256 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1257 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
1258 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
1259 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
1260 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
1261 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { .side_static = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } } }
1262 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1263 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1264 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1265 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1266 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
1267 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
1268 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
1269 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
1270 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
1271 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
1273 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = (_side_type) } } }
1274 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
1275 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
1276 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
1278 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1279 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1280 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1281 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1282 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1283 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1284 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1285 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1286 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1287 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1289 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1290 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1291 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1292 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1293 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1294 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1295 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1296 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1297 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1298 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1300 /* Gather field arguments */
1302 #define side_arg_gather_bool(_ptr) { .type = SIDE_TYPE_GATHER_BOOL, .u = { .side_static = { .side_bool_gather_ptr = (_ptr) } } }
1303 #define side_arg_gather_byte(_ptr) { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = (_ptr) } } }
1304 #define side_arg_gather_unsigned_integer(_ptr) { .type = SIDE_TYPE_GATHER_UNSIGNED_INT, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1305 #define side_arg_gather_signed_integer(_ptr) { .type = SIDE_TYPE_GATHER_SIGNED_INT, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1306 #define side_arg_gather_float(_ptr) { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = (_ptr) } } }
1307 #define side_arg_gather_struct(_ptr) { .type = SIDE_TYPE_GATHER_STRUCT, .u = { .side_static = { .side_struct_gather_ptr = (_ptr) } } }
1308 #define side_arg_gather_array(_ptr) { .type = SIDE_TYPE_GATHER_ARRAY, .u = { .side_static = { .side_array_gather_ptr = (_ptr) } } }
1309 #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) } } } }
1311 /* Dynamic field arguments */
1313 #define side_arg_dynamic_null(_attr) \
1315 .type = SIDE_TYPE_DYNAMIC_NULL, \
1320 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1326 #define side_arg_dynamic_bool(_val, _attr) \
1328 .type = SIDE_TYPE_DYNAMIC_BOOL, \
1334 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1335 .bool_size_bits = sizeof(uint8_t) * CHAR_BIT, \
1337 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
1339 .value = !!(_val), \
1345 #define side_arg_dynamic_byte(_val, _attr) \
1347 .type = SIDE_TYPE_DYNAMIC_BYTE, \
1353 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1360 #define side_arg_dynamic_string(_val, _attr) \
1362 .type = SIDE_TYPE_DYNAMIC_STRING, \
1368 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1370 .value = (uintptr_t) (_val), \
1376 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
1384 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1385 .integer_size_bits = _integer_size_bits, \
1386 .len_bits = _len_bits, \
1387 .signedness = _signedness, \
1388 .byte_order = _byte_order, \
1398 #define side_arg_dynamic_u8(_val, _attr) \
1399 _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1400 #define side_arg_dynamic_s8(_val, _attr) \
1401 _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1403 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1404 _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_U16, false, _byte_order, 16, 16, SIDE_PARAM(_attr))
1405 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1406 _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_U32, false, _byte_order, 32, 32, SIDE_PARAM(_attr))
1407 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1408 _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_U64, false, _byte_order, 64, 64, SIDE_PARAM(_attr))
1410 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1411 _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_S16, true, _byte_order, 16, 16, SIDE_PARAM(_attr))
1412 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1413 _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_S32, true, _byte_order, 32, 32, SIDE_PARAM(_attr))
1414 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1415 _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_S64, true, _byte_order, 64, 64, SIDE_PARAM(_attr))
1417 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1418 _side_arg_dynamic_integer(SIDE_PTR_HOST, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER_HOST, false, _byte_order, \
1419 SIDE_BITS_PER_LONG, SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
1421 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size_bits, _attr) \
1429 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1430 .float_size_bits = _float_size_bits, \
1431 .byte_order = _byte_order, \
1441 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1442 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY16, _byte_order, 16, SIDE_PARAM(_attr))
1443 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1444 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY32, _byte_order, 32, SIDE_PARAM(_attr))
1445 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1446 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY64, _byte_order, 64, SIDE_PARAM(_attr))
1447 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1448 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY128, _byte_order, 128, SIDE_PARAM(_attr))
1451 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1452 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1453 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1454 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1455 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1456 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1457 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1458 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1459 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1460 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1461 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1464 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1465 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1466 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1467 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1468 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1469 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1470 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1471 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1472 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1473 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1474 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1477 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1478 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1479 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1480 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1481 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1482 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1483 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1484 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1485 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1486 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1487 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1489 #define side_arg_dynamic_vla(_vla) \
1491 .type = SIDE_TYPE_DYNAMIC_VLA, \
1494 .side_dynamic_vla = (_vla), \
1499 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1501 .type = SIDE_TYPE_DYNAMIC_VLA_VISITOR, \
1504 .side_dynamic_vla_visitor = { \
1506 .visitor = _dynamic_vla_visitor, \
1508 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1514 #define side_arg_dynamic_struct(_struct) \
1516 .type = SIDE_TYPE_DYNAMIC_STRUCT, \
1519 .side_dynamic_struct = (_struct), \
1524 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1526 .type = SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, \
1529 .side_dynamic_struct_visitor = { \
1531 .visitor = _dynamic_struct_visitor, \
1533 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1539 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1540 const struct side_arg _identifier##_vec[] = { _sav }; \
1541 const struct side_arg_dynamic_vla _identifier = { \
1542 .sav = _identifier##_vec, \
1544 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1545 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1548 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1549 const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \
1550 const struct side_arg_dynamic_struct _identifier = { \
1551 .fields = _identifier##_fields, \
1553 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1554 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1557 #define side_arg_define_vec(_identifier, _sav) \
1558 const struct side_arg _identifier##_vec[] = { _sav }; \
1559 const struct side_arg_vec _identifier = { \
1560 .sav = _identifier##_vec, \
1561 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1564 #define side_arg_dynamic_field(_name, _elem) \
1566 .field_name = _name, \
1571 * Event instrumentation description registration, runtime enabled state
1572 * check, and instrumentation invocation.
1575 #define side_arg_list(...) __VA_ARGS__
1577 #define side_event_cond(_identifier) \
1578 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1581 #define side_event_call(_identifier, _sav) \
1583 const struct side_arg side_sav[] = { _sav }; \
1584 const struct side_arg_vec side_arg_vec = { \
1586 .len = SIDE_ARRAY_SIZE(side_sav), \
1588 side_call(&(_identifier), &side_arg_vec); \
1591 #define side_event(_identifier, _sav) \
1592 side_event_cond(_identifier) \
1593 side_event_call(_identifier, SIDE_PARAM(_sav))
1595 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1597 const struct side_arg side_sav[] = { _sav }; \
1598 const struct side_arg_vec side_arg_vec = { \
1600 .len = SIDE_ARRAY_SIZE(side_sav), \
1602 const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \
1603 const struct side_arg_dynamic_struct var_struct = { \
1604 .fields = side_fields, \
1606 .len = SIDE_ARRAY_SIZE(side_fields), \
1607 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1609 side_call_variadic(&(_identifier), &side_arg_vec, &var_struct); \
1612 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1613 side_event_cond(_identifier) \
1614 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1616 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1617 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1618 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1620 .enabled = &(side_event_enable__##_identifier), \
1621 .provider_name = _provider, \
1622 .event_name = _event, \
1623 .fields = _fields, \
1625 .callbacks = &side_empty_callback, \
1626 .flags = (_flags), \
1628 .loglevel = _loglevel, \
1629 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1630 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1631 .nr_callbacks = 0, \
1633 static const struct side_event_description *side_event_ptr__##_identifier \
1634 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1636 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1637 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1638 SIDE_PARAM(_attr), 0)
1640 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1641 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1642 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1644 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1645 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1646 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0)
1648 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1649 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1650 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1652 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1653 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1654 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0)
1656 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1657 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1658 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1660 #define side_declare_event(_identifier) \
1661 extern uintptr_t side_event_enable_##_identifier; \
1662 extern struct side_event_description _identifier
1664 extern const struct side_callback side_empty_callback
;
1666 void side_call(const struct side_event_description
*desc
,
1667 const struct side_arg_vec
*side_arg_vec
);
1668 void side_call_variadic(const struct side_event_description
*desc
,
1669 const struct side_arg_vec
*side_arg_vec
,
1670 const struct side_arg_dynamic_struct
*var_struct
);
1672 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
,
1673 uint32_t nr_events
);
1674 void side_events_unregister(struct side_events_register_handle
*handle
);
1677 * Userspace tracer registration API. This allows userspace tracers to
1678 * register event notification callbacks to be notified of the currently
1679 * registered instrumentation, and to register their callbacks to
1682 typedef void (*side_tracer_callback_func
)(const struct side_event_description
*desc
,
1683 const struct side_arg_vec
*side_arg_vec
,
1685 typedef void (*side_tracer_callback_variadic_func
)(const struct side_event_description
*desc
,
1686 const struct side_arg_vec
*side_arg_vec
,
1687 const struct side_arg_dynamic_struct
*var_struct
,
1690 int side_tracer_callback_register(struct side_event_description
*desc
,
1691 side_tracer_callback_func call
,
1693 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1694 side_tracer_callback_variadic_func call_variadic
,
1696 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1697 side_tracer_callback_func call
,
1699 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1700 side_tracer_callback_variadic_func call_variadic
,
1703 enum side_tracer_notification
{
1704 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1705 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1708 /* Callback is invoked with side library internal lock held. */
1709 struct side_tracer_handle
*side_tracer_event_notification_register(
1710 void (*cb
)(enum side_tracer_notification notif
,
1711 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1713 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1716 * Explicit hooks to initialize/finalize the side instrumentation
1717 * library. Those are also library constructor/destructor.
1719 void side_init(void);
1720 void side_exit(void);
1723 * The following constructors/destructors perform automatic registration
1724 * of the declared side events. Those may have to be called explicitly
1725 * in a statically linked library.
1729 * These weak symbols, the constructor, and destructor take care of
1730 * registering only _one_ instance of the side instrumentation per
1731 * shared-ojbect (or for the whole main program).
1733 extern struct side_event_description
* __start_side_event_description_ptr
[]
1734 __attribute__((weak
, visibility("hidden")));
1735 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1736 __attribute__((weak
, visibility("hidden")));
1737 int side_event_description_ptr_registered
1738 __attribute__((weak
, visibility("hidden")));
1739 struct side_events_register_handle
*side_events_handle
1740 __attribute__((weak
, visibility("hidden")));
1743 side_event_description_ptr_init(void)
1744 __attribute__((no_instrument_function
))
1745 __attribute__((constructor
));
1747 side_event_description_ptr_init(void)
1749 if (side_event_description_ptr_registered
++)
1751 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1752 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1756 side_event_description_ptr_exit(void)
1757 __attribute__((no_instrument_function
))
1758 __attribute__((destructor
));
1760 side_event_description_ptr_exit(void)
1762 if (--side_event_description_ptr_registered
)
1764 side_events_unregister(side_events_handle
);
1765 side_events_handle
= NULL
;
1768 #endif /* _SIDE_TRACE_H */