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.
25 struct side_arg_dynamic
;
26 struct side_arg_dynamic_vla
;
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
;
37 enum side_type_label
{
38 /* Statically declared types */
52 SIDE_TYPE_FLOAT_BINARY16
,
53 SIDE_TYPE_FLOAT_BINARY32
,
54 SIDE_TYPE_FLOAT_BINARY64
,
55 SIDE_TYPE_FLOAT_BINARY128
,
58 /* Statically declared compound types */
63 SIDE_TYPE_VLA_VISITOR
,
74 SIDE_TYPE_ARRAY_POINTER32
,
75 SIDE_TYPE_ARRAY_POINTER64
,
86 SIDE_TYPE_VLA_POINTER32
,
87 SIDE_TYPE_VLA_POINTER64
,
89 /* Statically declared enumeration types */
91 SIDE_TYPE_ENUM_BITMAP
,
96 SIDE_TYPE_DYNAMIC_NULL
,
97 SIDE_TYPE_DYNAMIC_BOOL
,
99 SIDE_TYPE_DYNAMIC_U16
,
100 SIDE_TYPE_DYNAMIC_U32
,
101 SIDE_TYPE_DYNAMIC_U64
,
102 SIDE_TYPE_DYNAMIC_S8
,
103 SIDE_TYPE_DYNAMIC_S16
,
104 SIDE_TYPE_DYNAMIC_S32
,
105 SIDE_TYPE_DYNAMIC_S64
,
106 SIDE_TYPE_DYNAMIC_BYTE
,
107 SIDE_TYPE_DYNAMIC_POINTER32
,
108 SIDE_TYPE_DYNAMIC_POINTER64
,
109 SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
,
110 SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
,
111 SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
,
112 SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
,
113 SIDE_TYPE_DYNAMIC_STRING
,
115 /* Dynamic compound types */
116 SIDE_TYPE_DYNAMIC_STRUCT
,
117 SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
,
118 SIDE_TYPE_DYNAMIC_VLA
,
119 SIDE_TYPE_DYNAMIC_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
,
142 enum side_type_label_sg
{
144 SIDE_TYPE_SG_UNSIGNED_INT
,
145 SIDE_TYPE_SG_SIGNED_INT
,
149 SIDE_LOGLEVEL_EMERG
= 0,
150 SIDE_LOGLEVEL_ALERT
= 1,
151 SIDE_LOGLEVEL_CRIT
= 2,
152 SIDE_LOGLEVEL_ERR
= 3,
153 SIDE_LOGLEVEL_WARNING
= 4,
154 SIDE_LOGLEVEL_NOTICE
= 5,
155 SIDE_LOGLEVEL_INFO
= 6,
156 SIDE_LOGLEVEL_DEBUG
= 7,
159 enum side_visitor_status
{
160 SIDE_VISITOR_STATUS_OK
= 0,
161 SIDE_VISITOR_STATUS_ERROR
= -1,
166 SIDE_ERROR_INVAL
= 1,
167 SIDE_ERROR_EXIST
= 2,
168 SIDE_ERROR_NOMEM
= 3,
169 SIDE_ERROR_NOENT
= 4,
170 SIDE_ERROR_EXITING
= 5,
173 enum side_type_label_byte_order
{
174 SIDE_TYPE_BYTE_ORDER_LE
= 0,
175 SIDE_TYPE_BYTE_ORDER_BE
= 1,
178 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
179 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
181 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
184 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
185 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
187 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
190 typedef enum side_visitor_status (*side_visitor
)(
191 const struct side_tracer_visitor_ctx
*tracer_ctx
,
193 typedef enum side_visitor_status (*side_dynamic_struct_visitor
)(
194 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
196 typedef enum side_visitor_status (*side_dynamic_vla_visitor
)(
197 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
200 union side_integer_value
{
211 union side_float_value
{
213 _Float16 side_float_binary16
;
216 _Float32 side_float_binary32
;
219 _Float64 side_float_binary64
;
222 _Float128 side_float_binary128
;
226 struct side_attr_value
{
227 uint32_t type
; /* enum side_attr_type */
230 uint64_t string_value
; /* const char * */
231 union side_integer_value integer_value
;
232 union side_float_value float_value
;
236 /* User attributes. */
239 const struct side_attr_value value
;
242 /* Type descriptions */
243 struct side_type_null
{
244 const struct side_attr
*attr
;
248 struct side_type_bool
{
249 const struct side_attr
*attr
;
253 struct side_type_byte
{
254 const struct side_attr
*attr
;
258 struct side_type_string
{
259 const struct side_attr
*attr
;
263 struct side_type_integer
{
264 const struct side_attr
*attr
;
266 uint16_t integer_size_bits
; /* bits */
267 uint16_t len_bits
; /* bits */
268 uint8_t signedness
; /* true/false */
269 uint8_t byte_order
; /* enum side_type_label_byte_order */
272 struct side_type_float
{
273 const struct side_attr
*attr
;
275 uint32_t byte_order
; /* enum side_type_label_byte_order */
276 uint16_t float_size_bits
; /* bits */
279 struct side_enum_mapping
{
285 struct side_enum_mappings
{
286 const struct side_enum_mapping
*mappings
;
287 const struct side_attr
*attr
;
288 uint32_t nr_mappings
;
292 struct side_enum_bitmap_mapping
{
293 uint64_t range_begin
;
298 struct side_enum_bitmap_mappings
{
299 const struct side_enum_bitmap_mapping
*mappings
;
300 const struct side_attr
*attr
;
301 uint32_t nr_mappings
;
305 struct side_type_struct
{
308 const struct side_event_field
*fields
;
309 const struct side_attr
*attr
;
312 struct side_type_sg_description
{
313 uint64_t offset
; /* bytes */
314 uint32_t type
; /* enum side_type_label_sg */
316 struct side_type_null side_null
;
318 struct side_type_integer type
;
319 uint16_t offset_bits
; /* bits */
320 } SIDE_PACKED side_integer
;
324 struct side_struct_field_sg
{
325 const char *field_name
;
326 struct side_type_sg_description side_type
;
329 /* Structure fields scatter-gather. */
330 struct side_type_struct_sg
{
333 const struct side_struct_field_sg
*fields_sg
;
334 const struct side_attr
*attr
;
337 /* Statically defined types. */
339 uint32_t type
; /* enum side_type_label */
342 struct side_type_null side_null
;
343 struct side_type_bool side_bool
;
344 struct side_type_byte side_byte
;
345 struct side_type_string side_string
;
346 struct side_type_integer side_integer
;
347 struct side_type_float side_float
;
351 const struct side_type
*elem_type
;
352 const struct side_attr
*attr
;
355 } SIDE_PACKED side_array
;
357 const struct side_type
*elem_type
;
358 const struct side_attr
*attr
;
360 } SIDE_PACKED side_vla
;
362 const struct side_type
*elem_type
;
363 side_visitor visitor
;
364 const struct side_attr
*attr
;
366 } SIDE_PACKED side_vla_visitor
;
367 const struct side_type_struct
*side_struct
;
368 const struct side_type_struct_sg
*side_struct_sg
;
370 /* Enumeration types */
372 const struct side_enum_mappings
*mappings
;
373 const struct side_type
*elem_type
;
374 } SIDE_PACKED side_enum
;
376 const struct side_enum_bitmap_mappings
*mappings
;
377 const struct side_type
*elem_type
;
378 } SIDE_PACKED side_enum_bitmap
;
382 struct side_event_field
{
383 const char *field_name
;
384 struct side_type side_type
;
387 enum side_event_flags
{
388 SIDE_EVENT_FLAG_VARIADIC
= (1 << 0),
391 struct side_callback
{
393 void (*call
)(const struct side_event_description
*desc
,
394 const struct side_arg_vec
*sav_desc
,
396 void (*call_variadic
)(const struct side_event_description
*desc
,
397 const struct side_arg_vec
*sav_desc
,
398 const struct side_arg_dynamic_event_struct
*var_struct
,
404 struct side_arg_static
{
408 uint64_t string_value
; /* const char * */
409 union side_integer_value integer_value
;
410 union side_float_value float_value
;
413 const struct side_arg_vec
*side_struct
;
414 const struct side_arg_vec
*side_array
;
415 const struct side_arg_vec
*side_vla
;
416 void *side_vla_app_visitor_ctx
;
417 void *side_array_fixint
;
421 } SIDE_PACKED side_vla_fixint
;
422 void *side_struct_sg_ptr
;
425 struct side_arg_dynamic
{
427 struct side_type_null side_null
;
429 struct side_type_bool type
;
431 } SIDE_PACKED side_bool
;
434 struct side_type_byte type
;
436 } SIDE_PACKED side_byte
;
439 struct side_type_string type
;
440 uint64_t value
; /* const char * */
441 } SIDE_PACKED side_string
;
445 struct side_type_integer type
;
446 union side_integer_value value
;
447 } SIDE_PACKED side_integer
;
450 struct side_type_float type
;
451 union side_float_value value
;
452 } SIDE_PACKED side_float
;
455 const struct side_arg_dynamic_event_struct
*side_dynamic_struct
;
458 side_dynamic_struct_visitor visitor
;
459 const struct side_attr
*attr
;
461 } SIDE_PACKED side_dynamic_struct_visitor
;
462 const struct side_arg_dynamic_vla
*side_dynamic_vla
;
465 side_dynamic_vla_visitor visitor
;
466 const struct side_attr
*attr
;
468 } SIDE_PACKED side_dynamic_vla_visitor
;
472 enum side_type_label type
;
474 struct side_arg_static side_static
;
475 struct side_arg_dynamic side_dynamic
;
479 struct side_arg_vec
{
480 const struct side_arg
*sav
;
484 struct side_event_description
{
486 const char *provider_name
;
487 const char *event_name
;
488 const struct side_event_field
*fields
;
489 const struct side_attr
*attr
;
490 const struct side_callback
*callbacks
;
493 uint32_t loglevel
; /* enum side_loglevel */
496 uint32_t nr_callbacks
;
499 struct side_arg_dynamic_vla
{
500 const struct side_arg
*sav
;
501 const struct side_attr
*attr
;
506 struct side_arg_dynamic_event_field
{
507 const char *field_name
;
508 const struct side_arg elem
;
511 struct side_arg_dynamic_event_struct
{
512 const struct side_arg_dynamic_event_field
*fields
;
513 const struct side_attr
*attr
;
518 /* The visitor pattern is a double-dispatch visitor. */
519 struct side_tracer_visitor_ctx
{
520 enum side_visitor_status (*write_elem
)(
521 const struct side_tracer_visitor_ctx
*tracer_ctx
,
522 const struct side_arg
*elem
);
523 void *priv
; /* Private tracer context. */
526 struct side_tracer_dynamic_struct_visitor_ctx
{
527 enum side_visitor_status (*write_field
)(
528 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
529 const struct side_arg_dynamic_event_field
*dynamic_field
);
530 void *priv
; /* Private tracer context. */
533 struct side_tracer_dynamic_vla_visitor_ctx
{
534 enum side_visitor_status (*write_elem
)(
535 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
536 const struct side_arg
*elem
);
537 void *priv
; /* Private tracer context. */
540 /* Event and type attributes */
542 #if SIDE_BITS_PER_LONG == 64
543 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
544 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
545 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
546 # define SIDE_TYPE_DYNAMIC_POINTER_HOST SIDE_TYPE_DYNAMIC_POINTER64
547 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
548 # define SIDE_PTR_HOST .side_u64
550 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
551 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
552 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
553 # define SIDE_TYPE_DYNAMIC_POINTER_HOST SIDE_TYPE_DYNAMIC_POINTER32
554 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
555 # define SIDE_PTR_HOST .side_u32
558 #define side_attr(_key, _value) \
561 .value = SIDE_PARAM(_value), \
564 #define side_attr_list(...) \
565 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
567 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
568 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
569 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
570 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
571 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
572 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
573 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
574 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
575 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
576 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
577 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
578 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
579 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
580 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
581 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
582 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string_value = (uintptr_t) (_val) } }
584 /* Static field definition */
586 #define side_type_null(_attr) \
588 .type = SIDE_TYPE_NULL, \
592 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
597 #define side_type_bool(_attr) \
599 .type = SIDE_TYPE_BOOL, \
603 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
608 #define side_type_byte(_attr) \
610 .type = SIDE_TYPE_BYTE, \
614 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
619 #define side_type_string(_attr) \
621 .type = SIDE_TYPE_STRING, \
625 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
630 #define side_type_dynamic() \
632 .type = SIDE_TYPE_DYNAMIC, \
635 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
641 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
642 .integer_size_bits = _integer_size_bits, \
643 .len_bits = _len_bits, \
644 .signedness = _signedness, \
645 .byte_order = _byte_order, \
650 #define _side_type_float(_type, _byte_order, _float_size_bits, _attr) \
656 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
657 .byte_order = _byte_order, \
658 .float_size_bits = _float_size_bits, \
663 #define _side_field(_name, _type) \
665 .field_name = _name, \
666 .side_type = _type, \
670 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
671 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
672 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
673 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
674 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
675 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
676 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
677 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
678 #define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_BITS_PER_LONG, \
679 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
680 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 16, SIDE_PARAM(_attr))
681 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 32, SIDE_PARAM(_attr))
682 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 64, SIDE_PARAM(_attr))
683 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 128, SIDE_PARAM(_attr))
685 #define side_field_null(_name, _attr) _side_field(_name, side_type_null(SIDE_PARAM(_attr)))
686 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
687 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
688 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
689 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
690 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
691 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
692 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
693 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
694 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
695 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
696 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
697 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
698 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
699 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
700 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
701 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
702 #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic())
705 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
706 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
707 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
708 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
709 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
710 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
711 #define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_LE, SIDE_BITS_PER_LONG, \
712 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
713 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, 16, SIDE_PARAM(_attr))
714 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, 32, SIDE_PARAM(_attr))
715 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, 64, SIDE_PARAM(_attr))
716 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 128, SIDE_PARAM(_attr))
718 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
719 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
720 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
721 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
722 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
723 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
724 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
725 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
726 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
727 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
728 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
731 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
732 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
733 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
734 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
735 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
736 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
737 #define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_BE, SIDE_BITS_PER_LONG, \
738 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
739 #define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, 16, SIDE_PARAM(_attr))
740 #define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, 32, SIDE_PARAM(_attr))
741 #define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, 64, SIDE_PARAM(_attr))
742 #define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, 128, SIDE_PARAM(_attr))
744 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
745 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
746 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
747 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
748 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
749 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
750 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
751 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
752 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
753 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
754 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
756 #define side_type_enum(_mappings, _elem_type) \
758 .type = SIDE_TYPE_ENUM, \
761 .mappings = _mappings, \
762 .elem_type = _elem_type, \
766 #define side_field_enum(_name, _mappings, _elem_type) \
767 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
769 #define side_type_enum_bitmap(_mappings, _elem_type) \
771 .type = SIDE_TYPE_ENUM_BITMAP, \
773 .side_enum_bitmap = { \
774 .mappings = _mappings, \
775 .elem_type = _elem_type, \
779 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
780 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
782 #define side_type_struct(_struct) \
784 .type = SIDE_TYPE_STRUCT, \
786 .side_struct = _struct, \
789 #define side_field_struct(_name, _struct) \
790 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
792 #define _side_type_struct_define(_fields, _attr) \
794 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
795 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
800 #define side_define_struct(_identifier, _fields, _attr) \
801 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
803 #define side_struct_literal(_fields, _attr) \
804 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
805 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
807 /* Scatter-gather struct */
809 #define _side_field_sg(_name, _type) \
811 .field_name = _name, \
812 .side_type = _type, \
815 #define side_type_sg_null(_attr) \
818 .type = SIDE_TYPE_SG_NULL, \
822 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
827 #define side_field_sg_null(_name, _attr) \
828 _side_field_sg(_name, side_type_sg_null(SIDE_PARAM(_attr)))
830 #define _side_type_sg_integer(_type, _signedness, _byte_order, _offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
838 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
839 .integer_size_bits = _integer_size_bits, \
840 .len_bits = _len_bits, \
841 .signedness = _signedness, \
842 .byte_order = _byte_order, \
844 .offset_bits = _offset_bits, \
849 #define side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
850 _side_type_sg_integer(SIDE_TYPE_SG_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_HOST, \
851 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
852 #define side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
853 _side_type_sg_integer(SIDE_TYPE_SG_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_HOST, \
854 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
856 #define side_field_sg_unsigned_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
857 _side_field_sg(_name, side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
858 #define side_field_sg_signed_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
859 _side_field_sg(_name, side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
861 #define side_type_struct_sg(_struct_sg) \
863 .type = SIDE_TYPE_STRUCT_SG, \
865 .side_struct_sg = _struct_sg, \
868 #define side_field_struct_sg(_name, _struct_sg) \
869 _side_field(_name, side_type_struct_sg(SIDE_PARAM(_struct_sg)))
871 #define _side_type_struct_sg_define(_fields_sg, _attr) \
873 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields_sg)), \
874 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
875 .fields_sg = _fields_sg, \
879 #define side_define_struct_sg(_identifier, _fields_sg, _attr) \
880 const struct side_type_struct_sg _identifier = _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr))
882 #define side_struct_sg_literal(_fields_sg, _attr) \
883 SIDE_COMPOUND_LITERAL(const struct side_type_struct_sg, \
884 _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr)))
886 #define side_type_array(_elem_type, _length, _attr) \
888 .type = SIDE_TYPE_ARRAY, \
891 .elem_type = _elem_type, \
894 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
898 #define side_field_array(_name, _elem_type, _length, _attr) \
899 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
901 #define side_type_vla(_elem_type, _attr) \
903 .type = SIDE_TYPE_VLA, \
906 .elem_type = _elem_type, \
908 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
912 #define side_field_vla(_name, _elem_type, _attr) \
913 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
915 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
917 .type = SIDE_TYPE_VLA_VISITOR, \
919 .side_vla_visitor = { \
920 .elem_type = SIDE_PARAM(_elem_type), \
921 .visitor = _visitor, \
923 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
927 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
928 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
930 #define side_elem(...) \
931 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
933 #define side_field_list(...) \
934 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
936 #define side_field_sg_list(...) \
937 SIDE_COMPOUND_LITERAL(const struct side_struct_field_sg, __VA_ARGS__)
939 /* Static field arguments */
941 #define side_arg_null(_val) { .type = SIDE_TYPE_NULL }
942 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = !!(_val) } } }
943 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_static = { .byte_value = (_val) } } }
944 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
946 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
947 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
948 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
949 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
950 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
951 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
952 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
953 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
954 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { .side_static = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } } }
955 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
956 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
957 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
958 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
959 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
960 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
961 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
962 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
963 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
964 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
966 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = (_side_type) } } }
967 #define side_arg_struct_sg(_ptr) { .type = SIDE_TYPE_STRUCT_SG, .u = { .side_static = { .side_struct_sg_ptr = (_ptr) } } }
968 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
969 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
970 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
972 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
973 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
974 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
975 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
976 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
977 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
978 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
979 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
980 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
981 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_static = { .side_array_fixint = (_ptr) } } }
983 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
984 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
985 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
986 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
987 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
988 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
989 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
990 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
991 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
992 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } }
994 /* Dynamic field arguments */
996 #define side_arg_dynamic_null(_attr) \
998 .type = SIDE_TYPE_DYNAMIC_NULL, \
1003 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1009 #define side_arg_dynamic_bool(_val, _attr) \
1011 .type = SIDE_TYPE_DYNAMIC_BOOL, \
1017 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1019 .value = !!(_val), \
1025 #define side_arg_dynamic_byte(_val, _attr) \
1027 .type = SIDE_TYPE_DYNAMIC_BYTE, \
1033 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1040 #define side_arg_dynamic_string(_val, _attr) \
1042 .type = SIDE_TYPE_DYNAMIC_STRING, \
1048 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1050 .value = (uintptr_t) (_val), \
1056 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
1064 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1065 .integer_size_bits = _integer_size_bits, \
1066 .len_bits = _len_bits, \
1067 .signedness = _signedness, \
1068 .byte_order = _byte_order, \
1078 #define side_arg_dynamic_u8(_val, _attr) \
1079 _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1080 #define side_arg_dynamic_s8(_val, _attr) \
1081 _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1083 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1084 _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_U16, false, _byte_order, 16, 16, SIDE_PARAM(_attr))
1085 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1086 _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_U32, false, _byte_order, 32, 32, SIDE_PARAM(_attr))
1087 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1088 _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_U64, false, _byte_order, 64, 64, SIDE_PARAM(_attr))
1090 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1091 _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_S16, true, _byte_order, 16, 16, SIDE_PARAM(_attr))
1092 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1093 _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_S32, true, _byte_order, 32, 32, SIDE_PARAM(_attr))
1094 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1095 _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_S64, true, _byte_order, 64, 64, SIDE_PARAM(_attr))
1097 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1098 _side_arg_dynamic_integer(SIDE_PTR_HOST, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER_HOST, false, _byte_order, \
1099 SIDE_BITS_PER_LONG, SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
1101 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size_bits, _attr) \
1109 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1110 .byte_order = _byte_order, \
1111 .float_size_bits = _float_size_bits, \
1121 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1122 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY16, _byte_order, 16, SIDE_PARAM(_attr))
1123 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1124 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY32, _byte_order, 32, SIDE_PARAM(_attr))
1125 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1126 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY64, _byte_order, 64, SIDE_PARAM(_attr))
1127 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1128 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY128, _byte_order, 128, SIDE_PARAM(_attr))
1131 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1132 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1133 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1134 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1135 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1136 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1137 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1138 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1139 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1140 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1141 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1144 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1145 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1146 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1147 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1148 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1149 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1150 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1151 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1152 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1153 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1154 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1157 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1158 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1159 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1160 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1161 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1162 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1163 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1164 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1165 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1166 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1167 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1169 #define side_arg_dynamic_vla(_vla) \
1171 .type = SIDE_TYPE_DYNAMIC_VLA, \
1174 .side_dynamic_vla = (_vla), \
1179 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1181 .type = SIDE_TYPE_DYNAMIC_VLA_VISITOR, \
1184 .side_dynamic_vla_visitor = { \
1186 .visitor = _dynamic_vla_visitor, \
1188 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1194 #define side_arg_dynamic_struct(_struct) \
1196 .type = SIDE_TYPE_DYNAMIC_STRUCT, \
1199 .side_dynamic_struct = (_struct), \
1204 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1206 .type = SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, \
1209 .side_dynamic_struct_visitor = { \
1211 .visitor = _dynamic_struct_visitor, \
1213 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1219 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1220 const struct side_arg _identifier##_vec[] = { _sav }; \
1221 const struct side_arg_dynamic_vla _identifier = { \
1222 .sav = _identifier##_vec, \
1224 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1225 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1228 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1229 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1230 const struct side_arg_dynamic_event_struct _identifier = { \
1231 .fields = _identifier##_fields, \
1233 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1234 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1237 #define side_arg_define_vec(_identifier, _sav) \
1238 const struct side_arg _identifier##_vec[] = { _sav }; \
1239 const struct side_arg_vec _identifier = { \
1240 .sav = _identifier##_vec, \
1241 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1244 #define side_arg_dynamic_field(_name, _elem) \
1246 .field_name = _name, \
1250 #define side_arg_list(...) __VA_ARGS__
1252 #define side_define_enum(_identifier, _mappings, _attr) \
1253 const struct side_enum_mappings _identifier = { \
1254 .mappings = _mappings, \
1256 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1257 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1260 #define side_enum_mapping_list(...) \
1261 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1263 #define side_enum_mapping_range(_label, _begin, _end) \
1265 .range_begin = _begin, \
1266 .range_end = _end, \
1270 #define side_enum_mapping_value(_label, _value) \
1272 .range_begin = _value, \
1273 .range_end = _value, \
1277 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1278 const struct side_enum_bitmap_mappings _identifier = { \
1279 .mappings = _mappings, \
1281 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1282 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1285 #define side_enum_bitmap_mapping_list(...) \
1286 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1288 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1290 .range_begin = _begin, \
1291 .range_end = _end, \
1295 #define side_enum_bitmap_mapping_value(_label, _value) \
1297 .range_begin = _value, \
1298 .range_end = _value, \
1302 #define side_event_cond(_identifier) \
1303 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1306 #define side_event_call(_identifier, _sav) \
1308 const struct side_arg side_sav[] = { _sav }; \
1309 const struct side_arg_vec sav_desc = { \
1311 .len = SIDE_ARRAY_SIZE(side_sav), \
1313 side_call(&(_identifier), &sav_desc); \
1316 #define side_event(_identifier, _sav) \
1317 side_event_cond(_identifier) \
1318 side_event_call(_identifier, SIDE_PARAM(_sav))
1320 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1322 const struct side_arg side_sav[] = { _sav }; \
1323 const struct side_arg_vec sav_desc = { \
1325 .len = SIDE_ARRAY_SIZE(side_sav), \
1327 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1328 const struct side_arg_dynamic_event_struct var_struct = { \
1329 .fields = side_fields, \
1331 .len = SIDE_ARRAY_SIZE(side_fields), \
1332 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1334 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1337 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1338 side_event_cond(_identifier) \
1339 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1341 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1342 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1343 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1345 .enabled = &(side_event_enable__##_identifier), \
1346 .provider_name = _provider, \
1347 .event_name = _event, \
1348 .fields = _fields, \
1350 .callbacks = &side_empty_callback, \
1351 .flags = (_flags), \
1353 .loglevel = _loglevel, \
1354 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1355 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1356 .nr_callbacks = 0, \
1358 static const struct side_event_description *side_event_ptr__##_identifier \
1359 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1361 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1362 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1363 SIDE_PARAM(_attr), 0)
1365 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1366 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1367 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1369 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1370 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1371 SIDE_PARAM(_attr), 0)
1373 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1374 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1375 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1377 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1378 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1379 SIDE_PARAM(_attr), 0)
1381 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1382 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1383 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1385 #define side_declare_event(_identifier) \
1386 extern uintptr_t side_event_enable_##_identifier; \
1387 extern struct side_event_description _identifier
1389 extern const struct side_callback side_empty_callback
;
1391 void side_call(const struct side_event_description
*desc
,
1392 const struct side_arg_vec
*sav_desc
);
1393 void side_call_variadic(const struct side_event_description
*desc
,
1394 const struct side_arg_vec
*sav_desc
,
1395 const struct side_arg_dynamic_event_struct
*var_struct
);
1397 int side_tracer_callback_register(struct side_event_description
*desc
,
1398 void (*call
)(const struct side_event_description
*desc
,
1399 const struct side_arg_vec
*sav_desc
,
1402 int side_tracer_callback_variadic_register(struct side_event_description
*desc
,
1403 void (*call_variadic
)(const struct side_event_description
*desc
,
1404 const struct side_arg_vec
*sav_desc
,
1405 const struct side_arg_dynamic_event_struct
*var_struct
,
1408 int side_tracer_callback_unregister(struct side_event_description
*desc
,
1409 void (*call
)(const struct side_event_description
*desc
,
1410 const struct side_arg_vec
*sav_desc
,
1413 int side_tracer_callback_variadic_unregister(struct side_event_description
*desc
,
1414 void (*call_variadic
)(const struct side_event_description
*desc
,
1415 const struct side_arg_vec
*sav_desc
,
1416 const struct side_arg_dynamic_event_struct
*var_struct
,
1420 struct side_events_register_handle
*side_events_register(struct side_event_description
**events
, uint32_t nr_events
);
1421 void side_events_unregister(struct side_events_register_handle
*handle
);
1423 enum side_tracer_notification
{
1424 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
,
1425 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS
,
1428 /* Callback is invoked with side library internal lock held. */
1429 struct side_tracer_handle
*side_tracer_event_notification_register(
1430 void (*cb
)(enum side_tracer_notification notif
,
1431 struct side_event_description
**events
, uint32_t nr_events
, void *priv
),
1433 void side_tracer_event_notification_unregister(struct side_tracer_handle
*handle
);
1435 void side_init(void);
1436 void side_exit(void);
1439 * These weak symbols, the constructor, and destructor take care of
1440 * registering only _one_ instance of the side instrumentation per
1441 * shared-ojbect (or for the whole main program).
1443 extern struct side_event_description
* __start_side_event_description_ptr
[]
1444 __attribute__((weak
, visibility("hidden")));
1445 extern struct side_event_description
* __stop_side_event_description_ptr
[]
1446 __attribute__((weak
, visibility("hidden")));
1447 int side_event_description_ptr_registered
1448 __attribute__((weak
, visibility("hidden")));
1449 struct side_events_register_handle
*side_events_handle
1450 __attribute__((weak
, visibility("hidden")));
1453 side_event_description_ptr_init(void)
1454 __attribute__((no_instrument_function
))
1455 __attribute__((constructor
));
1457 side_event_description_ptr_init(void)
1459 if (side_event_description_ptr_registered
++)
1461 side_events_handle
= side_events_register(__start_side_event_description_ptr
,
1462 __stop_side_event_description_ptr
- __start_side_event_description_ptr
);
1466 side_event_description_ptr_exit(void)
1467 __attribute__((no_instrument_function
))
1468 __attribute__((destructor
));
1470 side_event_description_ptr_exit(void)
1472 if (--side_event_description_ptr_registered
)
1474 side_events_unregister(side_events_handle
);
1475 side_events_handle
= NULL
;
1478 #endif /* _SIDE_TRACE_H */