1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 #include <side/macros.h>
15 #include <side/endian.h>
17 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
19 //TODO: as those structures will be ABI, we need to either consider them
20 //fixed forever, or think of a scheme that would allow their binary
21 //representation to be extended if need be.
24 struct side_arg_vec_description
;
25 struct side_arg_dynamic_vec
;
26 struct side_arg_dynamic_vec_vla
;
27 struct side_type_description
;
28 struct side_event_field
;
29 struct side_event_field_sg
;
30 struct side_tracer_visitor_ctx
;
31 struct side_tracer_dynamic_struct_visitor_ctx
;
32 struct side_tracer_dynamic_vla_visitor_ctx
;
33 struct side_event_description
;
34 struct side_arg_dynamic_event_struct
;
35 struct side_events_register_handle
;
51 SIDE_TYPE_FLOAT_BINARY16
,
52 SIDE_TYPE_FLOAT_BINARY32
,
53 SIDE_TYPE_FLOAT_BINARY64
,
54 SIDE_TYPE_FLOAT_BINARY128
,
62 SIDE_TYPE_VLA_VISITOR
,
73 SIDE_TYPE_ARRAY_POINTER32
,
74 SIDE_TYPE_ARRAY_POINTER64
,
85 SIDE_TYPE_VLA_POINTER32
,
86 SIDE_TYPE_VLA_POINTER64
,
88 /* Enumeration types */
90 SIDE_TYPE_ENUM_BITMAP
,
96 enum side_dynamic_type
{
98 SIDE_DYNAMIC_TYPE_NULL
,
99 SIDE_DYNAMIC_TYPE_BOOL
,
100 SIDE_DYNAMIC_TYPE_U8
,
101 SIDE_DYNAMIC_TYPE_U16
,
102 SIDE_DYNAMIC_TYPE_U32
,
103 SIDE_DYNAMIC_TYPE_U64
,
104 SIDE_DYNAMIC_TYPE_S8
,
105 SIDE_DYNAMIC_TYPE_S16
,
106 SIDE_DYNAMIC_TYPE_S32
,
107 SIDE_DYNAMIC_TYPE_S64
,
108 SIDE_DYNAMIC_TYPE_BYTE
,
109 SIDE_DYNAMIC_TYPE_POINTER32
,
110 SIDE_DYNAMIC_TYPE_POINTER64
,
111 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
,
112 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
,
113 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
,
114 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
,
115 SIDE_DYNAMIC_TYPE_STRING
,
118 SIDE_DYNAMIC_TYPE_STRUCT
,
119 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
,
120 SIDE_DYNAMIC_TYPE_VLA
,
121 SIDE_DYNAMIC_TYPE_VLA_VISITOR
,
124 enum side_attr_type
{
135 SIDE_ATTR_TYPE_POINTER32
,
136 SIDE_ATTR_TYPE_POINTER64
,
137 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
138 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
139 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
140 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
141 SIDE_ATTR_TYPE_STRING
,
145 SIDE_TYPE_SG_UNSIGNED_INT
,
146 SIDE_TYPE_SG_SIGNED_INT
,
150 SIDE_LOGLEVEL_EMERG
= 0,
151 SIDE_LOGLEVEL_ALERT
= 1,
152 SIDE_LOGLEVEL_CRIT
= 2,
153 SIDE_LOGLEVEL_ERR
= 3,
154 SIDE_LOGLEVEL_WARNING
= 4,
155 SIDE_LOGLEVEL_NOTICE
= 5,
156 SIDE_LOGLEVEL_INFO
= 6,
157 SIDE_LOGLEVEL_DEBUG
= 7,
160 enum side_visitor_status
{
161 SIDE_VISITOR_STATUS_OK
= 0,
162 SIDE_VISITOR_STATUS_ERROR
= -1,
167 SIDE_ERROR_INVAL
= 1,
168 SIDE_ERROR_EXIST
= 2,
169 SIDE_ERROR_NOMEM
= 3,
170 SIDE_ERROR_NOENT
= 4,
171 SIDE_ERROR_EXITING
= 5,
174 enum side_type_byte_order
{
175 SIDE_TYPE_BYTE_ORDER_LE
= 0,
176 SIDE_TYPE_BYTE_ORDER_BE
= 1,
179 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
180 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
182 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
185 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
186 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
188 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
191 typedef enum side_visitor_status (*side_visitor
)(
192 const struct side_tracer_visitor_ctx
*tracer_ctx
,
194 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
195 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
197 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
198 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
201 union side_integer_value
{
212 union side_float_value
{
214 _Float16 side_float_binary16
;
217 _Float32 side_float_binary32
;
220 _Float64 side_float_binary64
;
223 _Float128 side_float_binary128
;
227 struct side_attr_value
{
228 uint32_t type
; /* enum side_attr_type */
230 union side_integer_value integer_value
;
231 union side_float_value float_value
;
233 uint64_t string
; /* const char * */
237 /* User attributes. */
240 const struct side_attr_value value
;
243 struct side_type_integer
{
244 const struct side_attr
*attr
;
246 uint16_t integer_size_bits
; /* bits */
247 uint16_t len_bits
; /* bits */
248 uint8_t signedness
; /* true/false */
249 uint8_t byte_order
; /* enum side_type_byte_order */
252 struct side_type_float
{
253 const struct side_attr
*attr
;
255 uint32_t byte_order
; /* enum side_type_byte_order */
256 uint16_t float_size_bits
; /* bits */
259 struct side_enum_mapping
{
265 struct side_enum_mappings
{
266 const struct side_enum_mapping
*mappings
;
267 const struct side_attr
*attr
;
268 uint32_t nr_mappings
;
272 struct side_enum_bitmap_mapping
{
273 uint64_t range_begin
;
278 struct side_enum_bitmap_mappings
{
279 const struct side_enum_bitmap_mapping
*mappings
;
280 const struct side_attr
*attr
;
281 uint32_t nr_mappings
;
285 struct side_type_struct
{
288 const struct side_event_field
*fields
;
289 const struct side_attr
*attr
;
292 struct side_type_sg_description
{
293 uint64_t offset
; /* bytes */
294 uint32_t type
; /* enum side_type_sg */
297 struct side_type_integer type
;
298 uint16_t offset_bits
; /* bits */
303 struct side_struct_field_sg
{
304 const char *field_name
;
305 struct side_type_sg_description side_type
;
308 /* Structure fields scatter-gather. */
309 struct side_type_struct_sg
{
312 const struct side_struct_field_sg
*fields_sg
;
313 const struct side_attr
*attr
;
316 struct side_type_description
{
317 uint32_t type
; /* enum side_type */
321 const struct side_attr
*attr
;
323 uint32_t byte_order
; /* enum side_type_byte_order */
326 struct side_type_integer side_integer
;
327 struct side_type_float side_float
;
331 const struct side_type_description
*elem_type
;
332 const struct side_attr
*attr
;
337 const struct side_type_description
*elem_type
;
338 const struct side_attr
*attr
;
342 const struct side_type_description
*elem_type
;
343 side_visitor visitor
;
344 const struct side_attr
*attr
;
347 const struct side_type_struct
*side_struct
;
348 const struct side_type_struct_sg
*side_struct_sg
;
350 /* Enumeration types */
352 const struct side_enum_mappings
*mappings
;
353 const struct side_type_description
*elem_type
;
356 const struct side_enum_bitmap_mappings
*mappings
;
357 const struct side_type_description
*elem_type
;
362 struct side_event_field
{
363 const char *field_name
;
364 struct side_type_description side_type
;
367 enum side_event_flags
{
368 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
371 struct side_callback
{
373 void (*call
)(const struct side_event_description
*desc
,
374 const struct side_arg_vec_description
*sav_desc
,
376 void (*call_variadic
)(const struct side_event_description
*desc
,
377 const struct side_arg_vec_description
*sav_desc
,
378 const struct side_arg_dynamic_event_struct
*var_struct
,
384 struct side_event_description
{
386 const char *provider_name
;
387 const char *event_name
;
388 const struct side_event_field
*fields
;
389 const struct side_attr
*attr
;
390 const struct side_callback
*callbacks
;
393 uint32_t loglevel
; /* enum side_loglevel */
396 uint32_t nr_callbacks
;
399 struct side_arg_dynamic_vec
{
400 uint32_t dynamic_type
; /* enum side_dynamic_type */
404 const struct side_attr
*attr
;
406 uint32_t byte_order
; /* enum side_type_byte_order */
410 uint64_t string
; /* const char * */
416 struct side_type_integer type
;
417 union side_integer_value value
;
421 struct side_type_float type
;
422 union side_float_value value
;
426 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
429 side_dynamic_struct_visitor visitor
;
430 const struct side_attr
*attr
;
432 } side_dynamic_struct_visitor
;
433 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
436 side_dynamic_vla_visitor visitor
;
437 const struct side_attr
*attr
;
439 } side_dynamic_vla_visitor
;
443 struct side_arg_dynamic_vec_vla
{
444 const struct side_arg_dynamic_vec
*sav
;
445 const struct side_attr
*attr
;
450 struct side_arg_dynamic_event_field
{
451 const char *field_name
;
452 const struct side_arg_dynamic_vec elem
;
455 struct side_arg_dynamic_event_struct
{
456 const struct side_arg_dynamic_event_field
*fields
;
457 const struct side_attr
*attr
;
462 struct side_arg_vec
{
466 union side_integer_value integer_value
;
469 union side_float_value float_value
;
472 uint64_t string
; /* const char * */
475 const struct side_arg_vec_description
*side_struct
;
476 const struct side_arg_vec_description
*side_array
;
477 const struct side_arg_vec_description
*side_vla
;
478 void *side_vla_app_visitor_ctx
;
479 void *side_array_fixint
;
484 void *side_struct_sg_ptr
;
487 struct side_arg_dynamic_vec dynamic
;
491 struct side_arg_vec_description
{
492 const struct side_arg_vec
*sav
;
496 /* The visitor pattern is a double-dispatch visitor. */
497 struct side_tracer_visitor_ctx
{
498 enum side_visitor_status (*write_elem
)(
499 const struct side_tracer_visitor_ctx
*tracer_ctx
,
500 const struct side_arg_vec
*elem
);
501 void *priv
; /* Private tracer context. */
504 struct side_tracer_dynamic_struct_visitor_ctx
{
505 enum side_visitor_status (*write_field
)(
506 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
507 const struct side_arg_dynamic_event_field
*dynamic_field
);
508 void *priv
; /* Private tracer context. */
511 struct side_tracer_dynamic_vla_visitor_ctx
{
512 enum side_visitor_status (*write_elem
)(
513 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
514 const struct side_arg_dynamic_vec
*elem
);
515 void *priv
; /* Private tracer context. */
518 /* Event and type attributes */
520 #if SIDE_BITS_PER_LONG == 64
521 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
522 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
523 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
524 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER64
525 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
526 # define SIDE_PTR_HOST .side_u64
528 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
529 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
530 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
531 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER32
532 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
533 # define SIDE_PTR_HOST .side_u32
536 #define side_attr(_key, _value) \
539 .value = SIDE_PARAM(_value), \
542 #define side_attr_list(...) \
543 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
545 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
546 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
547 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
548 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
549 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
550 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
551 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
552 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
553 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
554 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
555 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
556 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
557 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
558 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
559 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
560 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
562 /* Static field definition */
564 #define _side_type_basic(_type, _byte_order, _attr) \
570 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
571 .byte_order = _byte_order, \
576 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
582 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
583 .integer_size_bits = _integer_size_bits, \
584 .len_bits = _len_bits, \
585 .signedness = _signedness, \
586 .byte_order = _byte_order, \
591 #define _side_type_float(_type, _byte_order, _float_size_bits, _attr) \
597 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
598 .byte_order = _byte_order, \
599 .float_size_bits = _float_size_bits, \
604 #define _side_field(_name, _type) \
606 .field_name = _name, \
607 .side_type = _type, \
611 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
612 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
613 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
614 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
615 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
616 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
617 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
618 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
619 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
620 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
621 #define side_type_pointer(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
622 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 16, SIDE_PARAM(_attr))
623 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 32, SIDE_PARAM(_attr))
624 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 64, SIDE_PARAM(_attr))
625 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 128, SIDE_PARAM(_attr))
626 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
627 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
629 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
630 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
631 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
632 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
633 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
634 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
635 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
636 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
637 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
638 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
639 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
640 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
641 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
642 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
643 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
644 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
645 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
648 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
649 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
650 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
651 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
652 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
653 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
654 #define side_type_pointer_le(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
655 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, 16, SIDE_PARAM(_attr))
656 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, 32, SIDE_PARAM(_attr))
657 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, 64, SIDE_PARAM(_attr))
658 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 128, SIDE_PARAM(_attr))
660 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
661 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
662 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
663 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
664 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
665 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
666 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
667 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
668 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
669 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
670 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
673 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
674 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
675 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
676 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
677 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
678 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
679 #define side_type_pointer_be(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
680 #define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, 16, SIDE_PARAM(_attr))
681 #define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, 32, SIDE_PARAM(_attr))
682 #define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, 64, SIDE_PARAM(_attr))
683 #define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, 128, SIDE_PARAM(_attr))
685 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
686 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
687 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
688 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
689 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
690 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
691 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
692 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
693 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
694 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
695 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
697 #define side_type_enum(_mappings, _elem_type) \
699 .type = SIDE_TYPE_ENUM, \
702 .mappings = _mappings, \
703 .elem_type = _elem_type, \
707 #define side_field_enum(_name, _mappings, _elem_type) \
708 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
710 #define side_type_enum_bitmap(_mappings, _elem_type) \
712 .type = SIDE_TYPE_ENUM_BITMAP, \
714 .side_enum_bitmap = { \
715 .mappings = _mappings, \
716 .elem_type = _elem_type, \
720 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
721 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
723 #define side_type_struct(_struct) \
725 .type = SIDE_TYPE_STRUCT, \
727 .side_struct = _struct, \
730 #define side_field_struct(_name, _struct) \
731 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
733 #define _side_type_struct_define(_fields, _attr) \
735 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
736 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
741 #define side_define_struct(_identifier, _fields, _attr) \
742 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
744 #define side_struct_literal(_fields, _attr) \
745 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
746 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
748 /* Scatter-gather struct */
750 #define _side_type_sg_integer(_type, _signedness, _byte_order, _offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
758 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
759 .integer_size_bits = _integer_size_bits, \
760 .len_bits = _len_bits, \
761 .signedness = _signedness, \
762 .byte_order = _byte_order, \
764 .offset_bits = _offset_bits, \
769 #define _side_field_sg(_name, _type) \
771 .field_name = _name, \
772 .side_type = _type, \
775 #define side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
776 _side_type_sg_integer(SIDE_TYPE_SG_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_HOST, \
777 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
778 #define side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
779 _side_type_sg_integer(SIDE_TYPE_SG_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_HOST, \
780 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
782 #define side_field_sg_unsigned_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
783 _side_field_sg(_name, side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
784 #define side_field_sg_signed_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
785 _side_field_sg(_name, side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
787 #define side_type_struct_sg(_struct_sg) \
789 .type = SIDE_TYPE_STRUCT_SG, \
791 .side_struct_sg = _struct_sg, \
794 #define side_field_struct_sg(_name, _struct_sg) \
795 _side_field(_name, side_type_struct_sg(SIDE_PARAM(_struct_sg)))
797 #define _side_type_struct_sg_define(_fields_sg, _attr) \
799 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields_sg)), \
800 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
801 .fields_sg = _fields_sg, \
805 #define side_define_struct_sg(_identifier, _fields_sg, _attr) \
806 const struct side_type_struct_sg _identifier = _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr))
808 #define side_struct_sg_literal(_fields_sg, _attr) \
809 SIDE_COMPOUND_LITERAL(const struct side_type_struct_sg, \
810 _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr)))
812 #define side_type_array(_elem_type, _length, _attr) \
814 .type = SIDE_TYPE_ARRAY, \
817 .elem_type = _elem_type, \
820 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
824 #define side_field_array(_name, _elem_type, _length, _attr) \
825 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
827 #define side_type_vla(_elem_type, _attr) \
829 .type = SIDE_TYPE_VLA, \
832 .elem_type = _elem_type, \
834 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
838 #define side_field_vla(_name, _elem_type, _attr) \
839 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
841 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
843 .type = SIDE_TYPE_VLA_VISITOR, \
845 .side_vla_visitor = { \
846 .elem_type = SIDE_PARAM(_elem_type), \
847 .visitor = _visitor, \
849 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
853 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
854 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
856 #define side_elem(...) \
857 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
859 #define side_field_list(...) \
860 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
862 #define side_field_sg_list(...) \
863 SIDE_COMPOUND_LITERAL(const struct side_struct_field_sg, __VA_ARGS__)
865 /* Static field arguments */
867 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
868 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
869 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
870 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
871 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
872 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
873 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
874 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
875 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
876 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
877 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
878 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .integer_value = { .side_u8 = (_val) } } }
879 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .integer_value = { .side_u16 = (_val) } } }
880 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .integer_value = { .side_u32 = (_val) } } }
881 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .integer_value = { .side_u64 = (_val) } } }
882 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
883 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
884 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
885 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
886 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
887 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
889 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
890 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
891 #define side_arg_struct_sg(_ptr) { .type = SIDE_TYPE_STRUCT_SG, .u = { .side_struct_sg_ptr = (_ptr) } }
892 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
893 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
894 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
896 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
897 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
898 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
899 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
900 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
901 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
902 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
903 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
904 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
905 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_array_fixint = (_ptr) } }
907 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
908 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
909 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
910 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
911 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
912 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
913 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
914 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
915 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
916 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
918 #define side_arg_dynamic(_dynamic_arg_type) \
920 .type = SIDE_TYPE_DYNAMIC, \
922 .dynamic = _dynamic_arg_type, \
926 /* Dynamic field arguments */
928 #define side_arg_dynamic_null(_attr) \
930 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
934 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
935 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
940 #define side_arg_dynamic_bool(_val, _attr) \
942 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
946 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
947 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
949 .side_bool = !!(_val), \
955 #define side_arg_dynamic_byte(_val, _attr) \
957 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
961 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
962 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
964 .side_byte = (_val), \
969 #define side_arg_dynamic_string(_val, _attr) \
971 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
975 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
976 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
978 .string = (uintptr_t) (_val), \
984 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
986 .dynamic_type = _type, \
991 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
992 .integer_size_bits = _integer_size_bits, \
993 .len_bits = _len_bits, \
994 .signedness = _signedness, \
995 .byte_order = _byte_order, \
1004 #define side_arg_dynamic_u8(_val, _attr) \
1005 _side_arg_dynamic_integer(.side_u8, _val, SIDE_DYNAMIC_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1006 #define side_arg_dynamic_s8(_val, _attr) \
1007 _side_arg_dynamic_integer(.side_s8, _val, SIDE_DYNAMIC_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1009 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1010 _side_arg_dynamic_integer(.side_u16, _val, SIDE_DYNAMIC_TYPE_U16, false, _byte_order, 16, 16, SIDE_PARAM(_attr))
1011 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1012 _side_arg_dynamic_integer(.side_u32, _val, SIDE_DYNAMIC_TYPE_U32, false, _byte_order, 32, 32, SIDE_PARAM(_attr))
1013 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1014 _side_arg_dynamic_integer(.side_u64, _val, SIDE_DYNAMIC_TYPE_U64, false, _byte_order, 64, 64, SIDE_PARAM(_attr))
1016 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1017 _side_arg_dynamic_integer(.side_s16, _val, SIDE_DYNAMIC_TYPE_S16, true, _byte_order, 16, 16, SIDE_PARAM(_attr))
1018 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1019 _side_arg_dynamic_integer(.side_s32, _val, SIDE_DYNAMIC_TYPE_S32, true, _byte_order, 32, 32, SIDE_PARAM(_attr))
1020 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1021 _side_arg_dynamic_integer(.side_s64, _val, SIDE_DYNAMIC_TYPE_S64, true, _byte_order, 64, 64, SIDE_PARAM(_attr))
1023 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1024 _side_arg_dynamic_integer(SIDE_PTR_HOST, (uintptr_t) (_val), SIDE_DYNAMIC_TYPE_POINTER_HOST, false, _byte_order, \
1025 SIDE_BITS_PER_LONG, SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
1027 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size_bits, _attr) \
1029 .dynamic_type = _type, \
1034 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1035 .byte_order = _byte_order, \
1036 .float_size_bits = _float_size_bits, \
1045 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1046 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, _byte_order, 16, SIDE_PARAM(_attr))
1047 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1048 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, _byte_order, 32, SIDE_PARAM(_attr))
1049 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1050 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, _byte_order, 64, SIDE_PARAM(_attr))
1051 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1052 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, _byte_order, 128, SIDE_PARAM(_attr))
1055 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1056 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1057 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1058 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1059 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1060 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1061 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1062 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1063 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1064 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1065 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1068 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1069 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1070 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1071 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1072 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1073 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1074 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1075 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1076 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1077 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1078 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1081 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1082 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1083 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1084 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1085 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1086 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1087 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1088 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1089 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1090 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1091 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1093 #define side_arg_dynamic_vla(_vla) \
1095 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1097 .side_dynamic_vla = (_vla), \
1101 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1103 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1105 .side_dynamic_vla_visitor = { \
1107 .visitor = _dynamic_vla_visitor, \
1109 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1114 #define side_arg_dynamic_struct(_struct) \
1116 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1118 .side_dynamic_struct = (_struct), \
1122 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1124 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1126 .side_dynamic_struct_visitor = { \
1128 .visitor = _dynamic_struct_visitor, \
1130 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1135 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1136 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1137 const struct side_arg_dynamic_vec_vla _identifier = { \
1138 .sav = _identifier##_vec, \
1140 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1141 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1144 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1145 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1146 const struct side_arg_dynamic_event_struct _identifier = { \
1147 .fields = _identifier##_fields, \
1149 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1150 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1153 #define side_arg_define_vec(_identifier, _sav) \
1154 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1155 const struct side_arg_vec_description _identifier = { \
1156 .sav = _identifier##_vec, \
1157 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1160 #define side_arg_dynamic_field(_name, _elem) \
1162 .field_name = _name, \
1166 #define side_arg_list(...) __VA_ARGS__
1168 #define side_define_enum(_identifier, _mappings, _attr) \
1169 const struct side_enum_mappings _identifier = { \
1170 .mappings = _mappings, \
1172 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1173 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1176 #define side_enum_mapping_list(...) \
1177 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1179 #define side_enum_mapping_range(_label, _begin, _end) \
1181 .range_begin = _begin, \
1182 .range_end = _end, \
1186 #define side_enum_mapping_value(_label, _value) \
1188 .range_begin = _value, \
1189 .range_end = _value, \
1193 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1194 const struct side_enum_bitmap_mappings _identifier = { \
1195 .mappings = _mappings, \
1197 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1198 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1201 #define side_enum_bitmap_mapping_list(...) \
1202 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1204 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1206 .range_begin = _begin, \
1207 .range_end = _end, \
1211 #define side_enum_bitmap_mapping_value(_label, _value) \
1213 .range_begin = _value, \
1214 .range_end = _value, \
1218 #define side_event_cond(_identifier) \
1219 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1222 #define side_event_call(_identifier, _sav) \
1224 const struct side_arg_vec side_sav[] = { _sav }; \
1225 const struct side_arg_vec_description sav_desc = { \
1227 .len = SIDE_ARRAY_SIZE(side_sav), \
1229 side_call(&(_identifier), &sav_desc); \
1232 #define side_event(_identifier, _sav) \
1233 side_event_cond(_identifier) \
1234 side_event_call(_identifier, SIDE_PARAM(_sav))
1236 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1238 const struct side_arg_vec side_sav[] = { _sav }; \
1239 const struct side_arg_vec_description sav_desc = { \
1241 .len = SIDE_ARRAY_SIZE(side_sav), \
1243 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1244 const struct side_arg_dynamic_event_struct var_struct = { \
1245 .fields = side_fields, \
1247 .len = SIDE_ARRAY_SIZE(side_fields), \
1248 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1250 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1253 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1254 side_event_cond(_identifier) \
1255 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1257 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1258 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1259 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1261 .enabled = &(side_event_enable__##_identifier), \
1262 .provider_name = _provider, \
1263 .event_name = _event, \
1264 .fields = _fields, \
1266 .callbacks = &side_empty_callback, \
1267 .flags = (_flags), \
1269 .loglevel = _loglevel, \
1270 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1271 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1272 .nr_callbacks = 0, \
1274 static const struct side_event_description *side_event_ptr__##_identifier \
1275 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1277 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1278 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1279 SIDE_PARAM(_attr), 0)
1281 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1282 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1283 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1285 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1286 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1287 SIDE_PARAM(_attr), 0)
1289 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1290 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1291 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1293 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1294 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1295 SIDE_PARAM(_attr), 0)
1297 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1298 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1299 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1301 #define side_declare_event(_identifier) \
1302 extern uintptr_t side_event_enable_##_identifier; \
1303 extern struct side_event_description _identifier
1305 extern const struct side_callback side_empty_callback
;
1307 void side_call(const struct side_event_description
*desc
,
1308 const struct side_arg_vec_description
*sav_desc
);
1309 void side_call_variadic(const struct side_event_description
*desc
,
1310 const struct side_arg_vec_description
*sav_desc
,
1311 const struct side_arg_dynamic_event_struct
*var_struct
);
1313 int side_tracer_callback_register(struct side_event_description
*desc
,
1314 void (*call
)(const struct side_event_description
*desc
,
1315 const struct side_arg_vec_description
*sav_desc
,
1318 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1319 void (*call_variadic
)(const struct side_event_description
*desc
,
1320 const struct side_arg_vec_description
*sav_desc
,
1321 const struct side_arg_dynamic_event_struct
*var_struct
,
1324 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1325 void (*call
)(const struct side_event_description
*desc
,
1326 const struct side_arg_vec_description
*sav_desc
,
1329 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1330 void (*call_variadic
)(const struct side_event_description
*desc
,
1331 const struct side_arg_vec_description
*sav_desc
,
1332 const struct side_arg_dynamic_event_struct
*var_struct
,
1336 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
, uint32_t nr_events
);
1337 void side_events_unregister(struct side_events_register_handle
*handle
);
1339 enum side_tracer_notification
{
1340 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1341 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1344 /* Callback is invoked with side library internal lock held. */
1345 struct side_tracer_handle
*side_tracer_event_notification_register(
1346 void (*cb
)(enum side_tracer_notification notif
,
1347 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1349 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1351 void side_init(void);
1352 void side_exit(void);
1355 * These weak symbols, the constructor, and destructor take care of
1356 * registering only _one_ instance of the side instrumentation per
1357 * shared-ojbect (or for the whole main program).
1359 extern struct side_event_description
* __start_side_event_description_ptr
[]
1360 __attribute__((weak
, visibility("hidden")));
1361 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1362 __attribute__((weak
, visibility("hidden")));
1363 int side_event_description_ptr_registered
1364 __attribute__((weak
, visibility("hidden")));
1365 struct side_events_register_handle
*side_events_handle
1366 __attribute__((weak
, visibility("hidden")));
1369 side_event_description_ptr_init(void)
1370 __attribute__((no_instrument_function
))
1371 __attribute__((constructor
));
1373 side_event_description_ptr_init(void)
1375 if (side_event_description_ptr_registered
++)
1377 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1378 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1382 side_event_description_ptr_exit(void)
1383 __attribute__((no_instrument_function
))
1384 __attribute__((destructor
));
1386 side_event_description_ptr_exit(void)
1388 if (--side_event_description_ptr_registered
)
1390 side_events_unregister(side_events_handle
);
1391 side_events_handle
= NULL
;
1394 #endif /* _SIDE_TRACE_H */