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
;
48 SIDE_TYPE_FLOAT_BINARY16
,
49 SIDE_TYPE_FLOAT_BINARY32
,
50 SIDE_TYPE_FLOAT_BINARY64
,
51 SIDE_TYPE_FLOAT_BINARY128
,
58 SIDE_TYPE_VLA_VISITOR
,
80 /* Enumeration types */
82 SIDE_TYPE_ENUM_BITMAP
,
88 enum side_dynamic_type
{
90 SIDE_DYNAMIC_TYPE_NULL
,
91 SIDE_DYNAMIC_TYPE_BOOL
,
93 SIDE_DYNAMIC_TYPE_U16
,
94 SIDE_DYNAMIC_TYPE_U32
,
95 SIDE_DYNAMIC_TYPE_U64
,
97 SIDE_DYNAMIC_TYPE_S16
,
98 SIDE_DYNAMIC_TYPE_S32
,
99 SIDE_DYNAMIC_TYPE_S64
,
100 SIDE_DYNAMIC_TYPE_BYTE
,
101 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
,
102 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
,
103 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
,
104 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
,
105 SIDE_DYNAMIC_TYPE_STRING
,
108 SIDE_DYNAMIC_TYPE_STRUCT
,
109 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
,
110 SIDE_DYNAMIC_TYPE_VLA
,
111 SIDE_DYNAMIC_TYPE_VLA_VISITOR
,
114 enum side_attr_type
{
125 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
126 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
127 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
128 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
129 SIDE_ATTR_TYPE_STRING
,
133 SIDE_LOGLEVEL_EMERG
= 0,
134 SIDE_LOGLEVEL_ALERT
= 1,
135 SIDE_LOGLEVEL_CRIT
= 2,
136 SIDE_LOGLEVEL_ERR
= 3,
137 SIDE_LOGLEVEL_WARNING
= 4,
138 SIDE_LOGLEVEL_NOTICE
= 5,
139 SIDE_LOGLEVEL_INFO
= 6,
140 SIDE_LOGLEVEL_DEBUG
= 7,
143 enum side_visitor_status
{
144 SIDE_VISITOR_STATUS_OK
= 0,
145 SIDE_VISITOR_STATUS_ERROR
= -1,
150 SIDE_ERROR_INVAL
= 1,
151 SIDE_ERROR_EXIST
= 2,
152 SIDE_ERROR_NOMEM
= 3,
153 SIDE_ERROR_NOENT
= 4,
154 SIDE_ERROR_EXITING
= 5,
157 enum side_type_byte_order
{
158 SIDE_TYPE_BYTE_ORDER_LE
= 0,
159 SIDE_TYPE_BYTE_ORDER_BE
= 1,
162 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
163 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
165 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
168 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
169 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
171 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
174 typedef enum side_visitor_status (*side_visitor
)(
175 const struct side_tracer_visitor_ctx
*tracer_ctx
,
177 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
178 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
180 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
181 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
184 struct side_attr_value
{
185 uint32_t type
; /* enum side_attr_type */
197 _Float16 side_float_binary16
;
200 _Float32 side_float_binary32
;
203 _Float64 side_float_binary64
;
206 _Float128 side_float_binary128
;
212 /* User attributes. */
215 const struct side_attr_value value
;
218 struct side_enum_mapping
{
224 struct side_enum_mappings
{
225 const struct side_enum_mapping
*mappings
;
226 const struct side_attr
*attr
;
227 uint32_t nr_mappings
;
231 struct side_enum_bitmap_mapping
{
232 uint64_t range_begin
;
237 struct side_enum_bitmap_mappings
{
238 const struct side_enum_bitmap_mapping
*mappings
;
239 const struct side_attr
*attr
;
240 uint32_t nr_mappings
;
244 struct side_type_struct
{
247 const struct side_event_field
*fields
;
248 const struct side_attr
*attr
;
251 struct side_type_description
{
252 uint32_t type
; /* enum side_type */
256 const struct side_attr
*attr
;
258 uint32_t byte_order
; /* enum side_type_byte_order */
263 const struct side_type_description
*elem_type
;
264 const struct side_attr
*attr
;
269 const struct side_type_description
*elem_type
;
270 const struct side_attr
*attr
;
274 const struct side_type_description
*elem_type
;
275 side_visitor visitor
;
276 const struct side_attr
*attr
;
279 const struct side_type_struct
*side_struct
;
281 /* Enumeration types */
283 const struct side_enum_mappings
*mappings
;
284 const struct side_type_description
*elem_type
;
287 const struct side_enum_bitmap_mappings
*mappings
;
288 const struct side_type_description
*elem_type
;
293 struct side_event_field
{
294 const char *field_name
;
295 struct side_type_description side_type
;
298 enum side_event_flags
{
299 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
302 struct side_callback
{
304 void (*call
)(const struct side_event_description
*desc
,
305 const struct side_arg_vec_description
*sav_desc
,
307 void (*call_variadic
)(const struct side_event_description
*desc
,
308 const struct side_arg_vec_description
*sav_desc
,
309 const struct side_arg_dynamic_event_struct
*var_struct
,
315 struct side_event_description
{
317 const char *provider_name
;
318 const char *event_name
;
319 const struct side_event_field
*fields
;
320 const struct side_attr
*attr
;
321 const struct side_callback
*callbacks
;
324 uint32_t loglevel
; /* enum side_loglevel */
327 uint32_t nr_callbacks
;
330 struct side_arg_dynamic_vec
{
331 uint32_t dynamic_type
; /* enum side_dynamic_type */
335 const struct side_attr
*attr
;
337 uint32_t byte_order
; /* enum side_type_byte_order */
350 _Float16 side_float_binary16
;
353 _Float32 side_float_binary32
;
356 _Float64 side_float_binary64
;
359 _Float128 side_float_binary128
;
366 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
369 side_dynamic_struct_visitor visitor
;
370 const struct side_attr
*attr
;
372 } side_dynamic_struct_visitor
;
373 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
376 side_dynamic_vla_visitor visitor
;
377 const struct side_attr
*attr
;
379 } side_dynamic_vla_visitor
;
383 struct side_arg_dynamic_vec_vla
{
384 const struct side_arg_dynamic_vec
*sav
;
385 const struct side_attr
*attr
;
390 struct side_arg_dynamic_event_field
{
391 const char *field_name
;
392 const struct side_arg_dynamic_vec elem
;
395 struct side_arg_dynamic_event_struct
{
396 const struct side_arg_dynamic_event_field
*fields
;
397 const struct side_attr
*attr
;
402 struct side_arg_vec
{
417 _Float16 side_float_binary16
;
420 _Float32 side_float_binary32
;
423 _Float64 side_float_binary64
;
426 _Float128 side_float_binary128
;
431 const struct side_arg_vec_description
*side_struct
;
432 const struct side_arg_vec_description
*side_array
;
433 const struct side_arg_vec_description
*side_vla
;
434 void *side_vla_app_visitor_ctx
;
435 void *side_array_fixint
;
442 struct side_arg_dynamic_vec dynamic
;
446 struct side_arg_vec_description
{
447 const struct side_arg_vec
*sav
;
451 /* The visitor pattern is a double-dispatch visitor. */
452 struct side_tracer_visitor_ctx
{
453 enum side_visitor_status (*write_elem
)(
454 const struct side_tracer_visitor_ctx
*tracer_ctx
,
455 const struct side_arg_vec
*elem
);
456 void *priv
; /* Private tracer context. */
459 struct side_tracer_dynamic_struct_visitor_ctx
{
460 enum side_visitor_status (*write_field
)(
461 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
462 const struct side_arg_dynamic_event_field
*dynamic_field
);
463 void *priv
; /* Private tracer context. */
466 struct side_tracer_dynamic_vla_visitor_ctx
{
467 enum side_visitor_status (*write_elem
)(
468 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
469 const struct side_arg_dynamic_vec
*elem
);
470 void *priv
; /* Private tracer context. */
473 /* Event and type attributes */
475 #define side_attr(_key, _value) \
478 .value = SIDE_PARAM(_value), \
481 #define side_attr_list(...) \
482 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
484 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
485 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
486 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
487 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
488 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
489 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
490 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
491 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
492 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
493 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
494 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
495 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
496 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
497 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
498 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
500 /* Static field definition */
502 #define _side_type_basic(_type, _byte_order, _attr) \
508 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
509 .byte_order = _byte_order, \
514 #define _side_field(_name, _type) \
516 .field_name = _name, \
517 .side_type = _type, \
521 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
522 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
523 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
524 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
525 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
526 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
527 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
528 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
529 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
530 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
531 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
532 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
533 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
534 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
535 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
536 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
538 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
539 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
540 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
541 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
542 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
543 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
544 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
545 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
546 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
547 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
548 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
549 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
550 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
551 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
552 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
553 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
556 #define side_type_u16_le(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
557 #define side_type_u32_le(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
558 #define side_type_u64_le(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
559 #define side_type_s16_le(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
560 #define side_type_s32_le(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
561 #define side_type_s64_le(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
562 #define side_type_float_binary16_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
563 #define side_type_float_binary32_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
564 #define side_type_float_binary64_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
565 #define side_type_float_binary128_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
567 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
568 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
569 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
570 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
571 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
572 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
573 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
574 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
575 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
576 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
579 #define side_type_u16_be(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
580 #define side_type_u32_be(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
581 #define side_type_u64_be(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
582 #define side_type_s16_be(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
583 #define side_type_s32_be(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
584 #define side_type_s64_be(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
585 #define side_type_float_binary16_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
586 #define side_type_float_binary32_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
587 #define side_type_float_binary64_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
588 #define side_type_float_binary128_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
590 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
591 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
592 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
593 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
594 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
595 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
596 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
597 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
598 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
599 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
601 #define side_type_enum(_mappings, _elem_type) \
603 .type = SIDE_TYPE_ENUM, \
606 .mappings = _mappings, \
607 .elem_type = _elem_type, \
611 #define side_field_enum(_name, _mappings, _elem_type) \
612 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
614 #define side_type_enum_bitmap(_mappings, _elem_type) \
616 .type = SIDE_TYPE_ENUM_BITMAP, \
618 .side_enum_bitmap = { \
619 .mappings = _mappings, \
620 .elem_type = _elem_type, \
624 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
625 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
627 #define side_type_struct(_struct) \
629 .type = SIDE_TYPE_STRUCT, \
631 .side_struct = _struct, \
634 #define side_field_struct(_name, _struct) \
635 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
637 #define _side_type_struct_define(_fields, _attr) \
639 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
640 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
645 #define side_define_struct(_identifier, _fields, _attr) \
646 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
648 #define side_struct_literal(_fields, _attr) \
649 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
650 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
652 #define side_type_array(_elem_type, _length, _attr) \
654 .type = SIDE_TYPE_ARRAY, \
657 .elem_type = _elem_type, \
660 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
664 #define side_field_array(_name, _elem_type, _length, _attr) \
665 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
667 #define side_type_vla(_elem_type, _attr) \
669 .type = SIDE_TYPE_VLA, \
672 .elem_type = _elem_type, \
674 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
678 #define side_field_vla(_name, _elem_type, _attr) \
679 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
681 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
683 .type = SIDE_TYPE_VLA_VISITOR, \
685 .side_vla_visitor = { \
686 .elem_type = SIDE_PARAM(_elem_type), \
687 .visitor = _visitor, \
689 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
693 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
694 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
696 #define side_elem(...) \
697 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
699 #define side_field_list(...) \
700 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
702 /* Static field arguments */
704 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
705 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
706 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
707 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
708 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
709 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
710 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
711 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
712 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
713 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
714 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
715 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
716 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
717 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
718 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
719 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
720 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
721 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
722 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
723 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
725 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
726 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
727 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
728 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
729 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
731 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
732 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
733 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
734 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
735 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
736 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
737 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
738 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
739 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
741 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
742 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
743 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
744 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
745 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
746 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
747 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
748 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
749 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
751 #define side_arg_dynamic(_dynamic_arg_type) \
753 .type = SIDE_TYPE_DYNAMIC, \
755 .dynamic = _dynamic_arg_type, \
759 /* Dynamic field arguments */
761 #define side_arg_dynamic_null(_attr) \
763 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
767 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
768 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
773 #define side_arg_dynamic_bool(_val, _attr) \
775 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
779 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
780 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
782 .side_bool = !!(_val), \
788 #define side_arg_dynamic_u8(_val, _attr) \
790 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
794 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
795 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
802 #define side_arg_dynamic_s8(_val, _attr) \
804 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
808 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
809 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
816 #define side_arg_dynamic_byte(_val, _attr) \
818 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
822 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
823 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
825 .side_byte = (_val), \
830 #define side_arg_dynamic_string(_val, _attr) \
832 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
836 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
837 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
845 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
847 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
851 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
852 .byte_order = _byte_order, \
854 .side_u16 = (_val), \
859 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
861 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
865 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
866 .byte_order = _byte_order, \
868 .side_u32 = (_val), \
873 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
875 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
879 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
880 .byte_order = _byte_order, \
882 .side_u64 = (_val), \
888 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
890 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
894 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
895 .byte_order = _byte_order, \
897 .side_s16 = (_val), \
902 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
904 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
908 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
909 .byte_order = _byte_order, \
911 .side_s32 = (_val), \
916 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
918 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
922 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
923 .byte_order = _byte_order, \
925 .side_s64 = (_val), \
930 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
932 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
936 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
937 .byte_order = _byte_order, \
939 .side_float_binary16 = (_val), \
944 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
946 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
950 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
951 .byte_order = _byte_order, \
953 .side_float_binary32 = (_val), \
958 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
960 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
964 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
965 .byte_order = _byte_order, \
967 .side_float_binary64 = (_val), \
972 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
974 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
978 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
979 .byte_order = _byte_order, \
981 .side_float_binary128 = (_val), \
988 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
989 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
990 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
991 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
992 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
993 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
994 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
995 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
996 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
997 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1000 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1001 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1002 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1003 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1004 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1005 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1006 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1007 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1008 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1009 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1012 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1013 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1014 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1015 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1016 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1017 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1018 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1019 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1020 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1021 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1023 #define side_arg_dynamic_vla(_vla) \
1025 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1027 .side_dynamic_vla = (_vla), \
1031 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1033 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1035 .side_dynamic_vla_visitor = { \
1037 .visitor = _dynamic_vla_visitor, \
1039 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1044 #define side_arg_dynamic_struct(_struct) \
1046 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1048 .side_dynamic_struct = (_struct), \
1052 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1054 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1056 .side_dynamic_struct_visitor = { \
1058 .visitor = _dynamic_struct_visitor, \
1060 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1065 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1066 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1067 const struct side_arg_dynamic_vec_vla _identifier = { \
1068 .sav = _identifier##_vec, \
1070 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1071 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1074 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1075 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1076 const struct side_arg_dynamic_event_struct _identifier = { \
1077 .fields = _identifier##_fields, \
1079 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1080 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1083 #define side_arg_define_vec(_identifier, _sav) \
1084 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1085 const struct side_arg_vec_description _identifier = { \
1086 .sav = _identifier##_vec, \
1087 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1090 #define side_arg_dynamic_field(_name, _elem) \
1092 .field_name = _name, \
1096 #define side_arg_list(...) __VA_ARGS__
1098 #define side_define_enum(_identifier, _mappings, _attr) \
1099 const struct side_enum_mappings _identifier = { \
1100 .mappings = _mappings, \
1102 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1103 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1106 #define side_enum_mapping_list(...) \
1107 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1109 #define side_enum_mapping_range(_label, _begin, _end) \
1111 .range_begin = _begin, \
1112 .range_end = _end, \
1116 #define side_enum_mapping_value(_label, _value) \
1118 .range_begin = _value, \
1119 .range_end = _value, \
1123 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1124 const struct side_enum_bitmap_mappings _identifier = { \
1125 .mappings = _mappings, \
1127 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1128 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1131 #define side_enum_bitmap_mapping_list(...) \
1132 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1134 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1136 .range_begin = _begin, \
1137 .range_end = _end, \
1141 #define side_enum_bitmap_mapping_value(_label, _value) \
1143 .range_begin = _value, \
1144 .range_end = _value, \
1148 #define side_event_cond(_identifier) \
1149 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1152 #define side_event_call(_identifier, _sav) \
1154 const struct side_arg_vec side_sav[] = { _sav }; \
1155 const struct side_arg_vec_description sav_desc = { \
1157 .len = SIDE_ARRAY_SIZE(side_sav), \
1159 side_call(&(_identifier), &sav_desc); \
1162 #define side_event(_identifier, _sav) \
1163 side_event_cond(_identifier) \
1164 side_event_call(_identifier, SIDE_PARAM(_sav))
1166 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1168 const struct side_arg_vec side_sav[] = { _sav }; \
1169 const struct side_arg_vec_description sav_desc = { \
1171 .len = SIDE_ARRAY_SIZE(side_sav), \
1173 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1174 const struct side_arg_dynamic_event_struct var_struct = { \
1175 .fields = side_fields, \
1177 .len = SIDE_ARRAY_SIZE(side_fields), \
1178 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1180 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1183 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1184 side_event_cond(_identifier) \
1185 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1187 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1188 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1189 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1192 .enabled = &(side_event_enable__##_identifier), \
1193 .loglevel = _loglevel, \
1194 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1195 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1196 .nr_callbacks = 0, \
1197 .flags = (_flags), \
1198 .provider_name = _provider, \
1199 .event_name = _event, \
1200 .fields = _fields, \
1202 .callbacks = &side_empty_callback, \
1204 static const struct side_event_description *side_event_ptr__##_identifier \
1205 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1207 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1208 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1209 SIDE_PARAM(_attr), 0)
1211 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1212 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1213 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1215 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1216 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1217 SIDE_PARAM(_attr), 0)
1219 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1220 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1221 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1223 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1224 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1225 SIDE_PARAM(_attr), 0)
1227 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1228 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1229 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1231 #define side_declare_event(_identifier) \
1232 extern uintptr_t side_event_enable_##_identifier; \
1233 extern struct side_event_description _identifier
1235 extern const struct side_callback side_empty_callback
;
1237 void side_call(const struct side_event_description
*desc
,
1238 const struct side_arg_vec_description
*sav_desc
);
1239 void side_call_variadic(const struct side_event_description
*desc
,
1240 const struct side_arg_vec_description
*sav_desc
,
1241 const struct side_arg_dynamic_event_struct
*var_struct
);
1243 int side_tracer_callback_register(struct side_event_description
*desc
,
1244 void (*call
)(const struct side_event_description
*desc
,
1245 const struct side_arg_vec_description
*sav_desc
,
1248 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1249 void (*call_variadic
)(const struct side_event_description
*desc
,
1250 const struct side_arg_vec_description
*sav_desc
,
1251 const struct side_arg_dynamic_event_struct
*var_struct
,
1254 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1255 void (*call
)(const struct side_event_description
*desc
,
1256 const struct side_arg_vec_description
*sav_desc
,
1259 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1260 void (*call_variadic
)(const struct side_event_description
*desc
,
1261 const struct side_arg_vec_description
*sav_desc
,
1262 const struct side_arg_dynamic_event_struct
*var_struct
,
1266 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
, uint32_t nr_events
);
1267 void side_events_unregister(struct side_events_register_handle
*handle
);
1269 enum side_tracer_notification
{
1270 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1271 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1274 /* Callback is invoked with side library internal lock held. */
1275 struct side_tracer_handle
*side_tracer_event_notification_register(
1276 void (*cb
)(enum side_tracer_notification notif
,
1277 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1279 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1281 void side_init(void);
1282 void side_exit(void);
1285 * These weak symbols, the constructor, and destructor take care of
1286 * registering only _one_ instance of the side instrumentation per
1287 * shared-ojbect (or for the whole main program).
1289 extern struct side_event_description
* __start_side_event_description_ptr
[]
1290 __attribute__((weak
, visibility("hidden")));
1291 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1292 __attribute__((weak
, visibility("hidden")));
1293 int side_event_description_ptr_registered
1294 __attribute__((weak
, visibility("hidden")));
1295 struct side_events_register_handle
*side_events_handle
1296 __attribute__((weak
, visibility("hidden")));
1299 side_event_description_ptr_init(void)
1300 __attribute__((no_instrument_function
))
1301 __attribute__((constructor
));
1303 side_event_description_ptr_init(void)
1305 if (side_event_description_ptr_registered
++)
1307 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1308 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1312 side_event_description_ptr_exit(void)
1313 __attribute__((no_instrument_function
))
1314 __attribute__((destructor
));
1316 side_event_description_ptr_exit(void)
1318 if (--side_event_description_ptr_registered
)
1320 side_events_unregister(side_events_handle
);
1321 side_events_handle
= NULL
;
1324 #endif /* _SIDE_TRACE_H */