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 /* Statically declared types */
101 SIDE_TYPE_FLOAT_BINARY16
,
102 SIDE_TYPE_FLOAT_BINARY32
,
103 SIDE_TYPE_FLOAT_BINARY64
,
104 SIDE_TYPE_FLOAT_BINARY128
,
107 /* Statically declared 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 /* Statically declared enumeration types */
139 SIDE_TYPE_ENUM_BITMAP
,
144 SIDE_TYPE_GATHER_UNSIGNED_INT
,
145 SIDE_TYPE_GATHER_SIGNED_INT
,
146 SIDE_TYPE_GATHER_BYTE
,
147 SIDE_TYPE_GATHER_FLOAT
,
148 SIDE_TYPE_GATHER_STRUCT
,
149 SIDE_TYPE_GATHER_ARRAY
,
150 SIDE_TYPE_GATHER_VLA
,
153 SIDE_TYPE_DYNAMIC_NULL
,
154 SIDE_TYPE_DYNAMIC_BOOL
,
155 SIDE_TYPE_DYNAMIC_U8
,
156 SIDE_TYPE_DYNAMIC_U16
,
157 SIDE_TYPE_DYNAMIC_U32
,
158 SIDE_TYPE_DYNAMIC_U64
,
159 SIDE_TYPE_DYNAMIC_S8
,
160 SIDE_TYPE_DYNAMIC_S16
,
161 SIDE_TYPE_DYNAMIC_S32
,
162 SIDE_TYPE_DYNAMIC_S64
,
163 SIDE_TYPE_DYNAMIC_BYTE
,
164 SIDE_TYPE_DYNAMIC_POINTER32
,
165 SIDE_TYPE_DYNAMIC_POINTER64
,
166 SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
,
167 SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
,
168 SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
,
169 SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
,
170 SIDE_TYPE_DYNAMIC_STRING
,
172 /* Dynamic compound types */
173 SIDE_TYPE_DYNAMIC_STRUCT
,
174 SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
,
175 SIDE_TYPE_DYNAMIC_VLA
,
176 SIDE_TYPE_DYNAMIC_VLA_VISITOR
,
179 enum side_attr_type
{
190 SIDE_ATTR_TYPE_POINTER32
,
191 SIDE_ATTR_TYPE_POINTER64
,
192 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
193 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
194 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
195 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
196 SIDE_ATTR_TYPE_STRING
,
200 SIDE_LOGLEVEL_EMERG
= 0,
201 SIDE_LOGLEVEL_ALERT
= 1,
202 SIDE_LOGLEVEL_CRIT
= 2,
203 SIDE_LOGLEVEL_ERR
= 3,
204 SIDE_LOGLEVEL_WARNING
= 4,
205 SIDE_LOGLEVEL_NOTICE
= 5,
206 SIDE_LOGLEVEL_INFO
= 6,
207 SIDE_LOGLEVEL_DEBUG
= 7,
210 enum side_visitor_status
{
211 SIDE_VISITOR_STATUS_OK
= 0,
212 SIDE_VISITOR_STATUS_ERROR
= -1,
217 SIDE_ERROR_INVAL
= 1,
218 SIDE_ERROR_EXIST
= 2,
219 SIDE_ERROR_NOMEM
= 3,
220 SIDE_ERROR_NOENT
= 4,
221 SIDE_ERROR_EXITING
= 5,
224 enum side_type_label_byte_order
{
225 SIDE_TYPE_BYTE_ORDER_LE
= 0,
226 SIDE_TYPE_BYTE_ORDER_BE
= 1,
229 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
230 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
232 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
235 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
236 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
238 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
241 typedef enum side_visitor_status (*side_visitor_func
)(
242 const struct side_tracer_visitor_ctx
*tracer_ctx
,
244 typedef enum side_visitor_status (*side_dynamic_struct_visitor_func
)(
245 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
248 union side_integer_value
{
259 union side_float_value
{
261 _Float16 side_float_binary16
;
264 _Float32 side_float_binary32
;
267 _Float64 side_float_binary64
;
270 _Float128 side_float_binary128
;
274 struct side_attr_value
{
275 uint32_t type
; /* enum side_attr_type */
278 uint64_t string_value
; /* const char * */
279 union side_integer_value integer_value
;
280 union side_float_value float_value
;
284 /* User attributes. */
287 const struct side_attr_value value
;
290 /* Type descriptions */
291 struct side_type_null
{
292 const struct side_attr
*attr
;
296 struct side_type_bool
{
297 const struct side_attr
*attr
;
301 struct side_type_byte
{
302 const struct side_attr
*attr
;
306 struct side_type_string
{
307 const struct side_attr
*attr
;
311 struct side_type_integer
{
312 const struct side_attr
*attr
;
314 uint16_t integer_size_bits
; /* bits */
315 uint16_t len_bits
; /* bits */
316 uint8_t signedness
; /* true/false */
317 uint8_t byte_order
; /* enum side_type_label_byte_order */
320 struct side_type_float
{
321 const struct side_attr
*attr
;
323 uint16_t float_size_bits
; /* bits */
324 uint8_t byte_order
; /* enum side_type_label_byte_order */
327 struct side_enum_mapping
{
333 struct side_enum_mappings
{
334 const struct side_enum_mapping
*mappings
;
335 const struct side_attr
*attr
;
336 uint32_t nr_mappings
;
340 struct side_enum_bitmap_mapping
{
341 uint64_t range_begin
;
346 struct side_enum_bitmap_mappings
{
347 const struct side_enum_bitmap_mapping
*mappings
;
348 const struct side_attr
*attr
;
349 uint32_t nr_mappings
;
353 struct side_type_struct
{
354 const struct side_event_field
*fields
;
355 const struct side_attr
*attr
;
360 struct side_type_array
{
361 const struct side_type
*elem_type
;
362 const struct side_attr
*attr
;
367 struct side_type_vla
{
368 const struct side_type
*elem_type
;
369 const struct side_attr
*attr
;
373 struct side_type_vla_visitor
{
374 const struct side_type
*elem_type
;
375 side_visitor_func visitor
;
376 const struct side_attr
*attr
;
380 struct side_type_enum
{
381 const struct side_enum_mappings
*mappings
;
382 const struct side_type
*elem_type
;
385 struct side_type_enum_bitmap
{
386 const struct side_enum_bitmap_mappings
*mappings
;
387 const struct side_type
*elem_type
;
390 struct side_type_gather_byte
{
391 uint64_t offset
; /* bytes */
392 uint8_t access_mode
; /* enum side_type_gather_access_mode */
393 struct side_type_byte type
;
396 struct side_type_gather_integer
{
397 uint64_t offset
; /* bytes */
398 uint8_t access_mode
; /* enum side_type_gather_access_mode */
399 struct side_type_integer type
;
400 uint16_t offset_bits
; /* bits */
403 struct side_type_gather_float
{
404 uint64_t offset
; /* bytes */
405 uint8_t access_mode
; /* enum side_type_gather_access_mode */
406 struct side_type_float type
;
409 struct side_type_gather_struct
{
410 uint64_t offset
; /* bytes */
411 uint8_t access_mode
; /* enum side_type_gather_access_mode */
412 const struct side_type_struct
*type
;
413 uint32_t size
; /* bytes */
416 struct side_type_gather_array
{
417 uint64_t offset
; /* bytes */
418 uint8_t access_mode
; /* enum side_type_gather_access_mode */
419 struct side_type_array type
;
422 struct side_type_gather_vla
{
423 const struct side_type
*length_type
; /* side_length() */
425 uint64_t offset
; /* bytes */
426 uint8_t access_mode
; /* enum side_type_gather_access_mode */
427 struct side_type_vla type
;
430 enum side_type_gather_access_mode
{
431 SIDE_TYPE_GATHER_ACCESS_ADDRESS
,
432 SIDE_TYPE_GATHER_ACCESS_POINTER
,
435 struct side_type_gather
{
437 struct side_type_gather_byte side_byte
;
438 struct side_type_gather_integer side_integer
;
439 struct side_type_gather_float side_float
;
440 struct side_type_gather_array side_array
;
441 struct side_type_gather_vla side_vla
;
442 struct side_type_gather_struct side_struct
;
446 /* Statically defined types. */
448 uint32_t type
; /* enum side_type_label */
451 struct side_type_null side_null
;
452 struct side_type_bool side_bool
;
453 struct side_type_byte side_byte
;
454 struct side_type_string side_string
;
455 struct side_type_integer side_integer
;
456 struct side_type_float side_float
;
459 struct side_type_array side_array
;
460 struct side_type_vla side_vla
;
461 struct side_type_vla_visitor side_vla_visitor
;
462 const struct side_type_struct
*side_struct
;
464 /* Enumeration types */
465 struct side_type_enum side_enum
;
466 struct side_type_enum_bitmap side_enum_bitmap
;
469 struct side_type_gather side_gather
;
473 struct side_event_field
{
474 const char *field_name
;
475 struct side_type side_type
;
478 enum side_event_flags
{
479 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
482 struct side_callback
{
484 void (*call
)(const struct side_event_description
*desc
,
485 const struct side_arg_vec
*side_arg_vec
,
487 void (*call_variadic
)(const struct side_event_description
*desc
,
488 const struct side_arg_vec
*side_arg_vec
,
489 const struct side_arg_dynamic_struct
*var_struct
,
495 struct side_arg_static
{
499 uint64_t string_value
; /* const char * */
500 union side_integer_value integer_value
;
501 union side_float_value float_value
;
504 const struct side_arg_vec
*side_struct
;
505 const struct side_arg_vec
*side_array
;
506 const struct side_arg_vec
*side_vla
;
507 void *side_vla_app_visitor_ctx
;
508 void *side_array_fixint
;
512 } SIDE_PACKED side_vla_fixint
;
515 void *side_byte_gather_ptr
;
516 void *side_integer_gather_ptr
;
517 void *side_float_gather_ptr
;
518 void *side_array_gather_ptr
;
519 void *side_struct_gather_ptr
;
523 } SIDE_PACKED side_vla_gather
;
526 struct side_arg_dynamic_vla
{
527 const struct side_arg
*sav
;
528 const struct side_attr
*attr
;
533 struct side_arg_dynamic_struct
{
534 const struct side_arg_dynamic_field
*fields
;
535 const struct side_attr
*attr
;
540 struct side_dynamic_struct_visitor
{
542 side_dynamic_struct_visitor_func visitor
;
543 const struct side_attr
*attr
;
547 struct side_dynamic_vla_visitor
{
549 side_visitor_func visitor
;
550 const struct side_attr
*attr
;
554 struct side_arg_dynamic
{
556 struct side_type_null side_null
;
558 struct side_type_bool type
;
560 } SIDE_PACKED side_bool
;
563 struct side_type_byte type
;
565 } SIDE_PACKED side_byte
;
568 struct side_type_string type
;
569 uint64_t value
; /* const char * */
570 } SIDE_PACKED side_string
;
574 struct side_type_integer type
;
575 union side_integer_value value
;
576 } SIDE_PACKED side_integer
;
579 struct side_type_float type
;
580 union side_float_value value
;
581 } SIDE_PACKED side_float
;
584 const struct side_arg_dynamic_struct
*side_dynamic_struct
;
585 const struct side_arg_dynamic_vla
*side_dynamic_vla
;
587 struct side_dynamic_struct_visitor side_dynamic_struct_visitor
;
588 struct side_dynamic_vla_visitor side_dynamic_vla_visitor
;
592 enum side_type_label type
;
594 struct side_arg_static side_static
;
595 struct side_arg_dynamic side_dynamic
;
599 struct side_arg_vec
{
600 const struct side_arg
*sav
;
604 struct side_arg_dynamic_field
{
605 const char *field_name
;
606 const struct side_arg elem
;
609 /* The visitor pattern is a double-dispatch visitor. */
610 struct side_tracer_visitor_ctx
{
611 enum side_visitor_status (*write_elem
)(
612 const struct side_tracer_visitor_ctx
*tracer_ctx
,
613 const struct side_arg
*elem
);
614 void *priv
; /* Private tracer context. */
617 struct side_tracer_dynamic_struct_visitor_ctx
{
618 enum side_visitor_status (*write_field
)(
619 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
620 const struct side_arg_dynamic_field
*dynamic_field
);
621 void *priv
; /* Private tracer context. */
624 struct side_event_description
{
626 const char *provider_name
;
627 const char *event_name
;
628 const struct side_event_field
*fields
;
629 const struct side_attr
*attr
;
630 const struct side_callback
*callbacks
;
633 uint32_t loglevel
; /* enum side_loglevel */
636 uint32_t nr_callbacks
;
639 /* Event and type attributes */
641 #if SIDE_BITS_PER_LONG == 64
642 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
643 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
644 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
645 # define SIDE_TYPE_DYNAMIC_POINTER_HOST SIDE_TYPE_DYNAMIC_POINTER64
646 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
647 # define SIDE_PTR_HOST .side_u64
649 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
650 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
651 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
652 # define SIDE_TYPE_DYNAMIC_POINTER_HOST SIDE_TYPE_DYNAMIC_POINTER32
653 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
654 # define SIDE_PTR_HOST .side_u32
657 #define side_attr(_key, _value) \
660 .value = SIDE_PARAM(_value), \
663 #define side_attr_list(...) \
664 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
666 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
667 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
668 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
669 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
670 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
671 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
672 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
673 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
674 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
675 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
676 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
677 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
678 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
679 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
680 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
681 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string_value = (uintptr_t) (_val) } }
683 /* Static field definition */
685 #define side_type_null(_attr) \
687 .type = SIDE_TYPE_NULL, \
691 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
696 #define side_type_bool(_attr) \
698 .type = SIDE_TYPE_BOOL, \
702 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
707 #define side_type_byte(_attr) \
709 .type = SIDE_TYPE_BYTE, \
713 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
718 #define side_type_string(_attr) \
720 .type = SIDE_TYPE_STRING, \
724 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
729 #define side_type_dynamic() \
731 .type = SIDE_TYPE_DYNAMIC, \
734 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
740 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
741 .integer_size_bits = _integer_size_bits, \
742 .len_bits = _len_bits, \
743 .signedness = _signedness, \
744 .byte_order = _byte_order, \
749 #define _side_type_float(_type, _byte_order, _float_size_bits, _attr) \
755 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
756 .float_size_bits = _float_size_bits, \
757 .byte_order = _byte_order, \
762 #define _side_field(_name, _type) \
764 .field_name = _name, \
765 .side_type = _type, \
769 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
770 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
771 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
772 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
773 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
774 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
775 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
776 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
777 #define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_BITS_PER_LONG, \
778 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
779 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 16, SIDE_PARAM(_attr))
780 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 32, SIDE_PARAM(_attr))
781 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 64, SIDE_PARAM(_attr))
782 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 128, SIDE_PARAM(_attr))
784 #define side_field_null(_name, _attr) _side_field(_name, side_type_null(SIDE_PARAM(_attr)))
785 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
786 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
787 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
788 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
789 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
790 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
791 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
792 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
793 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
794 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
795 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
796 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
797 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
798 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
799 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
800 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
801 #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic())
804 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
805 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
806 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
807 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
808 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
809 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
810 #define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_LE, SIDE_BITS_PER_LONG, \
811 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
812 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, 16, SIDE_PARAM(_attr))
813 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, 32, SIDE_PARAM(_attr))
814 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, 64, SIDE_PARAM(_attr))
815 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 128, SIDE_PARAM(_attr))
817 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
818 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
819 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
820 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
821 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
822 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
823 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
824 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
825 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
826 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
827 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
830 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
831 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
832 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
833 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
834 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
835 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
836 #define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_BE, SIDE_BITS_PER_LONG, \
837 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
838 #define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, 16, SIDE_PARAM(_attr))
839 #define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, 32, SIDE_PARAM(_attr))
840 #define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, 64, SIDE_PARAM(_attr))
841 #define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, 128, SIDE_PARAM(_attr))
843 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
844 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
845 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
846 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
847 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
848 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
849 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
850 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
851 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
852 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
853 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
855 #define side_type_enum(_mappings, _elem_type) \
857 .type = SIDE_TYPE_ENUM, \
860 .mappings = _mappings, \
861 .elem_type = _elem_type, \
865 #define side_field_enum(_name, _mappings, _elem_type) \
866 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
868 #define side_type_enum_bitmap(_mappings, _elem_type) \
870 .type = SIDE_TYPE_ENUM_BITMAP, \
872 .side_enum_bitmap = { \
873 .mappings = _mappings, \
874 .elem_type = _elem_type, \
878 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
879 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
881 #define side_type_struct(_struct) \
883 .type = SIDE_TYPE_STRUCT, \
885 .side_struct = _struct, \
888 #define side_field_struct(_name, _struct) \
889 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
891 #define _side_type_struct_define(_fields, _attr) \
895 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
896 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
899 #define side_define_struct(_identifier, _fields, _attr) \
900 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
902 #define side_struct_literal(_fields, _attr) \
903 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
904 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
906 #define side_type_array(_elem_type, _length, _attr) \
908 .type = SIDE_TYPE_ARRAY, \
911 .elem_type = _elem_type, \
914 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
918 #define side_field_array(_name, _elem_type, _length, _attr) \
919 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
921 #define side_type_vla(_elem_type, _attr) \
923 .type = SIDE_TYPE_VLA, \
926 .elem_type = _elem_type, \
928 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
932 #define side_field_vla(_name, _elem_type, _attr) \
933 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
935 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
937 .type = SIDE_TYPE_VLA_VISITOR, \
939 .side_vla_visitor = { \
940 .elem_type = SIDE_PARAM(_elem_type), \
941 .visitor = _visitor, \
943 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
947 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
948 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
952 #define side_type_gather_byte(_offset, _access_mode, _attr) \
954 .type = SIDE_TYPE_GATHER_BYTE, \
960 .access_mode = _access_mode, \
963 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
970 #define side_field_gather_byte(_name, _offset, _access_mode, _attr) \
971 _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM(_attr)))
973 #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
974 _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
982 .access_mode = _access_mode, \
985 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
986 .integer_size_bits = _integer_size_bits, \
987 .len_bits = _len_bits, \
988 .signedness = _signedness, \
989 .byte_order = _byte_order, \
991 .offset_bits = _offset_bits, \
998 #define side_type_gather_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
999 _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1000 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1001 #define side_type_gather_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1002 _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_HOST, \
1003 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1005 #define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1006 _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_LE, \
1007 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1008 #define side_type_gather_signed_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1009 _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_LE, \
1010 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1012 #define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1013 _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_BE, \
1014 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1015 #define side_type_gather_signed_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1016 _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_BE, \
1017 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1019 #define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1020 _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1021 #define side_field_gather_signed_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1022 _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1024 #define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1025 _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1026 #define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1027 _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1029 #define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1030 _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1031 #define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \
1032 _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1034 #define _side_type_gather_float(_byte_order, _offset, _float_size_bits, _access_mode, _attr) \
1036 .type = SIDE_TYPE_GATHER_FLOAT, \
1041 .offset = _offset, \
1042 .access_mode = _access_mode, \
1045 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1046 .float_size_bits = _float_size_bits, \
1047 .byte_order = _byte_order, \
1055 #define side_type_gather_float(_offset, _float_size_bits, _access_mode, _attr) \
1056 _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size_bits, _access_mode, _attr)
1057 #define side_type_gather_float_le(_offset, _float_size_bits, _access_mode, _attr) \
1058 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size_bits, _access_mode, _attr)
1059 #define side_type_gather_float_be(_offset, _float_size_bits, _access_mode, _attr) \
1060 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size_bits, _access_mode, _attr)
1062 #define side_field_gather_float(_name, _offset, _float_size_bits, _access_mode, _attr) \
1063 _side_field(_name, side_type_gather_float(_offset, _float_size_bits, _access_mode, _attr))
1064 #define side_field_gather_float_le(_name, _offset, _float_size_bits, _access_mode, _attr) \
1065 _side_field(_name, side_type_gather_float_le(_offset, _float_size_bits, _access_mode, _attr))
1066 #define side_field_gather_float_be(_name, _offset, _float_size_bits, _access_mode, _attr) \
1067 _side_field(_name, side_type_gather_float_be(_offset, _float_size_bits, _access_mode, _attr))
1069 #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
1071 .type = SIDE_TYPE_GATHER_STRUCT, \
1076 .offset = _offset, \
1077 .access_mode = _access_mode, \
1078 .type = _struct_gather, \
1085 #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \
1086 _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode))
1088 #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr) \
1090 .type = SIDE_TYPE_GATHER_ARRAY, \
1095 .offset = _offset, \
1096 .access_mode = _access_mode, \
1098 .elem_type = _elem_type_gather, \
1100 .length = _length, \
1101 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1108 #define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr) \
1109 _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM(_attr)))
1111 #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1113 .type = SIDE_TYPE_GATHER_VLA, \
1118 .offset = _offset, \
1119 .access_mode = _access_mode, \
1121 .elem_type = _elem_type_gather, \
1123 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1125 .length_type = _length_type_gather, \
1131 #define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1132 _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM(_attr)))
1134 #define side_elem(...) \
1135 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1137 #define side_length(...) \
1138 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1140 #define side_field_list(...) \
1141 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
1143 /* Static field arguments */
1145 #define side_arg_null(_val) { .type = SIDE_TYPE_NULL }
1146 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = !!(_val) } } }
1147 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_static = { .byte_value = (_val) } } }
1148 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1150 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1151 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1152 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1153 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1154 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
1155 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
1156 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
1157 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
1158 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { .side_static = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } } }
1159 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1160 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1161 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1162 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1163 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
1164 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
1165 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
1166 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
1167 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
1168 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
1170 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = (_side_type) } } }
1171 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
1172 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
1173 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
1175 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1176 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1177 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1178 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1179 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1180 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1181 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1182 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1183 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1184 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
1186 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1187 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1188 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1189 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1190 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1191 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1192 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1193 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1194 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1195 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
1197 /* Gather field arguments */
1198 #define side_arg_gather_byte(_ptr) { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = (_ptr) } } }
1199 #define side_arg_gather_unsigned_integer(_ptr) { .type = SIDE_TYPE_GATHER_UNSIGNED_INT, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1200 #define side_arg_gather_signed_integer(_ptr) { .type = SIDE_TYPE_GATHER_SIGNED_INT, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1201 #define side_arg_gather_float(_ptr) { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = (_ptr) } } }
1202 #define side_arg_gather_struct(_ptr) { .type = SIDE_TYPE_GATHER_STRUCT, .u = { .side_static = { .side_struct_gather_ptr = (_ptr) } } }
1203 #define side_arg_gather_array(_ptr) { .type = SIDE_TYPE_GATHER_ARRAY, .u = { .side_static = { .side_array_gather_ptr = (_ptr) } } }
1204 #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) } } } }
1206 /* Dynamic field arguments */
1208 #define side_arg_dynamic_null(_attr) \
1210 .type = SIDE_TYPE_DYNAMIC_NULL, \
1215 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1221 #define side_arg_dynamic_bool(_val, _attr) \
1223 .type = SIDE_TYPE_DYNAMIC_BOOL, \
1229 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1231 .value = !!(_val), \
1237 #define side_arg_dynamic_byte(_val, _attr) \
1239 .type = SIDE_TYPE_DYNAMIC_BYTE, \
1245 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1252 #define side_arg_dynamic_string(_val, _attr) \
1254 .type = SIDE_TYPE_DYNAMIC_STRING, \
1260 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1262 .value = (uintptr_t) (_val), \
1268 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
1276 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1277 .integer_size_bits = _integer_size_bits, \
1278 .len_bits = _len_bits, \
1279 .signedness = _signedness, \
1280 .byte_order = _byte_order, \
1290 #define side_arg_dynamic_u8(_val, _attr) \
1291 _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1292 #define side_arg_dynamic_s8(_val, _attr) \
1293 _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1295 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1296 _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_U16, false, _byte_order, 16, 16, SIDE_PARAM(_attr))
1297 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1298 _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_U32, false, _byte_order, 32, 32, SIDE_PARAM(_attr))
1299 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1300 _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_U64, false, _byte_order, 64, 64, SIDE_PARAM(_attr))
1302 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1303 _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_S16, true, _byte_order, 16, 16, SIDE_PARAM(_attr))
1304 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1305 _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_S32, true, _byte_order, 32, 32, SIDE_PARAM(_attr))
1306 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1307 _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_S64, true, _byte_order, 64, 64, SIDE_PARAM(_attr))
1309 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1310 _side_arg_dynamic_integer(SIDE_PTR_HOST, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER_HOST, false, _byte_order, \
1311 SIDE_BITS_PER_LONG, SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
1313 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size_bits, _attr) \
1321 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1322 .float_size_bits = _float_size_bits, \
1323 .byte_order = _byte_order, \
1333 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1334 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY16, _byte_order, 16, SIDE_PARAM(_attr))
1335 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1336 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY32, _byte_order, 32, SIDE_PARAM(_attr))
1337 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1338 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY64, _byte_order, 64, SIDE_PARAM(_attr))
1339 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1340 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY128, _byte_order, 128, SIDE_PARAM(_attr))
1343 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1344 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1345 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1346 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1347 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1348 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1349 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1350 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1351 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1352 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1353 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1356 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1357 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1358 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1359 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1360 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1361 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1362 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1363 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1364 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1365 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1366 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1369 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1370 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1371 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1372 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1373 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1374 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1375 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1376 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1377 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1378 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1379 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1381 #define side_arg_dynamic_vla(_vla) \
1383 .type = SIDE_TYPE_DYNAMIC_VLA, \
1386 .side_dynamic_vla = (_vla), \
1391 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1393 .type = SIDE_TYPE_DYNAMIC_VLA_VISITOR, \
1396 .side_dynamic_vla_visitor = { \
1398 .visitor = _dynamic_vla_visitor, \
1400 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1406 #define side_arg_dynamic_struct(_struct) \
1408 .type = SIDE_TYPE_DYNAMIC_STRUCT, \
1411 .side_dynamic_struct = (_struct), \
1416 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1418 .type = SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, \
1421 .side_dynamic_struct_visitor = { \
1423 .visitor = _dynamic_struct_visitor, \
1425 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1431 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1432 const struct side_arg _identifier##_vec[] = { _sav }; \
1433 const struct side_arg_dynamic_vla _identifier = { \
1434 .sav = _identifier##_vec, \
1436 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1437 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1440 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1441 const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \
1442 const struct side_arg_dynamic_struct _identifier = { \
1443 .fields = _identifier##_fields, \
1445 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1446 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1449 #define side_arg_define_vec(_identifier, _sav) \
1450 const struct side_arg _identifier##_vec[] = { _sav }; \
1451 const struct side_arg_vec _identifier = { \
1452 .sav = _identifier##_vec, \
1453 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1456 #define side_arg_dynamic_field(_name, _elem) \
1458 .field_name = _name, \
1462 #define side_arg_list(...) __VA_ARGS__
1464 #define side_define_enum(_identifier, _mappings, _attr) \
1465 const struct side_enum_mappings _identifier = { \
1466 .mappings = _mappings, \
1468 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1469 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1472 #define side_enum_mapping_list(...) \
1473 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1475 #define side_enum_mapping_range(_label, _begin, _end) \
1477 .range_begin = _begin, \
1478 .range_end = _end, \
1482 #define side_enum_mapping_value(_label, _value) \
1484 .range_begin = _value, \
1485 .range_end = _value, \
1489 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1490 const struct side_enum_bitmap_mappings _identifier = { \
1491 .mappings = _mappings, \
1493 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1494 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1497 #define side_enum_bitmap_mapping_list(...) \
1498 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1500 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1502 .range_begin = _begin, \
1503 .range_end = _end, \
1507 #define side_enum_bitmap_mapping_value(_label, _value) \
1509 .range_begin = _value, \
1510 .range_end = _value, \
1514 #define side_event_cond(_identifier) \
1515 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1518 #define side_event_call(_identifier, _sav) \
1520 const struct side_arg side_sav[] = { _sav }; \
1521 const struct side_arg_vec side_arg_vec = { \
1523 .len = SIDE_ARRAY_SIZE(side_sav), \
1525 side_call(&(_identifier), &side_arg_vec); \
1528 #define side_event(_identifier, _sav) \
1529 side_event_cond(_identifier) \
1530 side_event_call(_identifier, SIDE_PARAM(_sav))
1532 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1534 const struct side_arg side_sav[] = { _sav }; \
1535 const struct side_arg_vec side_arg_vec = { \
1537 .len = SIDE_ARRAY_SIZE(side_sav), \
1539 const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \
1540 const struct side_arg_dynamic_struct var_struct = { \
1541 .fields = side_fields, \
1543 .len = SIDE_ARRAY_SIZE(side_fields), \
1544 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1546 side_call_variadic(&(_identifier), &side_arg_vec, &var_struct); \
1549 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1550 side_event_cond(_identifier) \
1551 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1553 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1554 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1555 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1557 .enabled = &(side_event_enable__##_identifier), \
1558 .provider_name = _provider, \
1559 .event_name = _event, \
1560 .fields = _fields, \
1562 .callbacks = &side_empty_callback, \
1563 .flags = (_flags), \
1565 .loglevel = _loglevel, \
1566 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1567 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1568 .nr_callbacks = 0, \
1570 static const struct side_event_description *side_event_ptr__##_identifier \
1571 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1573 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1574 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1575 SIDE_PARAM(_attr), 0)
1577 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1578 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1579 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1581 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1582 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1583 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0)
1585 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1586 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1587 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1589 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1590 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1591 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0)
1593 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1594 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1595 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1597 #define side_declare_event(_identifier) \
1598 extern uintptr_t side_event_enable_##_identifier; \
1599 extern struct side_event_description _identifier
1601 extern const struct side_callback side_empty_callback
;
1603 void side_call(const struct side_event_description
*desc
,
1604 const struct side_arg_vec
*side_arg_vec
);
1605 void side_call_variadic(const struct side_event_description
*desc
,
1606 const struct side_arg_vec
*side_arg_vec
,
1607 const struct side_arg_dynamic_struct
*var_struct
);
1609 typedef void (*side_tracer_callback_func
)(const struct side_event_description
*desc
,
1610 const struct side_arg_vec
*side_arg_vec
,
1612 typedef void (*side_tracer_callback_variadic_func
)(const struct side_event_description
*desc
,
1613 const struct side_arg_vec
*side_arg_vec
,
1614 const struct side_arg_dynamic_struct
*var_struct
,
1617 int side_tracer_callback_register(struct side_event_description
*desc
,
1618 side_tracer_callback_func call
,
1620 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1621 side_tracer_callback_variadic_func call_variadic
,
1623 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1624 side_tracer_callback_func call
,
1626 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1627 side_tracer_callback_variadic_func call_variadic
,
1630 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
,
1631 uint32_t nr_events
);
1632 void side_events_unregister(struct side_events_register_handle
*handle
);
1634 enum side_tracer_notification
{
1635 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1636 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1639 /* Callback is invoked with side library internal lock held. */
1640 struct side_tracer_handle
*side_tracer_event_notification_register(
1641 void (*cb
)(enum side_tracer_notification notif
,
1642 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1644 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1646 void side_init(void);
1647 void side_exit(void);
1650 * These weak symbols, the constructor, and destructor take care of
1651 * registering only _one_ instance of the side instrumentation per
1652 * shared-ojbect (or for the whole main program).
1654 extern struct side_event_description
* __start_side_event_description_ptr
[]
1655 __attribute__((weak
, visibility("hidden")));
1656 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1657 __attribute__((weak
, visibility("hidden")));
1658 int side_event_description_ptr_registered
1659 __attribute__((weak
, visibility("hidden")));
1660 struct side_events_register_handle
*side_events_handle
1661 __attribute__((weak
, visibility("hidden")));
1664 side_event_description_ptr_init(void)
1665 __attribute__((no_instrument_function
))
1666 __attribute__((constructor
));
1668 side_event_description_ptr_init(void)
1670 if (side_event_description_ptr_registered
++)
1672 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1673 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1677 side_event_description_ptr_exit(void)
1678 __attribute__((no_instrument_function
))
1679 __attribute__((destructor
));
1681 side_event_description_ptr_exit(void)
1683 if (--side_event_description_ptr_registered
)
1685 side_events_unregister(side_events_handle
);
1686 side_events_handle
= NULL
;
1689 #endif /* _SIDE_TRACE_H */