1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 #include <side/macros.h>
15 #include <side/endian.h>
17 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
19 //TODO: as those structures will be ABI, we need to either consider them
20 //fixed forever, or think of a scheme that would allow their binary
21 //representation to be extended if need be.
24 struct side_arg_vec_description
;
25 struct side_arg_dynamic_vec
;
26 struct side_arg_dynamic_vec_vla
;
27 struct side_type_description
;
28 struct side_event_field
;
29 struct side_event_field_sg
;
30 struct side_tracer_visitor_ctx
;
31 struct side_tracer_dynamic_struct_visitor_ctx
;
32 struct side_tracer_dynamic_vla_visitor_ctx
;
33 struct side_event_description
;
34 struct side_arg_dynamic_event_struct
;
35 struct side_events_register_handle
;
51 SIDE_TYPE_FLOAT_BINARY16
,
52 SIDE_TYPE_FLOAT_BINARY32
,
53 SIDE_TYPE_FLOAT_BINARY64
,
54 SIDE_TYPE_FLOAT_BINARY128
,
62 SIDE_TYPE_VLA_VISITOR
,
73 SIDE_TYPE_ARRAY_POINTER32
,
74 SIDE_TYPE_ARRAY_POINTER64
,
85 SIDE_TYPE_VLA_POINTER32
,
86 SIDE_TYPE_VLA_POINTER64
,
88 /* Enumeration types */
90 SIDE_TYPE_ENUM_BITMAP
,
96 enum side_dynamic_type
{
98 SIDE_DYNAMIC_TYPE_NULL
,
99 SIDE_DYNAMIC_TYPE_BOOL
,
100 SIDE_DYNAMIC_TYPE_U8
,
101 SIDE_DYNAMIC_TYPE_U16
,
102 SIDE_DYNAMIC_TYPE_U32
,
103 SIDE_DYNAMIC_TYPE_U64
,
104 SIDE_DYNAMIC_TYPE_S8
,
105 SIDE_DYNAMIC_TYPE_S16
,
106 SIDE_DYNAMIC_TYPE_S32
,
107 SIDE_DYNAMIC_TYPE_S64
,
108 SIDE_DYNAMIC_TYPE_BYTE
,
109 SIDE_DYNAMIC_TYPE_POINTER32
,
110 SIDE_DYNAMIC_TYPE_POINTER64
,
111 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
,
112 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
,
113 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
,
114 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
,
115 SIDE_DYNAMIC_TYPE_STRING
,
118 SIDE_DYNAMIC_TYPE_STRUCT
,
119 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
,
120 SIDE_DYNAMIC_TYPE_VLA
,
121 SIDE_DYNAMIC_TYPE_VLA_VISITOR
,
124 enum side_attr_type
{
135 SIDE_ATTR_TYPE_POINTER32
,
136 SIDE_ATTR_TYPE_POINTER64
,
137 SIDE_ATTR_TYPE_FLOAT_BINARY16
,
138 SIDE_ATTR_TYPE_FLOAT_BINARY32
,
139 SIDE_ATTR_TYPE_FLOAT_BINARY64
,
140 SIDE_ATTR_TYPE_FLOAT_BINARY128
,
141 SIDE_ATTR_TYPE_STRING
,
145 SIDE_TYPE_SG_UNSIGNED_INT
,
146 SIDE_TYPE_SG_SIGNED_INT
,
150 SIDE_LOGLEVEL_EMERG
= 0,
151 SIDE_LOGLEVEL_ALERT
= 1,
152 SIDE_LOGLEVEL_CRIT
= 2,
153 SIDE_LOGLEVEL_ERR
= 3,
154 SIDE_LOGLEVEL_WARNING
= 4,
155 SIDE_LOGLEVEL_NOTICE
= 5,
156 SIDE_LOGLEVEL_INFO
= 6,
157 SIDE_LOGLEVEL_DEBUG
= 7,
160 enum side_visitor_status
{
161 SIDE_VISITOR_STATUS_OK
= 0,
162 SIDE_VISITOR_STATUS_ERROR
= -1,
167 SIDE_ERROR_INVAL
= 1,
168 SIDE_ERROR_EXIST
= 2,
169 SIDE_ERROR_NOMEM
= 3,
170 SIDE_ERROR_NOENT
= 4,
171 SIDE_ERROR_EXITING
= 5,
174 enum side_type_byte_order
{
175 SIDE_TYPE_BYTE_ORDER_LE
= 0,
176 SIDE_TYPE_BYTE_ORDER_BE
= 1,
179 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
180 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
182 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
185 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
186 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
188 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
191 typedef enum side_visitor_status (*side_visitor
)(
192 const struct side_tracer_visitor_ctx
*tracer_ctx
,
194 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
195 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
197 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
198 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
201 union side_integer_value
{
212 union side_float_value
{
214 _Float16 side_float_binary16
;
217 _Float32 side_float_binary32
;
220 _Float64 side_float_binary64
;
223 _Float128 side_float_binary128
;
227 struct side_attr_value
{
228 uint32_t type
; /* enum side_attr_type */
230 union side_integer_value integer_value
;
231 union side_float_value float_value
;
233 uint64_t string
; /* const char * */
237 /* User attributes. */
240 const struct side_attr_value value
;
243 struct side_type_integer
{
244 const struct side_attr
*attr
;
246 uint16_t integer_size_bits
; /* bits */
247 uint16_t len_bits
; /* bits */
248 uint8_t signedness
; /* true/false */
249 uint8_t byte_order
; /* enum side_type_byte_order */
252 struct side_type_float
{
253 const struct side_attr
*attr
;
255 uint32_t byte_order
; /* enum side_type_byte_order */
256 uint16_t float_size_bits
; /* bits */
259 struct side_enum_mapping
{
265 struct side_enum_mappings
{
266 const struct side_enum_mapping
*mappings
;
267 const struct side_attr
*attr
;
268 uint32_t nr_mappings
;
272 struct side_enum_bitmap_mapping
{
273 uint64_t range_begin
;
278 struct side_enum_bitmap_mappings
{
279 const struct side_enum_bitmap_mapping
*mappings
;
280 const struct side_attr
*attr
;
281 uint32_t nr_mappings
;
285 struct side_type_struct
{
288 const struct side_event_field
*fields
;
289 const struct side_attr
*attr
;
292 struct side_type_sg_description
{
293 uint64_t offset
; /* bytes */
294 uint32_t type
; /* enum side_type_sg */
297 struct side_type_integer type
;
298 uint16_t offset_bits
; /* bits */
303 struct side_struct_field_sg
{
304 const char *field_name
;
305 struct side_type_sg_description side_type
;
308 /* Structure fields scatter-gather. */
309 struct side_type_struct_sg
{
312 const struct side_struct_field_sg
*fields_sg
;
313 const struct side_attr
*attr
;
316 struct side_type_description
{
317 uint32_t type
; /* enum side_type */
321 const struct side_attr
*attr
;
325 struct side_type_integer side_integer
;
326 struct side_type_float side_float
;
330 const struct side_type_description
*elem_type
;
331 const struct side_attr
*attr
;
336 const struct side_type_description
*elem_type
;
337 const struct side_attr
*attr
;
341 const struct side_type_description
*elem_type
;
342 side_visitor visitor
;
343 const struct side_attr
*attr
;
346 const struct side_type_struct
*side_struct
;
347 const struct side_type_struct_sg
*side_struct_sg
;
349 /* Enumeration types */
351 const struct side_enum_mappings
*mappings
;
352 const struct side_type_description
*elem_type
;
355 const struct side_enum_bitmap_mappings
*mappings
;
356 const struct side_type_description
*elem_type
;
361 struct side_event_field
{
362 const char *field_name
;
363 struct side_type_description side_type
;
366 enum side_event_flags
{
367 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
370 struct side_callback
{
372 void (*call
)(const struct side_event_description
*desc
,
373 const struct side_arg_vec_description
*sav_desc
,
375 void (*call_variadic
)(const struct side_event_description
*desc
,
376 const struct side_arg_vec_description
*sav_desc
,
377 const struct side_arg_dynamic_event_struct
*var_struct
,
383 struct side_event_description
{
385 const char *provider_name
;
386 const char *event_name
;
387 const struct side_event_field
*fields
;
388 const struct side_attr
*attr
;
389 const struct side_callback
*callbacks
;
392 uint32_t loglevel
; /* enum side_loglevel */
395 uint32_t nr_callbacks
;
398 struct side_arg_dynamic_vec
{
399 uint32_t dynamic_type
; /* enum side_dynamic_type */
403 const struct side_attr
*attr
;
408 uint64_t string
; /* const char * */
414 struct side_type_integer type
;
415 union side_integer_value value
;
419 struct side_type_float type
;
420 union side_float_value value
;
424 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
427 side_dynamic_struct_visitor visitor
;
428 const struct side_attr
*attr
;
430 } side_dynamic_struct_visitor
;
431 const struct side_arg_dynamic_vec_vla
*side_dynamic_vla
;
434 side_dynamic_vla_visitor visitor
;
435 const struct side_attr
*attr
;
437 } side_dynamic_vla_visitor
;
441 struct side_arg_dynamic_vec_vla
{
442 const struct side_arg_dynamic_vec
*sav
;
443 const struct side_attr
*attr
;
448 struct side_arg_dynamic_event_field
{
449 const char *field_name
;
450 const struct side_arg_dynamic_vec elem
;
453 struct side_arg_dynamic_event_struct
{
454 const struct side_arg_dynamic_event_field
*fields
;
455 const struct side_attr
*attr
;
460 struct side_arg_vec
{
464 union side_integer_value integer_value
;
467 union side_float_value float_value
;
470 uint64_t string
; /* const char * */
473 const struct side_arg_vec_description
*side_struct
;
474 const struct side_arg_vec_description
*side_array
;
475 const struct side_arg_vec_description
*side_vla
;
476 void *side_vla_app_visitor_ctx
;
477 void *side_array_fixint
;
482 void *side_struct_sg_ptr
;
485 struct side_arg_dynamic_vec dynamic
;
489 struct side_arg_vec_description
{
490 const struct side_arg_vec
*sav
;
494 /* The visitor pattern is a double-dispatch visitor. */
495 struct side_tracer_visitor_ctx
{
496 enum side_visitor_status (*write_elem
)(
497 const struct side_tracer_visitor_ctx
*tracer_ctx
,
498 const struct side_arg_vec
*elem
);
499 void *priv
; /* Private tracer context. */
502 struct side_tracer_dynamic_struct_visitor_ctx
{
503 enum side_visitor_status (*write_field
)(
504 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
505 const struct side_arg_dynamic_event_field
*dynamic_field
);
506 void *priv
; /* Private tracer context. */
509 struct side_tracer_dynamic_vla_visitor_ctx
{
510 enum side_visitor_status (*write_elem
)(
511 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
512 const struct side_arg_dynamic_vec
*elem
);
513 void *priv
; /* Private tracer context. */
516 /* Event and type attributes */
518 #if SIDE_BITS_PER_LONG == 64
519 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
520 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
521 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
522 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER64
523 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
524 # define SIDE_PTR_HOST .side_u64
526 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
527 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
528 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
529 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER32
530 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
531 # define SIDE_PTR_HOST .side_u32
534 #define side_attr(_key, _value) \
537 .value = SIDE_PARAM(_value), \
540 #define side_attr_list(...) \
541 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
543 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
544 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
545 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
546 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
547 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
548 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
549 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
550 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
551 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
552 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
553 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
554 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
555 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
556 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
557 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
558 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
560 /* Static field definition */
562 #define _side_type_basic(_type, _attr) \
568 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
573 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
579 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
580 .integer_size_bits = _integer_size_bits, \
581 .len_bits = _len_bits, \
582 .signedness = _signedness, \
583 .byte_order = _byte_order, \
588 #define _side_type_float(_type, _byte_order, _float_size_bits, _attr) \
594 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
595 .byte_order = _byte_order, \
596 .float_size_bits = _float_size_bits, \
601 #define _side_field(_name, _type) \
603 .field_name = _name, \
604 .side_type = _type, \
608 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
609 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
610 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
611 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
612 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
613 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
614 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
615 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
616 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
617 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_PARAM(_attr))
618 #define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_BITS_PER_LONG, \
619 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
620 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 16, SIDE_PARAM(_attr))
621 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 32, SIDE_PARAM(_attr))
622 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 64, SIDE_PARAM(_attr))
623 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 128, SIDE_PARAM(_attr))
624 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
625 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
627 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
628 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
629 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
630 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
631 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
632 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
633 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
634 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
635 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
636 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
637 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
638 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
639 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
640 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
641 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
642 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
643 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
646 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
647 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
648 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
649 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
650 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
651 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
652 #define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_LE, SIDE_BITS_PER_LONG, \
653 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
654 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, 16, SIDE_PARAM(_attr))
655 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, 32, SIDE_PARAM(_attr))
656 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, 64, SIDE_PARAM(_attr))
657 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 128, SIDE_PARAM(_attr))
659 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
660 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
661 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
662 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
663 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
664 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
665 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
666 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
667 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
668 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
669 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
672 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
673 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
674 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
675 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
676 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
677 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
678 #define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_BE, SIDE_BITS_PER_LONG, \
679 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
680 #define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, 16, SIDE_PARAM(_attr))
681 #define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, 32, SIDE_PARAM(_attr))
682 #define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, 64, SIDE_PARAM(_attr))
683 #define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, 128, SIDE_PARAM(_attr))
685 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
686 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
687 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
688 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
689 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
690 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
691 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
692 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
693 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
694 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
695 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
697 #define side_type_enum(_mappings, _elem_type) \
699 .type = SIDE_TYPE_ENUM, \
702 .mappings = _mappings, \
703 .elem_type = _elem_type, \
707 #define side_field_enum(_name, _mappings, _elem_type) \
708 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
710 #define side_type_enum_bitmap(_mappings, _elem_type) \
712 .type = SIDE_TYPE_ENUM_BITMAP, \
714 .side_enum_bitmap = { \
715 .mappings = _mappings, \
716 .elem_type = _elem_type, \
720 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
721 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
723 #define side_type_struct(_struct) \
725 .type = SIDE_TYPE_STRUCT, \
727 .side_struct = _struct, \
730 #define side_field_struct(_name, _struct) \
731 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
733 #define _side_type_struct_define(_fields, _attr) \
735 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
736 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
741 #define side_define_struct(_identifier, _fields, _attr) \
742 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
744 #define side_struct_literal(_fields, _attr) \
745 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
746 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
748 /* Scatter-gather struct */
750 #define _side_type_sg_integer(_type, _signedness, _byte_order, _offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
758 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
759 .integer_size_bits = _integer_size_bits, \
760 .len_bits = _len_bits, \
761 .signedness = _signedness, \
762 .byte_order = _byte_order, \
764 .offset_bits = _offset_bits, \
769 #define _side_field_sg(_name, _type) \
771 .field_name = _name, \
772 .side_type = _type, \
775 #define side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
776 _side_type_sg_integer(SIDE_TYPE_SG_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_HOST, \
777 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
778 #define side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
779 _side_type_sg_integer(SIDE_TYPE_SG_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_HOST, \
780 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
782 #define side_field_sg_unsigned_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
783 _side_field_sg(_name, side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
784 #define side_field_sg_signed_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
785 _side_field_sg(_name, side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
787 #define side_type_struct_sg(_struct_sg) \
789 .type = SIDE_TYPE_STRUCT_SG, \
791 .side_struct_sg = _struct_sg, \
794 #define side_field_struct_sg(_name, _struct_sg) \
795 _side_field(_name, side_type_struct_sg(SIDE_PARAM(_struct_sg)))
797 #define _side_type_struct_sg_define(_fields_sg, _attr) \
799 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields_sg)), \
800 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
801 .fields_sg = _fields_sg, \
805 #define side_define_struct_sg(_identifier, _fields_sg, _attr) \
806 const struct side_type_struct_sg _identifier = _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr))
808 #define side_struct_sg_literal(_fields_sg, _attr) \
809 SIDE_COMPOUND_LITERAL(const struct side_type_struct_sg, \
810 _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr)))
812 #define side_type_array(_elem_type, _length, _attr) \
814 .type = SIDE_TYPE_ARRAY, \
817 .elem_type = _elem_type, \
820 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
824 #define side_field_array(_name, _elem_type, _length, _attr) \
825 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
827 #define side_type_vla(_elem_type, _attr) \
829 .type = SIDE_TYPE_VLA, \
832 .elem_type = _elem_type, \
834 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
838 #define side_field_vla(_name, _elem_type, _attr) \
839 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
841 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
843 .type = SIDE_TYPE_VLA_VISITOR, \
845 .side_vla_visitor = { \
846 .elem_type = SIDE_PARAM(_elem_type), \
847 .visitor = _visitor, \
849 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
853 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
854 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
856 #define side_elem(...) \
857 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
859 #define side_field_list(...) \
860 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
862 #define side_field_sg_list(...) \
863 SIDE_COMPOUND_LITERAL(const struct side_struct_field_sg, __VA_ARGS__)
865 /* Static field arguments */
867 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
868 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
869 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
870 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
871 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
872 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
873 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
874 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
875 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
876 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
877 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
878 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .integer_value = { .side_u8 = (_val) } } }
879 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .integer_value = { .side_u16 = (_val) } } }
880 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .integer_value = { .side_u32 = (_val) } } }
881 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .integer_value = { .side_u64 = (_val) } } }
882 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
883 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
884 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
885 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
886 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
887 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
889 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
890 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
891 #define side_arg_struct_sg(_ptr) { .type = SIDE_TYPE_STRUCT_SG, .u = { .side_struct_sg_ptr = (_ptr) } }
892 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
893 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
894 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
896 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
897 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
898 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
899 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
900 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
901 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
902 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
903 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
904 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
905 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_array_fixint = (_ptr) } }
907 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
908 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
909 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
910 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
911 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
912 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
913 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
914 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
915 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
916 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
918 #define side_arg_dynamic(_dynamic_arg_type) \
920 .type = SIDE_TYPE_DYNAMIC, \
922 .dynamic = _dynamic_arg_type, \
926 /* Dynamic field arguments */
928 #define side_arg_dynamic_null(_attr) \
930 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
934 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
939 #define side_arg_dynamic_bool(_val, _attr) \
941 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
945 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
947 .side_bool = !!(_val), \
953 #define side_arg_dynamic_byte(_val, _attr) \
955 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
959 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
961 .side_byte = (_val), \
966 #define side_arg_dynamic_string(_val, _attr) \
968 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
972 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
974 .string = (uintptr_t) (_val), \
980 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
982 .dynamic_type = _type, \
987 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
988 .integer_size_bits = _integer_size_bits, \
989 .len_bits = _len_bits, \
990 .signedness = _signedness, \
991 .byte_order = _byte_order, \
1000 #define side_arg_dynamic_u8(_val, _attr) \
1001 _side_arg_dynamic_integer(.side_u8, _val, SIDE_DYNAMIC_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1002 #define side_arg_dynamic_s8(_val, _attr) \
1003 _side_arg_dynamic_integer(.side_s8, _val, SIDE_DYNAMIC_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1005 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1006 _side_arg_dynamic_integer(.side_u16, _val, SIDE_DYNAMIC_TYPE_U16, false, _byte_order, 16, 16, SIDE_PARAM(_attr))
1007 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1008 _side_arg_dynamic_integer(.side_u32, _val, SIDE_DYNAMIC_TYPE_U32, false, _byte_order, 32, 32, SIDE_PARAM(_attr))
1009 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1010 _side_arg_dynamic_integer(.side_u64, _val, SIDE_DYNAMIC_TYPE_U64, false, _byte_order, 64, 64, SIDE_PARAM(_attr))
1012 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1013 _side_arg_dynamic_integer(.side_s16, _val, SIDE_DYNAMIC_TYPE_S16, true, _byte_order, 16, 16, SIDE_PARAM(_attr))
1014 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1015 _side_arg_dynamic_integer(.side_s32, _val, SIDE_DYNAMIC_TYPE_S32, true, _byte_order, 32, 32, SIDE_PARAM(_attr))
1016 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1017 _side_arg_dynamic_integer(.side_s64, _val, SIDE_DYNAMIC_TYPE_S64, true, _byte_order, 64, 64, SIDE_PARAM(_attr))
1019 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1020 _side_arg_dynamic_integer(SIDE_PTR_HOST, (uintptr_t) (_val), SIDE_DYNAMIC_TYPE_POINTER_HOST, false, _byte_order, \
1021 SIDE_BITS_PER_LONG, SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
1023 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size_bits, _attr) \
1025 .dynamic_type = _type, \
1030 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1031 .byte_order = _byte_order, \
1032 .float_size_bits = _float_size_bits, \
1041 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1042 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, _byte_order, 16, SIDE_PARAM(_attr))
1043 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1044 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, _byte_order, 32, SIDE_PARAM(_attr))
1045 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1046 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, _byte_order, 64, SIDE_PARAM(_attr))
1047 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1048 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, _byte_order, 128, SIDE_PARAM(_attr))
1051 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1052 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1053 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1054 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1055 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1056 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1057 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1058 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1059 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1060 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1061 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1064 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1065 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1066 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1067 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1068 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1069 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1070 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1071 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1072 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1073 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1074 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1077 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1078 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1079 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1080 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1081 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1082 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1083 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1084 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1085 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1086 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1087 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1089 #define side_arg_dynamic_vla(_vla) \
1091 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1093 .side_dynamic_vla = (_vla), \
1097 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1099 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1101 .side_dynamic_vla_visitor = { \
1103 .visitor = _dynamic_vla_visitor, \
1105 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1110 #define side_arg_dynamic_struct(_struct) \
1112 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1114 .side_dynamic_struct = (_struct), \
1118 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1120 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1122 .side_dynamic_struct_visitor = { \
1124 .visitor = _dynamic_struct_visitor, \
1126 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1131 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1132 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1133 const struct side_arg_dynamic_vec_vla _identifier = { \
1134 .sav = _identifier##_vec, \
1136 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1137 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1140 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1141 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1142 const struct side_arg_dynamic_event_struct _identifier = { \
1143 .fields = _identifier##_fields, \
1145 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1146 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1149 #define side_arg_define_vec(_identifier, _sav) \
1150 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1151 const struct side_arg_vec_description _identifier = { \
1152 .sav = _identifier##_vec, \
1153 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1156 #define side_arg_dynamic_field(_name, _elem) \
1158 .field_name = _name, \
1162 #define side_arg_list(...) __VA_ARGS__
1164 #define side_define_enum(_identifier, _mappings, _attr) \
1165 const struct side_enum_mappings _identifier = { \
1166 .mappings = _mappings, \
1168 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1169 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1172 #define side_enum_mapping_list(...) \
1173 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1175 #define side_enum_mapping_range(_label, _begin, _end) \
1177 .range_begin = _begin, \
1178 .range_end = _end, \
1182 #define side_enum_mapping_value(_label, _value) \
1184 .range_begin = _value, \
1185 .range_end = _value, \
1189 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1190 const struct side_enum_bitmap_mappings _identifier = { \
1191 .mappings = _mappings, \
1193 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1194 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1197 #define side_enum_bitmap_mapping_list(...) \
1198 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1200 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1202 .range_begin = _begin, \
1203 .range_end = _end, \
1207 #define side_enum_bitmap_mapping_value(_label, _value) \
1209 .range_begin = _value, \
1210 .range_end = _value, \
1214 #define side_event_cond(_identifier) \
1215 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1218 #define side_event_call(_identifier, _sav) \
1220 const struct side_arg_vec side_sav[] = { _sav }; \
1221 const struct side_arg_vec_description sav_desc = { \
1223 .len = SIDE_ARRAY_SIZE(side_sav), \
1225 side_call(&(_identifier), &sav_desc); \
1228 #define side_event(_identifier, _sav) \
1229 side_event_cond(_identifier) \
1230 side_event_call(_identifier, SIDE_PARAM(_sav))
1232 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1234 const struct side_arg_vec side_sav[] = { _sav }; \
1235 const struct side_arg_vec_description sav_desc = { \
1237 .len = SIDE_ARRAY_SIZE(side_sav), \
1239 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1240 const struct side_arg_dynamic_event_struct var_struct = { \
1241 .fields = side_fields, \
1243 .len = SIDE_ARRAY_SIZE(side_fields), \
1244 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1246 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1249 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1250 side_event_cond(_identifier) \
1251 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1253 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1254 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1255 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1257 .enabled = &(side_event_enable__##_identifier), \
1258 .provider_name = _provider, \
1259 .event_name = _event, \
1260 .fields = _fields, \
1262 .callbacks = &side_empty_callback, \
1263 .flags = (_flags), \
1265 .loglevel = _loglevel, \
1266 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1267 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1268 .nr_callbacks = 0, \
1270 static const struct side_event_description *side_event_ptr__##_identifier \
1271 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1273 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1274 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1275 SIDE_PARAM(_attr), 0)
1277 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1278 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1279 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1281 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1282 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1283 SIDE_PARAM(_attr), 0)
1285 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1286 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1287 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1289 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1290 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1291 SIDE_PARAM(_attr), 0)
1293 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1294 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1295 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1297 #define side_declare_event(_identifier) \
1298 extern uintptr_t side_event_enable_##_identifier; \
1299 extern struct side_event_description _identifier
1301 extern const struct side_callback side_empty_callback
;
1303 void side_call(const struct side_event_description
*desc
,
1304 const struct side_arg_vec_description
*sav_desc
);
1305 void side_call_variadic(const struct side_event_description
*desc
,
1306 const struct side_arg_vec_description
*sav_desc
,
1307 const struct side_arg_dynamic_event_struct
*var_struct
);
1309 int side_tracer_callback_register(struct side_event_description
*desc
,
1310 void (*call
)(const struct side_event_description
*desc
,
1311 const struct side_arg_vec_description
*sav_desc
,
1314 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1315 void (*call_variadic
)(const struct side_event_description
*desc
,
1316 const struct side_arg_vec_description
*sav_desc
,
1317 const struct side_arg_dynamic_event_struct
*var_struct
,
1320 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1321 void (*call
)(const struct side_event_description
*desc
,
1322 const struct side_arg_vec_description
*sav_desc
,
1325 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1326 void (*call_variadic
)(const struct side_event_description
*desc
,
1327 const struct side_arg_vec_description
*sav_desc
,
1328 const struct side_arg_dynamic_event_struct
*var_struct
,
1332 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
, uint32_t nr_events
);
1333 void side_events_unregister(struct side_events_register_handle
*handle
);
1335 enum side_tracer_notification
{
1336 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1337 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1340 /* Callback is invoked with side library internal lock held. */
1341 struct side_tracer_handle
*side_tracer_event_notification_register(
1342 void (*cb
)(enum side_tracer_notification notif
,
1343 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1345 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1347 void side_init(void);
1348 void side_exit(void);
1351 * These weak symbols, the constructor, and destructor take care of
1352 * registering only _one_ instance of the side instrumentation per
1353 * shared-ojbect (or for the whole main program).
1355 extern struct side_event_description
* __start_side_event_description_ptr
[]
1356 __attribute__((weak
, visibility("hidden")));
1357 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1358 __attribute__((weak
, visibility("hidden")));
1359 int side_event_description_ptr_registered
1360 __attribute__((weak
, visibility("hidden")));
1361 struct side_events_register_handle
*side_events_handle
1362 __attribute__((weak
, visibility("hidden")));
1365 side_event_description_ptr_init(void)
1366 __attribute__((no_instrument_function
))
1367 __attribute__((constructor
));
1369 side_event_description_ptr_init(void)
1371 if (side_event_description_ptr_registered
++)
1373 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1374 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1378 side_event_description_ptr_exit(void)
1379 __attribute__((no_instrument_function
))
1380 __attribute__((destructor
));
1382 side_event_description_ptr_exit(void)
1384 if (--side_event_description_ptr_registered
)
1386 side_events_unregister(side_events_handle
);
1387 side_events_handle
= NULL
;
1390 #endif /* _SIDE_TRACE_H */