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
;
50 SIDE_TYPE_FLOAT_BINARY16
,
51 SIDE_TYPE_FLOAT_BINARY32
,
52 SIDE_TYPE_FLOAT_BINARY64
,
53 SIDE_TYPE_FLOAT_BINARY128
,
60 SIDE_TYPE_VLA_VISITOR
,
71 SIDE_TYPE_ARRAY_POINTER32
,
72 SIDE_TYPE_ARRAY_POINTER64
,
83 SIDE_TYPE_VLA_POINTER32
,
84 SIDE_TYPE_VLA_POINTER64
,
86 /* Enumeration types */
88 SIDE_TYPE_ENUM_BITMAP
,
94 enum side_dynamic_type
{
96 SIDE_DYNAMIC_TYPE_NULL
,
97 SIDE_DYNAMIC_TYPE_BOOL
,
99 SIDE_DYNAMIC_TYPE_U16
,
100 SIDE_DYNAMIC_TYPE_U32
,
101 SIDE_DYNAMIC_TYPE_U64
,
102 SIDE_DYNAMIC_TYPE_S8
,
103 SIDE_DYNAMIC_TYPE_S16
,
104 SIDE_DYNAMIC_TYPE_S32
,
105 SIDE_DYNAMIC_TYPE_S64
,
106 SIDE_DYNAMIC_TYPE_BYTE
,
107 SIDE_DYNAMIC_TYPE_POINTER32
,
108 SIDE_DYNAMIC_TYPE_POINTER64
,
109 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
,
110 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
,
111 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
,
112 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
,
113 SIDE_DYNAMIC_TYPE_STRING
,
116 SIDE_DYNAMIC_TYPE_STRUCT
,
117 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
,
118 SIDE_DYNAMIC_TYPE_VLA
,
119 SIDE_DYNAMIC_TYPE_VLA_VISITOR
,
122 enum side_attr_type
{
133 SIDE_ATTR_TYPE_POINTER32
,
134 SIDE_ATTR_TYPE_POINTER64
,
135 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
136 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
137 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
138 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
139 SIDE_ATTR_TYPE_STRING
,
143 SIDE_LOGLEVEL_EMERG
= 0,
144 SIDE_LOGLEVEL_ALERT
= 1,
145 SIDE_LOGLEVEL_CRIT
= 2,
146 SIDE_LOGLEVEL_ERR
= 3,
147 SIDE_LOGLEVEL_WARNING
= 4,
148 SIDE_LOGLEVEL_NOTICE
= 5,
149 SIDE_LOGLEVEL_INFO
= 6,
150 SIDE_LOGLEVEL_DEBUG
= 7,
153 enum side_visitor_status
{
154 SIDE_VISITOR_STATUS_OK
= 0,
155 SIDE_VISITOR_STATUS_ERROR
= -1,
160 SIDE_ERROR_INVAL
= 1,
161 SIDE_ERROR_EXIST
= 2,
162 SIDE_ERROR_NOMEM
= 3,
163 SIDE_ERROR_NOENT
= 4,
164 SIDE_ERROR_EXITING
= 5,
167 enum side_type_byte_order
{
168 SIDE_TYPE_BYTE_ORDER_LE
= 0,
169 SIDE_TYPE_BYTE_ORDER_BE
= 1,
172 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
173 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
175 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
178 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
179 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
181 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
184 typedef enum side_visitor_status (*side_visitor
)(
185 const struct side_tracer_visitor_ctx
*tracer_ctx
,
187 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
188 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
190 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
191 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
194 struct side_attr_value
{
195 uint32_t type
; /* enum side_attr_type */
207 _Float16 side_float_binary16
;
210 _Float32 side_float_binary32
;
213 _Float64 side_float_binary64
;
216 _Float128 side_float_binary128
;
218 uint64_t string
; /* const char * */
222 /* User attributes. */
225 const struct side_attr_value value
;
228 struct side_enum_mapping
{
234 struct side_enum_mappings
{
235 const struct side_enum_mapping
*mappings
;
236 const struct side_attr
*attr
;
237 uint32_t nr_mappings
;
241 struct side_enum_bitmap_mapping
{
242 uint64_t range_begin
;
247 struct side_enum_bitmap_mappings
{
248 const struct side_enum_bitmap_mapping
*mappings
;
249 const struct side_attr
*attr
;
250 uint32_t nr_mappings
;
254 struct side_type_struct
{
257 const struct side_event_field
*fields
;
258 const struct side_attr
*attr
;
261 struct side_type_description
{
262 uint32_t type
; /* enum side_type */
266 const struct side_attr
*attr
;
268 uint32_t byte_order
; /* enum side_type_byte_order */
273 const struct side_type_description
*elem_type
;
274 const struct side_attr
*attr
;
279 const struct side_type_description
*elem_type
;
280 const struct side_attr
*attr
;
284 const struct side_type_description
*elem_type
;
285 side_visitor visitor
;
286 const struct side_attr
*attr
;
289 const struct side_type_struct
*side_struct
;
291 /* Enumeration types */
293 const struct side_enum_mappings
*mappings
;
294 const struct side_type_description
*elem_type
;
297 const struct side_enum_bitmap_mappings
*mappings
;
298 const struct side_type_description
*elem_type
;
303 struct side_event_field
{
304 const char *field_name
;
305 struct side_type_description side_type
;
308 enum side_event_flags
{
309 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
312 struct side_callback
{
314 void (*call
)(const struct side_event_description
*desc
,
315 const struct side_arg_vec_description
*sav_desc
,
317 void (*call_variadic
)(const struct side_event_description
*desc
,
318 const struct side_arg_vec_description
*sav_desc
,
319 const struct side_arg_dynamic_event_struct
*var_struct
,
325 struct side_event_description
{
327 const char *provider_name
;
328 const char *event_name
;
329 const struct side_event_field
*fields
;
330 const struct side_attr
*attr
;
331 const struct side_callback
*callbacks
;
334 uint32_t loglevel
; /* enum side_loglevel */
337 uint32_t nr_callbacks
;
340 struct side_arg_dynamic_vec
{
341 uint32_t dynamic_type
; /* enum side_dynamic_type */
345 const struct side_attr
*attr
;
347 uint32_t byte_order
; /* enum side_type_byte_order */
360 _Float16 side_float_binary16
;
363 _Float32 side_float_binary32
;
366 _Float64 side_float_binary64
;
369 _Float128 side_float_binary128
;
371 uint64_t string
; /* const char * */
376 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
379 side_dynamic_struct_visitor visitor
;
380 const struct side_attr
*attr
;
382 } side_dynamic_struct_visitor
;
383 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
386 side_dynamic_vla_visitor visitor
;
387 const struct side_attr
*attr
;
389 } side_dynamic_vla_visitor
;
393 struct side_arg_dynamic_vec_vla
{
394 const struct side_arg_dynamic_vec
*sav
;
395 const struct side_attr
*attr
;
400 struct side_arg_dynamic_event_field
{
401 const char *field_name
;
402 const struct side_arg_dynamic_vec elem
;
405 struct side_arg_dynamic_event_struct
{
406 const struct side_arg_dynamic_event_field
*fields
;
407 const struct side_attr
*attr
;
412 struct side_arg_vec
{
427 _Float16 side_float_binary16
;
430 _Float32 side_float_binary32
;
433 _Float64 side_float_binary64
;
436 _Float128 side_float_binary128
;
438 uint64_t string
; /* const char * */
441 const struct side_arg_vec_description
*side_struct
;
442 const struct side_arg_vec_description
*side_array
;
443 const struct side_arg_vec_description
*side_vla
;
444 void *side_vla_app_visitor_ctx
;
445 void *side_array_fixint
;
452 struct side_arg_dynamic_vec dynamic
;
456 struct side_arg_vec_description
{
457 const struct side_arg_vec
*sav
;
461 /* The visitor pattern is a double-dispatch visitor. */
462 struct side_tracer_visitor_ctx
{
463 enum side_visitor_status (*write_elem
)(
464 const struct side_tracer_visitor_ctx
*tracer_ctx
,
465 const struct side_arg_vec
*elem
);
466 void *priv
; /* Private tracer context. */
469 struct side_tracer_dynamic_struct_visitor_ctx
{
470 enum side_visitor_status (*write_field
)(
471 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
472 const struct side_arg_dynamic_event_field
*dynamic_field
);
473 void *priv
; /* Private tracer context. */
476 struct side_tracer_dynamic_vla_visitor_ctx
{
477 enum side_visitor_status (*write_elem
)(
478 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
479 const struct side_arg_dynamic_vec
*elem
);
480 void *priv
; /* Private tracer context. */
483 /* Event and type attributes */
485 #if SIDE_BITS_PER_LONG == 64
486 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
487 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
488 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
489 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER64
490 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
491 # define SIDE_PTR_HOST .side_u64
493 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
494 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
495 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
496 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER32
497 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
498 # define SIDE_PTR_HOST .side_u32
501 #define side_attr(_key, _value) \
504 .value = SIDE_PARAM(_value), \
507 #define side_attr_list(...) \
508 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
510 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
511 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
512 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
513 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
514 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
515 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
516 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
517 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
518 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
519 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
520 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { SIDE_PTR_HOST = (uintptr_t) (_val) } }
521 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
522 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
523 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
524 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
525 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
527 /* Static field definition */
529 #define _side_type_basic(_type, _byte_order, _attr) \
535 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
536 .byte_order = _byte_order, \
541 #define _side_field(_name, _type) \
543 .field_name = _name, \
544 .side_type = _type, \
548 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
549 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
550 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
551 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
552 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
553 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
554 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
555 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
556 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
557 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
558 #define side_type_pointer(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
559 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
560 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
561 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
562 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
563 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
564 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
566 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
567 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
568 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
569 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
570 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
571 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
572 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
573 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
574 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
575 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
576 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
577 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
578 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
579 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
580 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
581 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
582 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
585 #define side_type_u16_le(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
586 #define side_type_u32_le(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
587 #define side_type_u64_le(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
588 #define side_type_s16_le(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
589 #define side_type_s32_le(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
590 #define side_type_s64_le(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
591 #define side_type_pointer_le(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
592 #define side_type_float_binary16_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
593 #define side_type_float_binary32_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
594 #define side_type_float_binary64_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
595 #define side_type_float_binary128_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
597 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
598 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
599 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
600 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
601 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
602 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
603 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
604 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
605 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
606 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
607 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
610 #define side_type_u16_be(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
611 #define side_type_u32_be(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
612 #define side_type_u64_be(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
613 #define side_type_s16_be(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
614 #define side_type_s32_be(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
615 #define side_type_s64_be(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
616 #define side_type_pointer_be(_attr) _side_type_basic(SIDE_TYPE_POINTER_HOST, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
617 #define side_type_float_binary16_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
618 #define side_type_float_binary32_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
619 #define side_type_float_binary64_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
620 #define side_type_float_binary128_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
622 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
623 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
624 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
625 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
626 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
627 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
628 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
629 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
630 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
631 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
632 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
634 #define side_type_enum(_mappings, _elem_type) \
636 .type = SIDE_TYPE_ENUM, \
639 .mappings = _mappings, \
640 .elem_type = _elem_type, \
644 #define side_field_enum(_name, _mappings, _elem_type) \
645 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
647 #define side_type_enum_bitmap(_mappings, _elem_type) \
649 .type = SIDE_TYPE_ENUM_BITMAP, \
651 .side_enum_bitmap = { \
652 .mappings = _mappings, \
653 .elem_type = _elem_type, \
657 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
658 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
660 #define side_type_struct(_struct) \
662 .type = SIDE_TYPE_STRUCT, \
664 .side_struct = _struct, \
667 #define side_field_struct(_name, _struct) \
668 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
670 #define _side_type_struct_define(_fields, _attr) \
672 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
673 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
678 #define side_define_struct(_identifier, _fields, _attr) \
679 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
681 #define side_struct_literal(_fields, _attr) \
682 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
683 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
685 #define side_type_array(_elem_type, _length, _attr) \
687 .type = SIDE_TYPE_ARRAY, \
690 .elem_type = _elem_type, \
693 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
697 #define side_field_array(_name, _elem_type, _length, _attr) \
698 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
700 #define side_type_vla(_elem_type, _attr) \
702 .type = SIDE_TYPE_VLA, \
705 .elem_type = _elem_type, \
707 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
711 #define side_field_vla(_name, _elem_type, _attr) \
712 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
714 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
716 .type = SIDE_TYPE_VLA_VISITOR, \
718 .side_vla_visitor = { \
719 .elem_type = SIDE_PARAM(_elem_type), \
720 .visitor = _visitor, \
722 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
726 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
727 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
729 #define side_elem(...) \
730 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
732 #define side_field_list(...) \
733 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
735 /* Static field arguments */
737 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
738 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
739 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
740 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
741 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
742 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
743 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
744 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
745 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
746 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
747 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { SIDE_PTR_HOST = (uintptr_t) (_val) } }
748 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
749 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
750 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
751 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
752 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
753 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
754 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
755 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
756 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
757 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
759 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
760 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
761 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
762 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
763 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
765 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
766 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
767 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
768 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
769 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
770 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
771 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
772 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
773 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
774 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_array_fixint = (_ptr) } }
776 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
777 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
778 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
779 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
780 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
781 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
782 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
783 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
784 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
785 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
787 #define side_arg_dynamic(_dynamic_arg_type) \
789 .type = SIDE_TYPE_DYNAMIC, \
791 .dynamic = _dynamic_arg_type, \
795 /* Dynamic field arguments */
797 #define side_arg_dynamic_null(_attr) \
799 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
803 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
804 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
809 #define side_arg_dynamic_bool(_val, _attr) \
811 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
815 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
816 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
818 .side_bool = !!(_val), \
824 #define side_arg_dynamic_u8(_val, _attr) \
826 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
830 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
831 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
838 #define side_arg_dynamic_s8(_val, _attr) \
840 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
844 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
845 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
852 #define side_arg_dynamic_byte(_val, _attr) \
854 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
858 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
859 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
861 .side_byte = (_val), \
866 #define side_arg_dynamic_string(_val, _attr) \
868 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
872 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
873 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
875 .string = (uintptr_t) (_val), \
881 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
883 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
887 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
888 .byte_order = _byte_order, \
890 .side_u16 = (_val), \
895 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
897 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
901 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
902 .byte_order = _byte_order, \
904 .side_u32 = (_val), \
909 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
911 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
915 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
916 .byte_order = _byte_order, \
918 .side_u64 = (_val), \
924 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
926 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
930 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
931 .byte_order = _byte_order, \
933 .side_s16 = (_val), \
938 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
940 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
944 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
945 .byte_order = _byte_order, \
947 .side_s32 = (_val), \
952 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
954 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
958 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
959 .byte_order = _byte_order, \
961 .side_s64 = (_val), \
966 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
968 .dynamic_type = SIDE_DYNAMIC_TYPE_POINTER_HOST, \
972 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
973 .byte_order = _byte_order, \
975 SIDE_PTR_HOST = (uintptr_t) (_val), \
980 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
982 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
986 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
987 .byte_order = _byte_order, \
989 .side_float_binary16 = (_val), \
994 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
996 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
1000 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1001 .byte_order = _byte_order, \
1003 .side_float_binary32 = (_val), \
1008 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1010 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
1014 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1015 .byte_order = _byte_order, \
1017 .side_float_binary64 = (_val), \
1022 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1024 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
1028 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1029 .byte_order = _byte_order, \
1031 .side_float_binary128 = (_val), \
1038 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1039 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1040 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1041 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1042 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1043 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1044 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1045 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1046 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1047 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1048 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1051 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1052 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1053 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1054 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1055 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1056 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1057 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1058 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1059 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1060 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1061 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1064 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1065 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1066 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1067 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1068 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1069 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1070 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1071 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1072 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1073 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1074 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1076 #define side_arg_dynamic_vla(_vla) \
1078 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1080 .side_dynamic_vla = (_vla), \
1084 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1086 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1088 .side_dynamic_vla_visitor = { \
1090 .visitor = _dynamic_vla_visitor, \
1092 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1097 #define side_arg_dynamic_struct(_struct) \
1099 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1101 .side_dynamic_struct = (_struct), \
1105 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1107 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1109 .side_dynamic_struct_visitor = { \
1111 .visitor = _dynamic_struct_visitor, \
1113 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1118 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1119 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1120 const struct side_arg_dynamic_vec_vla _identifier = { \
1121 .sav = _identifier##_vec, \
1123 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1124 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1127 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1128 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1129 const struct side_arg_dynamic_event_struct _identifier = { \
1130 .fields = _identifier##_fields, \
1132 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1133 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1136 #define side_arg_define_vec(_identifier, _sav) \
1137 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1138 const struct side_arg_vec_description _identifier = { \
1139 .sav = _identifier##_vec, \
1140 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1143 #define side_arg_dynamic_field(_name, _elem) \
1145 .field_name = _name, \
1149 #define side_arg_list(...) __VA_ARGS__
1151 #define side_define_enum(_identifier, _mappings, _attr) \
1152 const struct side_enum_mappings _identifier = { \
1153 .mappings = _mappings, \
1155 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1156 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1159 #define side_enum_mapping_list(...) \
1160 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1162 #define side_enum_mapping_range(_label, _begin, _end) \
1164 .range_begin = _begin, \
1165 .range_end = _end, \
1169 #define side_enum_mapping_value(_label, _value) \
1171 .range_begin = _value, \
1172 .range_end = _value, \
1176 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1177 const struct side_enum_bitmap_mappings _identifier = { \
1178 .mappings = _mappings, \
1180 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1181 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1184 #define side_enum_bitmap_mapping_list(...) \
1185 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1187 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1189 .range_begin = _begin, \
1190 .range_end = _end, \
1194 #define side_enum_bitmap_mapping_value(_label, _value) \
1196 .range_begin = _value, \
1197 .range_end = _value, \
1201 #define side_event_cond(_identifier) \
1202 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1205 #define side_event_call(_identifier, _sav) \
1207 const struct side_arg_vec side_sav[] = { _sav }; \
1208 const struct side_arg_vec_description sav_desc = { \
1210 .len = SIDE_ARRAY_SIZE(side_sav), \
1212 side_call(&(_identifier), &sav_desc); \
1215 #define side_event(_identifier, _sav) \
1216 side_event_cond(_identifier) \
1217 side_event_call(_identifier, SIDE_PARAM(_sav))
1219 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1221 const struct side_arg_vec side_sav[] = { _sav }; \
1222 const struct side_arg_vec_description sav_desc = { \
1224 .len = SIDE_ARRAY_SIZE(side_sav), \
1226 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1227 const struct side_arg_dynamic_event_struct var_struct = { \
1228 .fields = side_fields, \
1230 .len = SIDE_ARRAY_SIZE(side_fields), \
1231 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1233 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1236 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1237 side_event_cond(_identifier) \
1238 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1240 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1241 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1242 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1245 .enabled = &(side_event_enable__##_identifier), \
1246 .loglevel = _loglevel, \
1247 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1248 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1249 .nr_callbacks = 0, \
1250 .flags = (_flags), \
1251 .provider_name = _provider, \
1252 .event_name = _event, \
1253 .fields = _fields, \
1255 .callbacks = &side_empty_callback, \
1257 static const struct side_event_description *side_event_ptr__##_identifier \
1258 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1260 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1261 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1262 SIDE_PARAM(_attr), 0)
1264 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1265 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1266 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1268 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1269 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1270 SIDE_PARAM(_attr), 0)
1272 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1273 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1274 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1276 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1277 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1278 SIDE_PARAM(_attr), 0)
1280 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1281 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1282 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1284 #define side_declare_event(_identifier) \
1285 extern uintptr_t side_event_enable_##_identifier; \
1286 extern struct side_event_description _identifier
1288 extern const struct side_callback side_empty_callback
;
1290 void side_call(const struct side_event_description
*desc
,
1291 const struct side_arg_vec_description
*sav_desc
);
1292 void side_call_variadic(const struct side_event_description
*desc
,
1293 const struct side_arg_vec_description
*sav_desc
,
1294 const struct side_arg_dynamic_event_struct
*var_struct
);
1296 int side_tracer_callback_register(struct side_event_description
*desc
,
1297 void (*call
)(const struct side_event_description
*desc
,
1298 const struct side_arg_vec_description
*sav_desc
,
1301 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1302 void (*call_variadic
)(const struct side_event_description
*desc
,
1303 const struct side_arg_vec_description
*sav_desc
,
1304 const struct side_arg_dynamic_event_struct
*var_struct
,
1307 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1308 void (*call
)(const struct side_event_description
*desc
,
1309 const struct side_arg_vec_description
*sav_desc
,
1312 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1313 void (*call_variadic
)(const struct side_event_description
*desc
,
1314 const struct side_arg_vec_description
*sav_desc
,
1315 const struct side_arg_dynamic_event_struct
*var_struct
,
1319 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
, uint32_t nr_events
);
1320 void side_events_unregister(struct side_events_register_handle
*handle
);
1322 enum side_tracer_notification
{
1323 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1324 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1327 /* Callback is invoked with side library internal lock held. */
1328 struct side_tracer_handle
*side_tracer_event_notification_register(
1329 void (*cb
)(enum side_tracer_notification notif
,
1330 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1332 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1334 void side_init(void);
1335 void side_exit(void);
1338 * These weak symbols, the constructor, and destructor take care of
1339 * registering only _one_ instance of the side instrumentation per
1340 * shared-ojbect (or for the whole main program).
1342 extern struct side_event_description
* __start_side_event_description_ptr
[]
1343 __attribute__((weak
, visibility("hidden")));
1344 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1345 __attribute__((weak
, visibility("hidden")));
1346 int side_event_description_ptr_registered
1347 __attribute__((weak
, visibility("hidden")));
1348 struct side_events_register_handle
*side_events_handle
1349 __attribute__((weak
, visibility("hidden")));
1352 side_event_description_ptr_init(void)
1353 __attribute__((no_instrument_function
))
1354 __attribute__((constructor
));
1356 side_event_description_ptr_init(void)
1358 if (side_event_description_ptr_registered
++)
1360 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1361 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1365 side_event_description_ptr_exit(void)
1366 __attribute__((no_instrument_function
))
1367 __attribute__((destructor
));
1369 side_event_description_ptr_exit(void)
1371 if (--side_event_description_ptr_registered
)
1373 side_events_unregister(side_events_handle
);
1374 side_events_handle
= NULL
;
1377 #endif /* _SIDE_TRACE_H */