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_tracer_visitor_ctx
;
30 struct side_tracer_dynamic_struct_visitor_ctx
;
31 struct side_tracer_dynamic_vla_visitor_ctx
;
32 struct side_event_description
;
33 struct side_arg_dynamic_event_struct
;
34 struct side_events_register_handle
;
49 SIDE_TYPE_FLOAT_BINARY16
,
50 SIDE_TYPE_FLOAT_BINARY32
,
51 SIDE_TYPE_FLOAT_BINARY64
,
52 SIDE_TYPE_FLOAT_BINARY128
,
59 SIDE_TYPE_VLA_VISITOR
,
70 SIDE_TYPE_ARRAY_POINTER
,
81 SIDE_TYPE_VLA_POINTER
,
83 /* Enumeration types */
85 SIDE_TYPE_ENUM_BITMAP
,
91 enum side_dynamic_type
{
93 SIDE_DYNAMIC_TYPE_NULL
,
94 SIDE_DYNAMIC_TYPE_BOOL
,
96 SIDE_DYNAMIC_TYPE_U16
,
97 SIDE_DYNAMIC_TYPE_U32
,
98 SIDE_DYNAMIC_TYPE_U64
,
100 SIDE_DYNAMIC_TYPE_S16
,
101 SIDE_DYNAMIC_TYPE_S32
,
102 SIDE_DYNAMIC_TYPE_S64
,
103 SIDE_DYNAMIC_TYPE_BYTE
,
104 SIDE_DYNAMIC_TYPE_POINTER
,
105 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
,
106 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
,
107 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
,
108 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
,
109 SIDE_DYNAMIC_TYPE_STRING
,
112 SIDE_DYNAMIC_TYPE_STRUCT
,
113 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
,
114 SIDE_DYNAMIC_TYPE_VLA
,
115 SIDE_DYNAMIC_TYPE_VLA_VISITOR
,
118 enum side_attr_type
{
129 SIDE_ATTR_TYPE_POINTER
,
130 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
131 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
132 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
133 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
134 SIDE_ATTR_TYPE_STRING
,
138 SIDE_LOGLEVEL_EMERG
= 0,
139 SIDE_LOGLEVEL_ALERT
= 1,
140 SIDE_LOGLEVEL_CRIT
= 2,
141 SIDE_LOGLEVEL_ERR
= 3,
142 SIDE_LOGLEVEL_WARNING
= 4,
143 SIDE_LOGLEVEL_NOTICE
= 5,
144 SIDE_LOGLEVEL_INFO
= 6,
145 SIDE_LOGLEVEL_DEBUG
= 7,
148 enum side_visitor_status
{
149 SIDE_VISITOR_STATUS_OK
= 0,
150 SIDE_VISITOR_STATUS_ERROR
= -1,
155 SIDE_ERROR_INVAL
= 1,
156 SIDE_ERROR_EXIST
= 2,
157 SIDE_ERROR_NOMEM
= 3,
158 SIDE_ERROR_NOENT
= 4,
159 SIDE_ERROR_EXITING
= 5,
162 enum side_type_byte_order
{
163 SIDE_TYPE_BYTE_ORDER_LE
= 0,
164 SIDE_TYPE_BYTE_ORDER_BE
= 1,
167 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
168 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
170 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
173 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
174 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
176 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
179 typedef enum side_visitor_status (*side_visitor
)(
180 const struct side_tracer_visitor_ctx
*tracer_ctx
,
182 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
183 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
185 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
186 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
189 struct side_attr_value
{
190 uint32_t type
; /* enum side_attr_type */
201 uintptr_t side_pointer
;
203 _Float16 side_float_binary16
;
206 _Float32 side_float_binary32
;
209 _Float64 side_float_binary64
;
212 _Float128 side_float_binary128
;
218 /* User attributes. */
221 const struct side_attr_value value
;
224 struct side_enum_mapping
{
230 struct side_enum_mappings
{
231 const struct side_enum_mapping
*mappings
;
232 const struct side_attr
*attr
;
233 uint32_t nr_mappings
;
237 struct side_enum_bitmap_mapping
{
238 uint64_t range_begin
;
243 struct side_enum_bitmap_mappings
{
244 const struct side_enum_bitmap_mapping
*mappings
;
245 const struct side_attr
*attr
;
246 uint32_t nr_mappings
;
250 struct side_type_struct
{
253 const struct side_event_field
*fields
;
254 const struct side_attr
*attr
;
257 struct side_type_description
{
258 uint32_t type
; /* enum side_type */
262 const struct side_attr
*attr
;
264 uint32_t byte_order
; /* enum side_type_byte_order */
269 const struct side_type_description
*elem_type
;
270 const struct side_attr
*attr
;
275 const struct side_type_description
*elem_type
;
276 const struct side_attr
*attr
;
280 const struct side_type_description
*elem_type
;
281 side_visitor visitor
;
282 const struct side_attr
*attr
;
285 const struct side_type_struct
*side_struct
;
287 /* Enumeration types */
289 const struct side_enum_mappings
*mappings
;
290 const struct side_type_description
*elem_type
;
293 const struct side_enum_bitmap_mappings
*mappings
;
294 const struct side_type_description
*elem_type
;
299 struct side_event_field
{
300 const char *field_name
;
301 struct side_type_description side_type
;
304 enum side_event_flags
{
305 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
308 struct side_callback
{
310 void (*call
)(const struct side_event_description
*desc
,
311 const struct side_arg_vec_description
*sav_desc
,
313 void (*call_variadic
)(const struct side_event_description
*desc
,
314 const struct side_arg_vec_description
*sav_desc
,
315 const struct side_arg_dynamic_event_struct
*var_struct
,
321 struct side_event_description
{
323 const char *provider_name
;
324 const char *event_name
;
325 const struct side_event_field
*fields
;
326 const struct side_attr
*attr
;
327 const struct side_callback
*callbacks
;
330 uint32_t loglevel
; /* enum side_loglevel */
333 uint32_t nr_callbacks
;
336 struct side_arg_dynamic_vec
{
337 uint32_t dynamic_type
; /* enum side_dynamic_type */
341 const struct side_attr
*attr
;
343 uint32_t byte_order
; /* enum side_type_byte_order */
355 uintptr_t side_pointer
;
357 _Float16 side_float_binary16
;
360 _Float32 side_float_binary32
;
363 _Float64 side_float_binary64
;
366 _Float128 side_float_binary128
;
373 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
376 side_dynamic_struct_visitor visitor
;
377 const struct side_attr
*attr
;
379 } side_dynamic_struct_visitor
;
380 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
383 side_dynamic_vla_visitor visitor
;
384 const struct side_attr
*attr
;
386 } side_dynamic_vla_visitor
;
390 struct side_arg_dynamic_vec_vla
{
391 const struct side_arg_dynamic_vec
*sav
;
392 const struct side_attr
*attr
;
397 struct side_arg_dynamic_event_field
{
398 const char *field_name
;
399 const struct side_arg_dynamic_vec elem
;
402 struct side_arg_dynamic_event_struct
{
403 const struct side_arg_dynamic_event_field
*fields
;
404 const struct side_attr
*attr
;
409 struct side_arg_vec
{
423 uintptr_t side_pointer
;
425 _Float16 side_float_binary16
;
428 _Float32 side_float_binary32
;
431 _Float64 side_float_binary64
;
434 _Float128 side_float_binary128
;
439 const struct side_arg_vec_description
*side_struct
;
440 const struct side_arg_vec_description
*side_array
;
441 const struct side_arg_vec_description
*side_vla
;
442 void *side_vla_app_visitor_ctx
;
443 void *side_array_fixint
;
450 struct side_arg_dynamic_vec dynamic
;
454 struct side_arg_vec_description
{
455 const struct side_arg_vec
*sav
;
459 /* The visitor pattern is a double-dispatch visitor. */
460 struct side_tracer_visitor_ctx
{
461 enum side_visitor_status (*write_elem
)(
462 const struct side_tracer_visitor_ctx
*tracer_ctx
,
463 const struct side_arg_vec
*elem
);
464 void *priv
; /* Private tracer context. */
467 struct side_tracer_dynamic_struct_visitor_ctx
{
468 enum side_visitor_status (*write_field
)(
469 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
470 const struct side_arg_dynamic_event_field
*dynamic_field
);
471 void *priv
; /* Private tracer context. */
474 struct side_tracer_dynamic_vla_visitor_ctx
{
475 enum side_visitor_status (*write_elem
)(
476 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
477 const struct side_arg_dynamic_vec
*elem
);
478 void *priv
; /* Private tracer context. */
481 /* Event and type attributes */
483 #define side_attr(_key, _value) \
486 .value = SIDE_PARAM(_value), \
489 #define side_attr_list(...) \
490 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
492 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
493 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
494 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
495 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
496 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
497 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
498 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
499 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
500 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
501 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
502 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER, .u = { .side_pointer = (uintptr_t) (_val) } }
503 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
504 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
505 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
506 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
507 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
509 /* Static field definition */
511 #define _side_type_basic(_type, _byte_order, _attr) \
517 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
518 .byte_order = _byte_order, \
523 #define _side_field(_name, _type) \
525 .field_name = _name, \
526 .side_type = _type, \
530 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
531 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
532 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
533 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
534 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
535 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
536 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
537 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
538 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
539 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
540 #define side_type_pointer(_attr) _side_type_basic(SIDE_TYPE_POINTER, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
541 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
542 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
543 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
544 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
545 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
546 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
548 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
549 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
550 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
551 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
552 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
553 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
554 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
555 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
556 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
557 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
558 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
559 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
560 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
561 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
562 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
563 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
564 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
567 #define side_type_u16_le(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
568 #define side_type_u32_le(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
569 #define side_type_u64_le(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
570 #define side_type_s16_le(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
571 #define side_type_s32_le(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
572 #define side_type_s64_le(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
573 #define side_type_pointer_le(_attr) _side_type_basic(SIDE_TYPE_POINTER, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
574 #define side_type_float_binary16_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
575 #define side_type_float_binary32_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
576 #define side_type_float_binary64_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
577 #define side_type_float_binary128_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
579 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
580 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
581 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
582 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
583 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
584 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
585 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
586 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
587 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
588 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
589 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
592 #define side_type_u16_be(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
593 #define side_type_u32_be(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
594 #define side_type_u64_be(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
595 #define side_type_s16_be(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
596 #define side_type_s32_be(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
597 #define side_type_s64_be(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
598 #define side_type_pointer_be(_attr) _side_type_basic(SIDE_TYPE_POINTER, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
599 #define side_type_float_binary16_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
600 #define side_type_float_binary32_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
601 #define side_type_float_binary64_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
602 #define side_type_float_binary128_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
604 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
605 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
606 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
607 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
608 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
609 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
610 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
611 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
612 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
613 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
614 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
616 #define side_type_enum(_mappings, _elem_type) \
618 .type = SIDE_TYPE_ENUM, \
621 .mappings = _mappings, \
622 .elem_type = _elem_type, \
626 #define side_field_enum(_name, _mappings, _elem_type) \
627 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
629 #define side_type_enum_bitmap(_mappings, _elem_type) \
631 .type = SIDE_TYPE_ENUM_BITMAP, \
633 .side_enum_bitmap = { \
634 .mappings = _mappings, \
635 .elem_type = _elem_type, \
639 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
640 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
642 #define side_type_struct(_struct) \
644 .type = SIDE_TYPE_STRUCT, \
646 .side_struct = _struct, \
649 #define side_field_struct(_name, _struct) \
650 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
652 #define _side_type_struct_define(_fields, _attr) \
654 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
655 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
660 #define side_define_struct(_identifier, _fields, _attr) \
661 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
663 #define side_struct_literal(_fields, _attr) \
664 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
665 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
667 #define side_type_array(_elem_type, _length, _attr) \
669 .type = SIDE_TYPE_ARRAY, \
672 .elem_type = _elem_type, \
675 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
679 #define side_field_array(_name, _elem_type, _length, _attr) \
680 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
682 #define side_type_vla(_elem_type, _attr) \
684 .type = SIDE_TYPE_VLA, \
687 .elem_type = _elem_type, \
689 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
693 #define side_field_vla(_name, _elem_type, _attr) \
694 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
696 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
698 .type = SIDE_TYPE_VLA_VISITOR, \
700 .side_vla_visitor = { \
701 .elem_type = SIDE_PARAM(_elem_type), \
702 .visitor = _visitor, \
704 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
708 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
709 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
711 #define side_elem(...) \
712 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
714 #define side_field_list(...) \
715 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
717 /* Static field arguments */
719 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
720 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
721 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
722 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
723 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
724 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
725 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
726 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
727 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
728 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
729 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER, .u = { .side_pointer = (uintptr_t) (_val) } }
730 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
731 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
732 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
733 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
734 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
735 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
736 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
737 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
738 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
739 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
741 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
742 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
743 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
744 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
745 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
747 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
748 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
749 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
750 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
751 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
752 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
753 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
754 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
755 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
756 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER, .u = { .side_array_fixint = (_ptr) } }
758 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
759 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
760 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
761 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
762 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
763 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
764 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
765 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
766 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
767 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
769 #define side_arg_dynamic(_dynamic_arg_type) \
771 .type = SIDE_TYPE_DYNAMIC, \
773 .dynamic = _dynamic_arg_type, \
777 /* Dynamic field arguments */
779 #define side_arg_dynamic_null(_attr) \
781 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
785 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
786 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
791 #define side_arg_dynamic_bool(_val, _attr) \
793 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
797 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
798 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
800 .side_bool = !!(_val), \
806 #define side_arg_dynamic_u8(_val, _attr) \
808 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
812 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
813 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
820 #define side_arg_dynamic_s8(_val, _attr) \
822 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
826 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
827 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
834 #define side_arg_dynamic_byte(_val, _attr) \
836 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
840 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
841 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
843 .side_byte = (_val), \
848 #define side_arg_dynamic_string(_val, _attr) \
850 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
854 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
855 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
863 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
865 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
869 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
870 .byte_order = _byte_order, \
872 .side_u16 = (_val), \
877 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
879 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
883 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
884 .byte_order = _byte_order, \
886 .side_u32 = (_val), \
891 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
893 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
897 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
898 .byte_order = _byte_order, \
900 .side_u64 = (_val), \
906 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
908 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
912 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
913 .byte_order = _byte_order, \
915 .side_s16 = (_val), \
920 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
922 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
926 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
927 .byte_order = _byte_order, \
929 .side_s32 = (_val), \
934 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
936 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
940 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
941 .byte_order = _byte_order, \
943 .side_s64 = (_val), \
948 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
950 .dynamic_type = SIDE_DYNAMIC_TYPE_POINTER, \
954 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
955 .byte_order = _byte_order, \
957 .side_pointer = (uintptr_t) (_val), \
962 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
964 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
968 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
969 .byte_order = _byte_order, \
971 .side_float_binary16 = (_val), \
976 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
978 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
982 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
983 .byte_order = _byte_order, \
985 .side_float_binary32 = (_val), \
990 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
992 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
996 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
997 .byte_order = _byte_order, \
999 .side_float_binary64 = (_val), \
1004 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1006 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
1010 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1011 .byte_order = _byte_order, \
1013 .side_float_binary128 = (_val), \
1020 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1021 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1022 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1023 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1024 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1025 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1026 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1027 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1028 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1029 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1030 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1033 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1034 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1035 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1036 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1037 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1038 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1039 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1040 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1041 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1042 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1043 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1046 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1047 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1048 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1049 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1050 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1051 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1052 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1053 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1054 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1055 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1056 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1058 #define side_arg_dynamic_vla(_vla) \
1060 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1062 .side_dynamic_vla = (_vla), \
1066 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1068 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1070 .side_dynamic_vla_visitor = { \
1072 .visitor = _dynamic_vla_visitor, \
1074 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1079 #define side_arg_dynamic_struct(_struct) \
1081 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1083 .side_dynamic_struct = (_struct), \
1087 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1089 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1091 .side_dynamic_struct_visitor = { \
1093 .visitor = _dynamic_struct_visitor, \
1095 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1100 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1101 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1102 const struct side_arg_dynamic_vec_vla _identifier = { \
1103 .sav = _identifier##_vec, \
1105 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1106 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1109 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1110 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1111 const struct side_arg_dynamic_event_struct _identifier = { \
1112 .fields = _identifier##_fields, \
1114 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1115 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1118 #define side_arg_define_vec(_identifier, _sav) \
1119 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1120 const struct side_arg_vec_description _identifier = { \
1121 .sav = _identifier##_vec, \
1122 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1125 #define side_arg_dynamic_field(_name, _elem) \
1127 .field_name = _name, \
1131 #define side_arg_list(...) __VA_ARGS__
1133 #define side_define_enum(_identifier, _mappings, _attr) \
1134 const struct side_enum_mappings _identifier = { \
1135 .mappings = _mappings, \
1137 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1138 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1141 #define side_enum_mapping_list(...) \
1142 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1144 #define side_enum_mapping_range(_label, _begin, _end) \
1146 .range_begin = _begin, \
1147 .range_end = _end, \
1151 #define side_enum_mapping_value(_label, _value) \
1153 .range_begin = _value, \
1154 .range_end = _value, \
1158 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1159 const struct side_enum_bitmap_mappings _identifier = { \
1160 .mappings = _mappings, \
1162 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1163 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1166 #define side_enum_bitmap_mapping_list(...) \
1167 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1169 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1171 .range_begin = _begin, \
1172 .range_end = _end, \
1176 #define side_enum_bitmap_mapping_value(_label, _value) \
1178 .range_begin = _value, \
1179 .range_end = _value, \
1183 #define side_event_cond(_identifier) \
1184 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1187 #define side_event_call(_identifier, _sav) \
1189 const struct side_arg_vec side_sav[] = { _sav }; \
1190 const struct side_arg_vec_description sav_desc = { \
1192 .len = SIDE_ARRAY_SIZE(side_sav), \
1194 side_call(&(_identifier), &sav_desc); \
1197 #define side_event(_identifier, _sav) \
1198 side_event_cond(_identifier) \
1199 side_event_call(_identifier, SIDE_PARAM(_sav))
1201 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1203 const struct side_arg_vec side_sav[] = { _sav }; \
1204 const struct side_arg_vec_description sav_desc = { \
1206 .len = SIDE_ARRAY_SIZE(side_sav), \
1208 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1209 const struct side_arg_dynamic_event_struct var_struct = { \
1210 .fields = side_fields, \
1212 .len = SIDE_ARRAY_SIZE(side_fields), \
1213 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1215 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1218 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1219 side_event_cond(_identifier) \
1220 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1222 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1223 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1224 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1227 .enabled = &(side_event_enable__##_identifier), \
1228 .loglevel = _loglevel, \
1229 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1230 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1231 .nr_callbacks = 0, \
1232 .flags = (_flags), \
1233 .provider_name = _provider, \
1234 .event_name = _event, \
1235 .fields = _fields, \
1237 .callbacks = &side_empty_callback, \
1239 static const struct side_event_description *side_event_ptr__##_identifier \
1240 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1242 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1243 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1244 SIDE_PARAM(_attr), 0)
1246 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1247 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1248 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1250 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1251 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1252 SIDE_PARAM(_attr), 0)
1254 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1255 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1256 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1258 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1259 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1260 SIDE_PARAM(_attr), 0)
1262 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1263 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1264 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1266 #define side_declare_event(_identifier) \
1267 extern uintptr_t side_event_enable_##_identifier; \
1268 extern struct side_event_description _identifier
1270 extern const struct side_callback side_empty_callback
;
1272 void side_call(const struct side_event_description
*desc
,
1273 const struct side_arg_vec_description
*sav_desc
);
1274 void side_call_variadic(const struct side_event_description
*desc
,
1275 const struct side_arg_vec_description
*sav_desc
,
1276 const struct side_arg_dynamic_event_struct
*var_struct
);
1278 int side_tracer_callback_register(struct side_event_description
*desc
,
1279 void (*call
)(const struct side_event_description
*desc
,
1280 const struct side_arg_vec_description
*sav_desc
,
1283 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1284 void (*call_variadic
)(const struct side_event_description
*desc
,
1285 const struct side_arg_vec_description
*sav_desc
,
1286 const struct side_arg_dynamic_event_struct
*var_struct
,
1289 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1290 void (*call
)(const struct side_event_description
*desc
,
1291 const struct side_arg_vec_description
*sav_desc
,
1294 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1295 void (*call_variadic
)(const struct side_event_description
*desc
,
1296 const struct side_arg_vec_description
*sav_desc
,
1297 const struct side_arg_dynamic_event_struct
*var_struct
,
1301 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
, uint32_t nr_events
);
1302 void side_events_unregister(struct side_events_register_handle
*handle
);
1304 enum side_tracer_notification
{
1305 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1306 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1309 /* Callback is invoked with side library internal lock held. */
1310 struct side_tracer_handle
*side_tracer_event_notification_register(
1311 void (*cb
)(enum side_tracer_notification notif
,
1312 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1314 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1316 void side_init(void);
1317 void side_exit(void);
1320 * These weak symbols, the constructor, and destructor take care of
1321 * registering only _one_ instance of the side instrumentation per
1322 * shared-ojbect (or for the whole main program).
1324 extern struct side_event_description
* __start_side_event_description_ptr
[]
1325 __attribute__((weak
, visibility("hidden")));
1326 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1327 __attribute__((weak
, visibility("hidden")));
1328 int side_event_description_ptr_registered
1329 __attribute__((weak
, visibility("hidden")));
1330 struct side_events_register_handle
*side_events_handle
1331 __attribute__((weak
, visibility("hidden")));
1334 side_event_description_ptr_init(void)
1335 __attribute__((no_instrument_function
))
1336 __attribute__((constructor
));
1338 side_event_description_ptr_init(void)
1340 if (side_event_description_ptr_registered
++)
1342 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1343 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1347 side_event_description_ptr_exit(void)
1348 __attribute__((no_instrument_function
))
1349 __attribute__((destructor
));
1351 side_event_description_ptr_exit(void)
1353 if (--side_event_description_ptr_registered
)
1355 side_events_unregister(side_events_handle
);
1356 side_events_handle
= NULL
;
1359 #endif /* _SIDE_TRACE_H */