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 struct side_attr_value
{
202 uint32_t type
; /* enum side_attr_type */
214 _Float16 side_float_binary16
;
217 _Float32 side_float_binary32
;
220 _Float64 side_float_binary64
;
223 _Float128 side_float_binary128
;
225 uint64_t string
; /* const char * */
229 /* User attributes. */
232 const struct side_attr_value value
;
235 struct side_enum_mapping
{
241 struct side_enum_mappings
{
242 const struct side_enum_mapping
*mappings
;
243 const struct side_attr
*attr
;
244 uint32_t nr_mappings
;
248 struct side_enum_bitmap_mapping
{
249 uint64_t range_begin
;
254 struct side_enum_bitmap_mappings
{
255 const struct side_enum_bitmap_mapping
*mappings
;
256 const struct side_attr
*attr
;
257 uint32_t nr_mappings
;
261 struct side_type_struct
{
264 const struct side_event_field
*fields
;
265 const struct side_attr
*attr
;
268 struct side_type_sg_description
{
269 uint32_t type
; /* enum side_type_sg */
273 uint64_t integer_offset
; /* bytes */
274 const struct side_attr
*attr
;
276 uint32_t byte_order
; /* enum side_type_byte_order */
277 uint8_t integer_size_bits
; /* bits */
278 uint8_t offset_bits
; /* bits */
279 uint8_t len_bits
; /* bits */
284 struct side_struct_field_sg
{
285 const char *field_name
;
286 struct side_type_sg_description side_type
;
289 /* Structure fields scatter-gather. */
290 struct side_type_struct_sg
{
293 const struct side_struct_field_sg
*fields_sg
;
294 const struct side_attr
*attr
;
297 struct side_type_description
{
298 uint32_t type
; /* enum side_type */
302 const struct side_attr
*attr
;
304 uint32_t byte_order
; /* enum side_type_byte_order */
309 const struct side_type_description
*elem_type
;
310 const struct side_attr
*attr
;
315 const struct side_type_description
*elem_type
;
316 const struct side_attr
*attr
;
320 const struct side_type_description
*elem_type
;
321 side_visitor visitor
;
322 const struct side_attr
*attr
;
325 const struct side_type_struct
*side_struct
;
326 const struct side_type_struct_sg
*side_struct_sg
;
328 /* Enumeration types */
330 const struct side_enum_mappings
*mappings
;
331 const struct side_type_description
*elem_type
;
334 const struct side_enum_bitmap_mappings
*mappings
;
335 const struct side_type_description
*elem_type
;
340 struct side_event_field
{
341 const char *field_name
;
342 struct side_type_description side_type
;
345 enum side_event_flags
{
346 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
349 struct side_callback
{
351 void (*call
)(const struct side_event_description
*desc
,
352 const struct side_arg_vec_description
*sav_desc
,
354 void (*call_variadic
)(const struct side_event_description
*desc
,
355 const struct side_arg_vec_description
*sav_desc
,
356 const struct side_arg_dynamic_event_struct
*var_struct
,
362 struct side_event_description
{
364 const char *provider_name
;
365 const char *event_name
;
366 const struct side_event_field
*fields
;
367 const struct side_attr
*attr
;
368 const struct side_callback
*callbacks
;
371 uint32_t loglevel
; /* enum side_loglevel */
374 uint32_t nr_callbacks
;
377 struct side_arg_dynamic_vec
{
378 uint32_t dynamic_type
; /* enum side_dynamic_type */
382 const struct side_attr
*attr
;
384 uint32_t byte_order
; /* enum side_type_byte_order */
397 _Float16 side_float_binary16
;
400 _Float32 side_float_binary32
;
403 _Float64 side_float_binary64
;
406 _Float128 side_float_binary128
;
408 uint64_t string
; /* const char * */
413 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
416 side_dynamic_struct_visitor visitor
;
417 const struct side_attr
*attr
;
419 } side_dynamic_struct_visitor
;
420 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
423 side_dynamic_vla_visitor visitor
;
424 const struct side_attr
*attr
;
426 } side_dynamic_vla_visitor
;
430 struct side_arg_dynamic_vec_vla
{
431 const struct side_arg_dynamic_vec
*sav
;
432 const struct side_attr
*attr
;
437 struct side_arg_dynamic_event_field
{
438 const char *field_name
;
439 const struct side_arg_dynamic_vec elem
;
442 struct side_arg_dynamic_event_struct
{
443 const struct side_arg_dynamic_event_field
*fields
;
444 const struct side_attr
*attr
;
449 struct side_arg_vec
{
464 _Float16 side_float_binary16
;
467 _Float32 side_float_binary32
;
470 _Float64 side_float_binary64
;
473 _Float128 side_float_binary128
;
475 uint64_t string
; /* const char * */
478 const struct side_arg_vec_description
*side_struct
;
479 const struct side_arg_vec_description
*side_array
;
480 const struct side_arg_vec_description
*side_vla
;
481 void *side_vla_app_visitor_ctx
;
482 void *side_array_fixint
;
487 void *side_struct_sg_ptr
;
490 struct side_arg_dynamic_vec dynamic
;
494 struct side_arg_vec_description
{
495 const struct side_arg_vec
*sav
;
499 /* The visitor pattern is a double-dispatch visitor. */
500 struct side_tracer_visitor_ctx
{
501 enum side_visitor_status (*write_elem
)(
502 const struct side_tracer_visitor_ctx
*tracer_ctx
,
503 const struct side_arg_vec
*elem
);
504 void *priv
; /* Private tracer context. */
507 struct side_tracer_dynamic_struct_visitor_ctx
{
508 enum side_visitor_status (*write_field
)(
509 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
510 const struct side_arg_dynamic_event_field
*dynamic_field
);
511 void *priv
; /* Private tracer context. */
514 struct side_tracer_dynamic_vla_visitor_ctx
{
515 enum side_visitor_status (*write_elem
)(
516 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
517 const struct side_arg_dynamic_vec
*elem
);
518 void *priv
; /* Private tracer context. */
521 /* Event and type attributes */
523 #if SIDE_BITS_PER_LONG == 64
524 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
525 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
526 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
527 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER64
528 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
529 # define SIDE_PTR_HOST .side_u64
531 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
532 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
533 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
534 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER32
535 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
536 # define SIDE_PTR_HOST .side_u32
539 #define side_attr(_key, _value) \
542 .value = SIDE_PARAM(_value), \
545 #define side_attr_list(...) \
546 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
548 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
549 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
550 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
551 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
552 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
553 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
554 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
555 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
556 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
557 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
558 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { SIDE_PTR_HOST = (uintptr_t) (_val) } }
559 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
560 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
561 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
562 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
563 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
565 /* Static field definition */
567 #define _side_type_basic(_type, _byte_order, _attr) \
573 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
574 .byte_order = _byte_order, \
579 #define _side_field(_name, _type) \
581 .field_name = _name, \
582 .side_type = _type, \
586 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
587 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
588 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
589 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
590 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
591 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
592 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
593 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
594 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
595 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
596 #define side_type_pointer(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
597 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
598 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
599 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
600 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
601 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
602 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
604 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
605 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
606 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
607 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
608 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
609 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
610 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
611 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
612 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
613 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
614 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
615 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
616 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
617 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
618 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
619 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
620 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
623 #define side_type_u16_le(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
624 #define side_type_u32_le(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
625 #define side_type_u64_le(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
626 #define side_type_s16_le(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
627 #define side_type_s32_le(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
628 #define side_type_s64_le(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
629 #define side_type_pointer_le(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
630 #define side_type_float_binary16_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
631 #define side_type_float_binary32_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
632 #define side_type_float_binary64_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
633 #define side_type_float_binary128_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
635 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
636 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
637 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
638 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
639 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
640 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
641 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
642 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
643 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
644 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
645 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
648 #define side_type_u16_be(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
649 #define side_type_u32_be(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
650 #define side_type_u64_be(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
651 #define side_type_s16_be(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
652 #define side_type_s32_be(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
653 #define side_type_s64_be(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
654 #define side_type_pointer_be(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
655 #define side_type_float_binary16_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
656 #define side_type_float_binary32_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
657 #define side_type_float_binary64_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
658 #define side_type_float_binary128_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
660 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
661 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
662 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
663 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
664 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
665 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
666 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
667 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
668 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
669 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
670 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
672 #define side_type_enum(_mappings, _elem_type) \
674 .type = SIDE_TYPE_ENUM, \
677 .mappings = _mappings, \
678 .elem_type = _elem_type, \
682 #define side_field_enum(_name, _mappings, _elem_type) \
683 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
685 #define side_type_enum_bitmap(_mappings, _elem_type) \
687 .type = SIDE_TYPE_ENUM_BITMAP, \
689 .side_enum_bitmap = { \
690 .mappings = _mappings, \
691 .elem_type = _elem_type, \
695 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
696 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
698 #define side_type_struct(_struct) \
700 .type = SIDE_TYPE_STRUCT, \
702 .side_struct = _struct, \
705 #define side_field_struct(_name, _struct) \
706 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
708 #define _side_type_struct_define(_fields, _attr) \
710 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
711 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
716 #define side_define_struct(_identifier, _fields, _attr) \
717 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
719 #define side_struct_literal(_fields, _attr) \
720 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
721 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
723 /* Scatter-gather struct */
725 #define _side_type_sg_integer(_type, _byte_order, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
731 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
732 .byte_order = _byte_order, \
733 .integer_offset = _integer_offset, \
734 .integer_size_bits = _integer_size_bits, \
735 .offset_bits = _offset_bits, \
736 .len_bits = _len_bits, \
741 #define _side_field_sg(_name, _type) \
743 .field_name = _name, \
744 .side_type = _type, \
747 #define side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
748 _side_type_sg_integer(SIDE_TYPE_SG_UNSIGNED_INT, SIDE_TYPE_BYTE_ORDER_HOST, \
749 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
750 #define side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
751 _side_type_sg_integer(SIDE_TYPE_SG_SIGNED_INT, SIDE_TYPE_BYTE_ORDER_HOST, \
752 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
754 #define side_field_sg_unsigned_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
755 _side_field_sg(_name, side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
756 #define side_field_sg_signed_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
757 _side_field_sg(_name, side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
759 #define side_type_struct_sg(_struct_sg) \
761 .type = SIDE_TYPE_STRUCT_SG, \
763 .side_struct_sg = _struct_sg, \
766 #define side_field_struct_sg(_name, _struct_sg) \
767 _side_field(_name, side_type_struct_sg(SIDE_PARAM(_struct_sg)))
769 #define _side_type_struct_sg_define(_fields_sg, _attr) \
771 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields_sg)), \
772 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
773 .fields_sg = _fields_sg, \
777 #define side_define_struct_sg(_identifier, _fields_sg, _attr) \
778 const struct side_type_struct_sg _identifier = _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr))
780 #define side_struct_sg_literal(_fields_sg, _attr) \
781 SIDE_COMPOUND_LITERAL(const struct side_type_struct_sg, \
782 _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr)))
784 #define side_type_array(_elem_type, _length, _attr) \
786 .type = SIDE_TYPE_ARRAY, \
789 .elem_type = _elem_type, \
792 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
796 #define side_field_array(_name, _elem_type, _length, _attr) \
797 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
799 #define side_type_vla(_elem_type, _attr) \
801 .type = SIDE_TYPE_VLA, \
804 .elem_type = _elem_type, \
806 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
810 #define side_field_vla(_name, _elem_type, _attr) \
811 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
813 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
815 .type = SIDE_TYPE_VLA_VISITOR, \
817 .side_vla_visitor = { \
818 .elem_type = SIDE_PARAM(_elem_type), \
819 .visitor = _visitor, \
821 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
825 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
826 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
828 #define side_elem(...) \
829 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
831 #define side_field_list(...) \
832 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
834 #define side_field_sg_list(...) \
835 SIDE_COMPOUND_LITERAL(const struct side_struct_field_sg, __VA_ARGS__)
837 /* Static field arguments */
839 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
840 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
841 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
842 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
843 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
844 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
845 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
846 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
847 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
848 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
849 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { SIDE_PTR_HOST = (uintptr_t) (_val) } }
850 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
851 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
852 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
853 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
854 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
855 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
856 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
857 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
858 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
859 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
861 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
862 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
863 #define side_arg_struct_sg(_ptr) { .type = SIDE_TYPE_STRUCT_SG, .u = { .side_struct_sg_ptr = (_ptr) } }
864 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
865 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
866 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
868 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
869 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
870 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
871 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
872 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
873 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
874 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
875 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
876 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
877 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_array_fixint = (_ptr) } }
879 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
880 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
881 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
882 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
883 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
884 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
885 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
886 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
887 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
888 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
890 #define side_arg_dynamic(_dynamic_arg_type) \
892 .type = SIDE_TYPE_DYNAMIC, \
894 .dynamic = _dynamic_arg_type, \
898 /* Dynamic field arguments */
900 #define side_arg_dynamic_null(_attr) \
902 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
906 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
907 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
912 #define side_arg_dynamic_bool(_val, _attr) \
914 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
918 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
919 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
921 .side_bool = !!(_val), \
927 #define side_arg_dynamic_u8(_val, _attr) \
929 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
933 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
934 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
941 #define side_arg_dynamic_s8(_val, _attr) \
943 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
947 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
948 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
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_u16(_val, _byte_order, _attr) \
986 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
990 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
991 .byte_order = _byte_order, \
993 .side_u16 = (_val), \
998 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1000 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
1004 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1005 .byte_order = _byte_order, \
1007 .side_u32 = (_val), \
1012 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1014 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
1018 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1019 .byte_order = _byte_order, \
1021 .side_u64 = (_val), \
1027 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1029 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
1033 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1034 .byte_order = _byte_order, \
1036 .side_s16 = (_val), \
1041 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1043 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
1047 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1048 .byte_order = _byte_order, \
1050 .side_s32 = (_val), \
1055 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1057 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
1061 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1062 .byte_order = _byte_order, \
1064 .side_s64 = (_val), \
1069 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1071 .dynamic_type = SIDE_DYNAMIC_TYPE_POINTER_HOST, \
1075 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1076 .byte_order = _byte_order, \
1078 SIDE_PTR_HOST = (uintptr_t) (_val), \
1083 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1085 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
1089 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1090 .byte_order = _byte_order, \
1092 .side_float_binary16 = (_val), \
1097 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1099 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
1103 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1104 .byte_order = _byte_order, \
1106 .side_float_binary32 = (_val), \
1111 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1113 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
1117 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1118 .byte_order = _byte_order, \
1120 .side_float_binary64 = (_val), \
1125 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1127 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
1131 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1132 .byte_order = _byte_order, \
1134 .side_float_binary128 = (_val), \
1141 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1142 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1143 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1144 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1145 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1146 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1147 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1148 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1149 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1150 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1151 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1154 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1155 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1156 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1157 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1158 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1159 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1160 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1161 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1162 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1163 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1164 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1167 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1168 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1169 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1170 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1171 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1172 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1173 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1174 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1175 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1176 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1177 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1179 #define side_arg_dynamic_vla(_vla) \
1181 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1183 .side_dynamic_vla = (_vla), \
1187 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1189 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1191 .side_dynamic_vla_visitor = { \
1193 .visitor = _dynamic_vla_visitor, \
1195 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1200 #define side_arg_dynamic_struct(_struct) \
1202 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1204 .side_dynamic_struct = (_struct), \
1208 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1210 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1212 .side_dynamic_struct_visitor = { \
1214 .visitor = _dynamic_struct_visitor, \
1216 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1221 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1222 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1223 const struct side_arg_dynamic_vec_vla _identifier = { \
1224 .sav = _identifier##_vec, \
1226 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1227 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1230 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1231 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1232 const struct side_arg_dynamic_event_struct _identifier = { \
1233 .fields = _identifier##_fields, \
1235 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1236 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1239 #define side_arg_define_vec(_identifier, _sav) \
1240 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1241 const struct side_arg_vec_description _identifier = { \
1242 .sav = _identifier##_vec, \
1243 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1246 #define side_arg_dynamic_field(_name, _elem) \
1248 .field_name = _name, \
1252 #define side_arg_list(...) __VA_ARGS__
1254 #define side_define_enum(_identifier, _mappings, _attr) \
1255 const struct side_enum_mappings _identifier = { \
1256 .mappings = _mappings, \
1258 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1259 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1262 #define side_enum_mapping_list(...) \
1263 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1265 #define side_enum_mapping_range(_label, _begin, _end) \
1267 .range_begin = _begin, \
1268 .range_end = _end, \
1272 #define side_enum_mapping_value(_label, _value) \
1274 .range_begin = _value, \
1275 .range_end = _value, \
1279 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1280 const struct side_enum_bitmap_mappings _identifier = { \
1281 .mappings = _mappings, \
1283 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1284 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1287 #define side_enum_bitmap_mapping_list(...) \
1288 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1290 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1292 .range_begin = _begin, \
1293 .range_end = _end, \
1297 #define side_enum_bitmap_mapping_value(_label, _value) \
1299 .range_begin = _value, \
1300 .range_end = _value, \
1304 #define side_event_cond(_identifier) \
1305 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1308 #define side_event_call(_identifier, _sav) \
1310 const struct side_arg_vec side_sav[] = { _sav }; \
1311 const struct side_arg_vec_description sav_desc = { \
1313 .len = SIDE_ARRAY_SIZE(side_sav), \
1315 side_call(&(_identifier), &sav_desc); \
1318 #define side_event(_identifier, _sav) \
1319 side_event_cond(_identifier) \
1320 side_event_call(_identifier, SIDE_PARAM(_sav))
1322 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1324 const struct side_arg_vec side_sav[] = { _sav }; \
1325 const struct side_arg_vec_description sav_desc = { \
1327 .len = SIDE_ARRAY_SIZE(side_sav), \
1329 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1330 const struct side_arg_dynamic_event_struct var_struct = { \
1331 .fields = side_fields, \
1333 .len = SIDE_ARRAY_SIZE(side_fields), \
1334 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1336 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1339 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1340 side_event_cond(_identifier) \
1341 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1343 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1344 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1345 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1347 .enabled = &(side_event_enable__##_identifier), \
1348 .provider_name = _provider, \
1349 .event_name = _event, \
1350 .fields = _fields, \
1352 .callbacks = &side_empty_callback, \
1353 .flags = (_flags), \
1355 .loglevel = _loglevel, \
1356 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1357 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1358 .nr_callbacks = 0, \
1360 static const struct side_event_description *side_event_ptr__##_identifier \
1361 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1363 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1364 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1365 SIDE_PARAM(_attr), 0)
1367 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1368 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1369 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1371 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1372 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1373 SIDE_PARAM(_attr), 0)
1375 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1376 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1377 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1379 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1380 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1381 SIDE_PARAM(_attr), 0)
1383 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1384 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1385 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1387 #define side_declare_event(_identifier) \
1388 extern uintptr_t side_event_enable_##_identifier; \
1389 extern struct side_event_description _identifier
1391 extern const struct side_callback side_empty_callback
;
1393 void side_call(const struct side_event_description
*desc
,
1394 const struct side_arg_vec_description
*sav_desc
);
1395 void side_call_variadic(const struct side_event_description
*desc
,
1396 const struct side_arg_vec_description
*sav_desc
,
1397 const struct side_arg_dynamic_event_struct
*var_struct
);
1399 int side_tracer_callback_register(struct side_event_description
*desc
,
1400 void (*call
)(const struct side_event_description
*desc
,
1401 const struct side_arg_vec_description
*sav_desc
,
1404 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1405 void (*call_variadic
)(const struct side_event_description
*desc
,
1406 const struct side_arg_vec_description
*sav_desc
,
1407 const struct side_arg_dynamic_event_struct
*var_struct
,
1410 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1411 void (*call
)(const struct side_event_description
*desc
,
1412 const struct side_arg_vec_description
*sav_desc
,
1415 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1416 void (*call_variadic
)(const struct side_event_description
*desc
,
1417 const struct side_arg_vec_description
*sav_desc
,
1418 const struct side_arg_dynamic_event_struct
*var_struct
,
1422 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
, uint32_t nr_events
);
1423 void side_events_unregister(struct side_events_register_handle
*handle
);
1425 enum side_tracer_notification
{
1426 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1427 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1430 /* Callback is invoked with side library internal lock held. */
1431 struct side_tracer_handle
*side_tracer_event_notification_register(
1432 void (*cb
)(enum side_tracer_notification notif
,
1433 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1435 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1437 void side_init(void);
1438 void side_exit(void);
1441 * These weak symbols, the constructor, and destructor take care of
1442 * registering only _one_ instance of the side instrumentation per
1443 * shared-ojbect (or for the whole main program).
1445 extern struct side_event_description
* __start_side_event_description_ptr
[]
1446 __attribute__((weak
, visibility("hidden")));
1447 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1448 __attribute__((weak
, visibility("hidden")));
1449 int side_event_description_ptr_registered
1450 __attribute__((weak
, visibility("hidden")));
1451 struct side_events_register_handle
*side_events_handle
1452 __attribute__((weak
, visibility("hidden")));
1455 side_event_description_ptr_init(void)
1456 __attribute__((no_instrument_function
))
1457 __attribute__((constructor
));
1459 side_event_description_ptr_init(void)
1461 if (side_event_description_ptr_registered
++)
1463 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1464 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1468 side_event_description_ptr_exit(void)
1469 __attribute__((no_instrument_function
))
1470 __attribute__((destructor
));
1472 side_event_description_ptr_exit(void)
1474 if (--side_event_description_ptr_registered
)
1476 side_events_unregister(side_events_handle
);
1477 side_events_handle
= NULL
;
1480 #endif /* _SIDE_TRACE_H */