trace.h: Use side_enum_t for enum side_type_label_byte_order
[libside.git] / include / side / trace.h
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 */
5
6 #ifndef _SIDE_TRACE_H
7 #define _SIDE_TRACE_H
8
9 #include <stdint.h>
10 #include <inttypes.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <math.h>
14 #include <stdbool.h>
15 #include <side/macros.h>
16 #include <side/endian.h>
17
18 /*
19 * SIDE stands for "Software Instrumentation Dynamically Enabled"
20 *
21 * This is an instrumentation API for Linux user-space, which exposes an
22 * instrumentation type system and facilities allowing a kernel or
23 * user-space tracer to consume user-space instrumentation.
24 *
25 * This instrumentation API exposes 3 type systems:
26 *
27 * * Stack-copy type system: This is the core type system which can
28 * represent all supported types and into which all other type systems
29 * can be nested. This type system requires that every type is
30 * statically or dynamically declared and then registered, thus giving
31 * tracers a complete description of the events and their associated
32 * fields before the associated instrumentation is invoked. The
33 * application needs to copy each argument (side_arg_...()) onto the
34 * stack when calling the instrumentation.
35 *
36 * This is the most expressive of the 3 type systems, althrough not the
37 * fastest due to the extra copy of the arguments.
38 *
39 * * Data-gathering type system: This type system requires every type to
40 * be statically or dynamically declared and registered, but does not
41 * require the application to copy its arguments onto the stack.
42 * Instead, the type description contains all the required information
43 * to fetch the data from the application memory. The only argument
44 * required from the instrumentation is the base pointer from which
45 * the data should be fetched.
46 *
47 * This type system can be used as an event field, or nested within
48 * the stack-copy type system. Nesting of gather-vla within
49 * gather-array and gather-vla types is not allowed.
50 *
51 * This type system is has the least overhead of the 3 type systems.
52 *
53 * * Dynamic type system: This type system receives both type
54 * description and actual data onto the stack at runtime. It has more
55 * overhead that the 2 other type systems, but does not require a
56 * prior registration of event field description. This makes it useful
57 * for seldom used types which are not performance critical, but for
58 * which registering each individual events would needlessly grow the
59 * number of events to declare and register.
60 *
61 * Another use-case for this type system is for use by dynamically
62 * typed language runtimes, where the field type is only known when
63 * the instrumentation is called.
64 *
65 * Those dynamic types can be either used as arguments to a variadic
66 * field list, or as on-stack instrumentation argument for a static
67 * type SIDE_TYPE_DYNAMIC place holder in the stack-copy type system.
68 */
69
70 //TODO: as those structures will be ABI, we need to either consider them
71 //fixed forever, or think of a scheme that would allow their binary
72 //representation to be extended if need be.
73
74 struct side_arg;
75 struct side_arg_vec;
76 union side_arg_dynamic;
77 struct side_arg_dynamic_field;
78 struct side_arg_dynamic_vla;
79 struct side_type;
80 struct side_event_field;
81 struct side_tracer_visitor_ctx;
82 struct side_tracer_dynamic_struct_visitor_ctx;
83 struct side_event_description;
84 struct side_arg_dynamic_struct;
85 struct side_events_register_handle;
86 struct side_arg_variant;
87
88 enum side_type_label {
89 /* Stack-copy basic types */
90 SIDE_TYPE_NULL,
91 SIDE_TYPE_BOOL,
92 SIDE_TYPE_U8,
93 SIDE_TYPE_U16,
94 SIDE_TYPE_U32,
95 SIDE_TYPE_U64,
96 SIDE_TYPE_S8,
97 SIDE_TYPE_S16,
98 SIDE_TYPE_S32,
99 SIDE_TYPE_S64,
100 SIDE_TYPE_BYTE,
101 SIDE_TYPE_POINTER,
102 SIDE_TYPE_FLOAT_BINARY16,
103 SIDE_TYPE_FLOAT_BINARY32,
104 SIDE_TYPE_FLOAT_BINARY64,
105 SIDE_TYPE_FLOAT_BINARY128,
106 SIDE_TYPE_STRING_UTF8,
107 SIDE_TYPE_STRING_UTF16,
108 SIDE_TYPE_STRING_UTF32,
109
110 /* Stack-copy compound types */
111 SIDE_TYPE_STRUCT,
112 SIDE_TYPE_VARIANT,
113 SIDE_TYPE_ARRAY,
114 SIDE_TYPE_VLA,
115 SIDE_TYPE_VLA_VISITOR,
116
117 /* Stack-copy enumeration types */
118 SIDE_TYPE_ENUM,
119 SIDE_TYPE_ENUM_BITMAP,
120
121 /* Stack-copy place holder for dynamic types */
122 SIDE_TYPE_DYNAMIC,
123
124 /* Gather basic types */
125 SIDE_TYPE_GATHER_BOOL,
126 SIDE_TYPE_GATHER_INTEGER,
127 SIDE_TYPE_GATHER_BYTE,
128 SIDE_TYPE_GATHER_POINTER,
129 SIDE_TYPE_GATHER_FLOAT,
130 SIDE_TYPE_GATHER_STRING,
131
132 /* Gather compound types */
133 SIDE_TYPE_GATHER_STRUCT,
134 SIDE_TYPE_GATHER_ARRAY,
135 SIDE_TYPE_GATHER_VLA,
136
137 /* Gather enumeration types */
138 SIDE_TYPE_GATHER_ENUM,
139
140 /* Dynamic basic types */
141 SIDE_TYPE_DYNAMIC_NULL,
142 SIDE_TYPE_DYNAMIC_BOOL,
143 SIDE_TYPE_DYNAMIC_INTEGER,
144 SIDE_TYPE_DYNAMIC_BYTE,
145 SIDE_TYPE_DYNAMIC_POINTER,
146 SIDE_TYPE_DYNAMIC_FLOAT,
147 SIDE_TYPE_DYNAMIC_STRING,
148
149 /* Dynamic compound types */
150 SIDE_TYPE_DYNAMIC_STRUCT,
151 SIDE_TYPE_DYNAMIC_STRUCT_VISITOR,
152 SIDE_TYPE_DYNAMIC_VLA,
153 SIDE_TYPE_DYNAMIC_VLA_VISITOR,
154 };
155
156 enum side_attr_type {
157 SIDE_ATTR_TYPE_NULL,
158 SIDE_ATTR_TYPE_BOOL,
159 SIDE_ATTR_TYPE_U8,
160 SIDE_ATTR_TYPE_U16,
161 SIDE_ATTR_TYPE_U32,
162 SIDE_ATTR_TYPE_U64,
163 SIDE_ATTR_TYPE_S8,
164 SIDE_ATTR_TYPE_S16,
165 SIDE_ATTR_TYPE_S32,
166 SIDE_ATTR_TYPE_S64,
167 SIDE_ATTR_TYPE_FLOAT_BINARY16,
168 SIDE_ATTR_TYPE_FLOAT_BINARY32,
169 SIDE_ATTR_TYPE_FLOAT_BINARY64,
170 SIDE_ATTR_TYPE_FLOAT_BINARY128,
171 SIDE_ATTR_TYPE_STRING,
172 };
173
174 enum side_loglevel {
175 SIDE_LOGLEVEL_EMERG = 0,
176 SIDE_LOGLEVEL_ALERT = 1,
177 SIDE_LOGLEVEL_CRIT = 2,
178 SIDE_LOGLEVEL_ERR = 3,
179 SIDE_LOGLEVEL_WARNING = 4,
180 SIDE_LOGLEVEL_NOTICE = 5,
181 SIDE_LOGLEVEL_INFO = 6,
182 SIDE_LOGLEVEL_DEBUG = 7,
183 };
184
185 enum side_visitor_status {
186 SIDE_VISITOR_STATUS_OK = 0,
187 SIDE_VISITOR_STATUS_ERROR = -1,
188 };
189
190 //TODO: side_error enum is currently unused.
191 enum side_error {
192 SIDE_ERROR_OK = 0,
193 SIDE_ERROR_INVAL = 1,
194 SIDE_ERROR_EXIST = 2,
195 SIDE_ERROR_NOMEM = 3,
196 SIDE_ERROR_NOENT = 4,
197 SIDE_ERROR_EXITING = 5,
198 };
199
200 enum side_type_label_byte_order {
201 SIDE_TYPE_BYTE_ORDER_LE = 0,
202 SIDE_TYPE_BYTE_ORDER_BE = 1,
203 };
204
205 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
206 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
207 #else
208 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
209 #endif
210
211 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
212 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
213 #else
214 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
215 #endif
216
217 enum side_type_gather_access_mode {
218 SIDE_TYPE_GATHER_ACCESS_DIRECT,
219 SIDE_TYPE_GATHER_ACCESS_POINTER, /* Pointer dereference */
220 };
221
222 typedef enum side_visitor_status (*side_visitor_func)(
223 const struct side_tracer_visitor_ctx *tracer_ctx,
224 void *app_ctx);
225 typedef enum side_visitor_status (*side_dynamic_struct_visitor_func)(
226 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
227 void *app_ctx);
228
229 union side_integer_value {
230 uint8_t side_u8;
231 uint16_t side_u16;
232 uint32_t side_u32;
233 uint64_t side_u64;
234 int8_t side_s8;
235 int16_t side_s16;
236 int32_t side_s32;
237 int64_t side_s64;
238 uintptr_t side_uptr;
239 } SIDE_PACKED;
240
241 union side_bool_value {
242 uint8_t side_bool8;
243 uint16_t side_bool16;
244 uint32_t side_bool32;
245 uint64_t side_bool64;
246 } SIDE_PACKED;
247
248 union side_float_value {
249 #if __HAVE_FLOAT16
250 _Float16 side_float_binary16;
251 #endif
252 #if __HAVE_FLOAT32
253 _Float32 side_float_binary32;
254 #endif
255 #if __HAVE_FLOAT64
256 _Float64 side_float_binary64;
257 #endif
258 #if __HAVE_FLOAT128
259 _Float128 side_float_binary128;
260 #endif
261 } SIDE_PACKED;
262
263 struct side_type_raw_string {
264 side_ptr_t(const void) p; /* pointer to string */
265 uint8_t unit_size; /* 1, 2, or 4 bytes */
266 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
267 } SIDE_PACKED;
268
269 struct side_attr_value {
270 side_enum_t(enum side_attr_type, uint32_t) type;
271 union {
272 uint8_t bool_value;
273 struct side_type_raw_string string_value;
274 union side_integer_value integer_value;
275 union side_float_value float_value;
276 } SIDE_PACKED u;
277 };
278
279 /* User attributes. */
280 struct side_attr {
281 const struct side_type_raw_string key;
282 const struct side_attr_value value;
283 } SIDE_PACKED;
284
285 /* Type descriptions */
286 struct side_type_null {
287 side_ptr_t(const struct side_attr) attr;
288 uint32_t nr_attr;
289 } SIDE_PACKED;
290
291 struct side_type_bool {
292 side_ptr_t(const struct side_attr) attr;
293 uint32_t nr_attr;
294 uint16_t bool_size; /* bytes */
295 uint16_t len_bits; /* bits. 0 for (bool_size * CHAR_BITS) */
296 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
297 } SIDE_PACKED;
298
299 struct side_type_byte {
300 side_ptr_t(const struct side_attr) attr;
301 uint32_t nr_attr;
302 } SIDE_PACKED;
303
304 struct side_type_string {
305 side_ptr_t(const struct side_attr) attr;
306 uint32_t nr_attr;
307 uint8_t unit_size; /* 1, 2, or 4 bytes */
308 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
309 } SIDE_PACKED;
310
311 struct side_type_integer {
312 side_ptr_t(const struct side_attr) attr;
313 uint32_t nr_attr;
314 uint16_t integer_size; /* bytes */
315 uint16_t len_bits; /* bits. 0 for (integer_size * CHAR_BITS) */
316 uint8_t signedness; /* true/false */
317 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
318 } SIDE_PACKED;
319
320 struct side_type_float {
321 side_ptr_t(const struct side_attr) attr;
322 uint32_t nr_attr;
323 uint16_t float_size; /* bytes */
324 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
325 } SIDE_PACKED;
326
327 struct side_enum_mapping {
328 int64_t range_begin;
329 int64_t range_end;
330 struct side_type_raw_string label;
331 } SIDE_PACKED;
332
333 struct side_enum_mappings {
334 side_ptr_t(const struct side_enum_mapping) mappings;
335 side_ptr_t(const struct side_attr) attr;
336 uint32_t nr_mappings;
337 uint32_t nr_attr;
338 } SIDE_PACKED;
339
340 struct side_enum_bitmap_mapping {
341 uint64_t range_begin;
342 uint64_t range_end;
343 struct side_type_raw_string label;
344 } SIDE_PACKED;
345
346 struct side_enum_bitmap_mappings {
347 side_ptr_t(const struct side_enum_bitmap_mapping) mappings;
348 side_ptr_t(const struct side_attr) attr;
349 uint32_t nr_mappings;
350 uint32_t nr_attr;
351 } SIDE_PACKED;
352
353 struct side_type_struct {
354 side_ptr_t(const struct side_event_field) fields;
355 side_ptr_t(const struct side_attr) attr;
356 uint32_t nr_fields;
357 uint32_t nr_attr;
358 } SIDE_PACKED;
359
360 struct side_type_array {
361 side_ptr_t(const struct side_type) elem_type;
362 side_ptr_t(const struct side_attr) attr;
363 uint32_t length;
364 uint32_t nr_attr;
365 } SIDE_PACKED;
366
367 struct side_type_vla {
368 side_ptr_t(const struct side_type) elem_type;
369 side_ptr_t(const struct side_attr) attr;
370 uint32_t nr_attr;
371 } SIDE_PACKED;
372
373 struct side_type_vla_visitor {
374 side_ptr_t(const struct side_type) elem_type;
375 side_visitor_func visitor;
376 side_ptr_t(const struct side_attr) attr;
377 uint32_t nr_attr;
378 } SIDE_PACKED;
379
380 struct side_type_enum {
381 side_ptr_t(const struct side_enum_mappings) mappings;
382 side_ptr_t(const struct side_type) elem_type;
383 } SIDE_PACKED;
384
385 struct side_type_enum_bitmap {
386 side_ptr_t(const struct side_enum_bitmap_mappings) mappings;
387 side_ptr_t(const struct side_type) elem_type;
388 } SIDE_PACKED;
389
390 struct side_type_gather_bool {
391 uint64_t offset; /* bytes */
392 uint8_t access_mode; /* enum side_type_gather_access_mode */
393 struct side_type_bool type;
394 uint16_t offset_bits; /* bits */
395 } SIDE_PACKED;
396
397 struct side_type_gather_byte {
398 uint64_t offset; /* bytes */
399 uint8_t access_mode; /* enum side_type_gather_access_mode */
400 struct side_type_byte type;
401 } SIDE_PACKED;
402
403 struct side_type_gather_integer {
404 uint64_t offset; /* bytes */
405 uint8_t access_mode; /* enum side_type_gather_access_mode */
406 struct side_type_integer type;
407 uint16_t offset_bits; /* bits */
408 } SIDE_PACKED;
409
410 struct side_type_gather_float {
411 uint64_t offset; /* bytes */
412 uint8_t access_mode; /* enum side_type_gather_access_mode */
413 struct side_type_float type;
414 } SIDE_PACKED;
415
416 struct side_type_gather_string {
417 uint64_t offset; /* bytes */
418 uint8_t access_mode; /* enum side_type_gather_access_mode */
419 struct side_type_string type;
420 } SIDE_PACKED;
421
422 struct side_type_gather_enum {
423 side_ptr_t(const struct side_enum_mappings) mappings;
424 side_ptr_t(const struct side_type) elem_type;
425 } SIDE_PACKED;
426
427 struct side_type_gather_struct {
428 uint64_t offset; /* bytes */
429 uint8_t access_mode; /* enum side_type_gather_access_mode */
430 side_ptr_t(const struct side_type_struct) type;
431 uint32_t size; /* bytes */
432 } SIDE_PACKED;
433
434 struct side_type_gather_array {
435 uint64_t offset; /* bytes */
436 uint8_t access_mode; /* enum side_type_gather_access_mode */
437 struct side_type_array type;
438 } SIDE_PACKED;
439
440 struct side_type_gather_vla {
441 side_ptr_t(const struct side_type) length_type; /* side_length() */
442
443 uint64_t offset; /* bytes */
444 uint8_t access_mode; /* enum side_type_gather_access_mode */
445 struct side_type_vla type;
446 } SIDE_PACKED;
447
448 struct side_type_gather {
449 union {
450 struct side_type_gather_bool side_bool;
451 struct side_type_gather_byte side_byte;
452 struct side_type_gather_integer side_integer;
453 struct side_type_gather_float side_float;
454 struct side_type_gather_string side_string;
455 struct side_type_gather_enum side_enum;
456 struct side_type_gather_array side_array;
457 struct side_type_gather_vla side_vla;
458 struct side_type_gather_struct side_struct;
459 } SIDE_PACKED u;
460 } SIDE_PACKED;
461
462 struct side_type {
463 side_enum_t(enum side_type_label, uint32_t) type;
464 union {
465 /* Stack-copy basic types */
466 struct side_type_null side_null;
467 struct side_type_bool side_bool;
468 struct side_type_byte side_byte;
469 struct side_type_string side_string;
470 struct side_type_integer side_integer;
471 struct side_type_float side_float;
472
473 /* Stack-copy compound types */
474 struct side_type_array side_array;
475 struct side_type_vla side_vla;
476 struct side_type_vla_visitor side_vla_visitor;
477 side_ptr_t(const struct side_type_struct) side_struct;
478 side_ptr_t(const struct side_type_variant) side_variant;
479
480 /* Stack-copy enumeration types */
481 struct side_type_enum side_enum;
482 struct side_type_enum_bitmap side_enum_bitmap;
483
484 /* Gather types */
485 struct side_type_gather side_gather;
486 } SIDE_PACKED u;
487 } SIDE_PACKED;
488
489 struct side_variant_option {
490 int64_t range_begin;
491 int64_t range_end;
492 const struct side_type side_type;
493 } SIDE_PACKED;
494
495 struct side_type_variant {
496 const struct side_type selector;
497 side_ptr_t(const struct side_variant_option) options;
498 side_ptr_t(const struct side_attr) attr;
499 uint32_t nr_options;
500 uint32_t nr_attr;
501 } SIDE_PACKED;
502
503 struct side_event_field {
504 side_ptr_t(const char) field_name;
505 struct side_type side_type;
506 } SIDE_PACKED;
507
508 enum side_event_flags {
509 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
510 };
511
512 struct side_callback {
513 union {
514 void (*call)(const struct side_event_description *desc,
515 const struct side_arg_vec *side_arg_vec,
516 void *priv);
517 void (*call_variadic)(const struct side_event_description *desc,
518 const struct side_arg_vec *side_arg_vec,
519 const struct side_arg_dynamic_struct *var_struct,
520 void *priv);
521 } SIDE_PACKED u;
522 void *priv;
523 } SIDE_PACKED;
524
525 union side_arg_static {
526 /* Stack-copy basic types */
527 union side_bool_value bool_value;
528 uint8_t byte_value;
529 side_ptr_t(const void) string_value; /* const {uint8_t, uint16_t, uint32_t} * */
530 union side_integer_value integer_value;
531 union side_float_value float_value;
532
533 /* Stack-copy compound types */
534 side_ptr_t(const struct side_arg_vec) side_struct;
535 side_ptr_t(const struct side_arg_variant) side_variant;
536 side_ptr_t(const struct side_arg_vec) side_array;
537 side_ptr_t(const struct side_arg_vec) side_vla;
538 void *side_vla_app_visitor_ctx;
539
540 /* Gather basic types */
541 side_ptr_t(const void) side_bool_gather_ptr;
542 side_ptr_t(const void) side_byte_gather_ptr;
543 side_ptr_t(const void) side_integer_gather_ptr;
544 side_ptr_t(const void) side_float_gather_ptr;
545 side_ptr_t(const void) side_string_gather_ptr;
546
547 /* Gather compound types */
548 side_ptr_t(const void) side_array_gather_ptr;
549 side_ptr_t(const void) side_struct_gather_ptr;
550 struct {
551 side_ptr_t(const void) ptr;
552 side_ptr_t(const void) length_ptr;
553 } SIDE_PACKED side_vla_gather;
554 } SIDE_PACKED;
555
556 struct side_arg_dynamic_vla {
557 side_ptr_t(const struct side_arg) sav;
558 side_ptr_t(const struct side_attr) attr;
559 uint32_t len;
560 uint32_t nr_attr;
561 } SIDE_PACKED;
562
563 struct side_arg_dynamic_struct {
564 side_ptr_t(const struct side_arg_dynamic_field) fields;
565 side_ptr_t(const struct side_attr) attr;
566 uint32_t len;
567 uint32_t nr_attr;
568 } SIDE_PACKED;
569
570 struct side_dynamic_struct_visitor {
571 void *app_ctx;
572 side_dynamic_struct_visitor_func visitor;
573 side_ptr_t(const struct side_attr) attr;
574 uint32_t nr_attr;
575 } SIDE_PACKED;
576
577 struct side_dynamic_vla_visitor {
578 void *app_ctx;
579 side_visitor_func visitor;
580 side_ptr_t(const struct side_attr) attr;
581 uint32_t nr_attr;
582 } SIDE_PACKED;
583
584 union side_arg_dynamic {
585 /* Dynamic basic types */
586 struct side_type_null side_null;
587 struct {
588 struct side_type_bool type;
589 union side_bool_value value;
590 } SIDE_PACKED side_bool;
591 struct {
592 struct side_type_byte type;
593 uint8_t value;
594 } SIDE_PACKED side_byte;
595 struct {
596 struct side_type_string type;
597 uint64_t value; /* const char * */
598 } SIDE_PACKED side_string;
599 struct {
600 struct side_type_integer type;
601 union side_integer_value value;
602 } SIDE_PACKED side_integer;
603 struct {
604 struct side_type_float type;
605 union side_float_value value;
606 } SIDE_PACKED side_float;
607
608 /* Dynamic compound types */
609 side_ptr_t(const struct side_arg_dynamic_struct) side_dynamic_struct;
610 side_ptr_t(const struct side_arg_dynamic_vla) side_dynamic_vla;
611
612 struct side_dynamic_struct_visitor side_dynamic_struct_visitor;
613 struct side_dynamic_vla_visitor side_dynamic_vla_visitor;
614 } SIDE_PACKED;
615
616 struct side_arg {
617 side_enum_t(enum side_type_label, uint32_t) type;
618 union {
619 union side_arg_static side_static;
620 union side_arg_dynamic side_dynamic;
621 } SIDE_PACKED u;
622 } SIDE_PACKED;
623
624 struct side_arg_variant {
625 struct side_arg selector;
626 struct side_arg option;
627 } SIDE_PACKED;
628
629 struct side_arg_vec {
630 side_ptr_t(const struct side_arg) sav;
631 uint32_t len;
632 } SIDE_PACKED;
633
634 struct side_arg_dynamic_field {
635 side_ptr_t(const char) field_name;
636 const struct side_arg elem;
637 } SIDE_PACKED;
638
639 /* The visitor pattern is a double-dispatch visitor. */
640 struct side_tracer_visitor_ctx {
641 enum side_visitor_status (*write_elem)(
642 const struct side_tracer_visitor_ctx *tracer_ctx,
643 const struct side_arg *elem);
644 void *priv; /* Private tracer context. */
645 } SIDE_PACKED;
646
647 struct side_tracer_dynamic_struct_visitor_ctx {
648 enum side_visitor_status (*write_field)(
649 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
650 const struct side_arg_dynamic_field *dynamic_field);
651 void *priv; /* Private tracer context. */
652 } SIDE_PACKED;
653
654 /*
655 * This structure is _not_ packed to allow atomic operations on its
656 * fields.
657 */
658 struct side_event_state {
659 uintptr_t enabled;
660 const struct side_callback *callbacks;
661 uint32_t nr_callbacks;
662 };
663
664 struct side_event_description {
665 side_ptr_t(struct side_event_state) state;
666 side_ptr_t(const char) provider_name;
667 side_ptr_t(const char) event_name;
668 side_ptr_t(const struct side_event_field) fields;
669 side_ptr_t(const struct side_attr) attr;
670 uint64_t flags;
671 uint32_t version;
672 side_enum_t(enum side_loglevel, uint32_t) loglevel;
673 uint32_t nr_fields;
674 uint32_t nr_attr;
675 } SIDE_PACKED;
676
677 /* Event and type attributes */
678
679 #define side_attr(_key, _value) \
680 { \
681 .key = { \
682 .p = SIDE_PTR_INIT(_key), \
683 .unit_size = sizeof(uint8_t), \
684 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
685 }, \
686 .value = SIDE_PARAM(_value), \
687 }
688
689 #define side_attr_list(...) \
690 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
691
692 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
693 #define side_attr_bool(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_BOOL), .u = { .bool_value = !!(_val) } }
694 #define side_attr_u8(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U8), .u = { .integer_value = { .side_u8 = (_val) } } }
695 #define side_attr_u16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U16), .u = { .integer_value = { .side_u16 = (_val) } } }
696 #define side_attr_u32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U32), .u = { .integer_value = { .side_u32 = (_val) } } }
697 #define side_attr_u64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U64), .u = { .integer_value = { .side_u64 = (_val) } } }
698 #define side_attr_s8(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S8), .u = { .integer_value = { .side_s8 = (_val) } } }
699 #define side_attr_s16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S16), .u = { .integer_value = { .side_s16 = (_val) } } }
700 #define side_attr_s32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S32), .u = { .integer_value = { .side_s32 = (_val) } } }
701 #define side_attr_s64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S64), .u = { .integer_value = { .side_s64 = (_val) } } }
702 #define side_attr_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY16), .u = { .float_value = { .side_float_binary16 = (_val) } } }
703 #define side_attr_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY32), .u = { .float_value = { .side_float_binary32 = (_val) } } }
704 #define side_attr_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY64), .u = { .float_value = { .side_float_binary64 = (_val) } } }
705 #define side_attr_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY128), .u = { .float_value = { .side_float_binary128 = (_val) } } }
706
707 #define _side_attr_string(_val, _byte_order, _unit_size) \
708 { \
709 .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_STRING), \
710 .u = { \
711 .string_value = { \
712 .p = SIDE_PTR_INIT(_val), \
713 .unit_size = _unit_size, \
714 .byte_order = SIDE_ENUM_INIT(_byte_order), \
715 }, \
716 }, \
717 }
718
719 #define side_attr_string(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t))
720 #define side_attr_string16(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t))
721 #define side_attr_string32(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t))
722
723 /* Stack-copy enumeration type definitions */
724
725 #define side_define_enum(_identifier, _mappings, _attr...) \
726 const struct side_enum_mappings _identifier = { \
727 .mappings = SIDE_PTR_INIT(_mappings), \
728 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
729 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
730 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
731 }
732
733 #define side_enum_mapping_list(...) \
734 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
735
736 #define side_enum_mapping_range(_label, _begin, _end) \
737 { \
738 .range_begin = _begin, \
739 .range_end = _end, \
740 .label = { \
741 .p = SIDE_PTR_INIT(_label), \
742 .unit_size = sizeof(uint8_t), \
743 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
744 }, \
745 }
746
747 #define side_enum_mapping_value(_label, _value) \
748 { \
749 .range_begin = _value, \
750 .range_end = _value, \
751 .label = { \
752 .p = SIDE_PTR_INIT(_label), \
753 .unit_size = sizeof(uint8_t), \
754 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
755 }, \
756 }
757
758 #define side_define_enum_bitmap(_identifier, _mappings, _attr...) \
759 const struct side_enum_bitmap_mappings _identifier = { \
760 .mappings = SIDE_PTR_INIT(_mappings), \
761 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
762 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
763 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
764 }
765
766 #define side_enum_bitmap_mapping_list(...) \
767 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
768
769 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
770 { \
771 .range_begin = _begin, \
772 .range_end = _end, \
773 .label = { \
774 .p = SIDE_PTR_INIT(_label), \
775 .unit_size = sizeof(uint8_t), \
776 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
777 }, \
778 }
779
780 #define side_enum_bitmap_mapping_value(_label, _value) \
781 { \
782 .range_begin = _value, \
783 .range_end = _value, \
784 .label = { \
785 .p = SIDE_PTR_INIT(_label), \
786 .unit_size = sizeof(uint8_t), \
787 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
788 }, \
789 }
790
791 /* Stack-copy field and type definitions */
792
793 #define side_type_null(_attr...) \
794 { \
795 .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL), \
796 .u = { \
797 .side_null = { \
798 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
799 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
800 }, \
801 }, \
802 }
803
804 #define side_type_bool(_attr...) \
805 { \
806 .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), \
807 .u = { \
808 .side_bool = { \
809 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
810 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
811 .bool_size = sizeof(uint8_t), \
812 .len_bits = 0, \
813 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
814 }, \
815 }, \
816 }
817
818 #define side_type_byte(_attr...) \
819 { \
820 .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), \
821 .u = { \
822 .side_byte = { \
823 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
824 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
825 }, \
826 }, \
827 }
828
829 #define _side_type_string(_type, _byte_order, _unit_size, _attr) \
830 { \
831 .type = SIDE_ENUM_INIT(_type), \
832 .u = { \
833 .side_string = { \
834 .attr = SIDE_PTR_INIT(_attr), \
835 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
836 .unit_size = _unit_size, \
837 .byte_order = SIDE_ENUM_INIT(_byte_order), \
838 }, \
839 }, \
840 }
841
842 #define side_type_dynamic() \
843 { \
844 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC), \
845 }
846
847 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
848 { \
849 .type = SIDE_ENUM_INIT(_type), \
850 .u = { \
851 .side_integer = { \
852 .attr = SIDE_PTR_INIT(_attr), \
853 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
854 .integer_size = _integer_size, \
855 .len_bits = _len_bits, \
856 .signedness = _signedness, \
857 .byte_order = SIDE_ENUM_INIT(_byte_order), \
858 }, \
859 }, \
860 }
861
862 #define _side_type_float(_type, _byte_order, _float_size, _attr) \
863 { \
864 .type = SIDE_ENUM_INIT(_type), \
865 .u = { \
866 .side_float = { \
867 .attr = SIDE_PTR_INIT(_attr), \
868 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
869 .float_size = _float_size, \
870 .byte_order = SIDE_ENUM_INIT(_byte_order), \
871 }, \
872 }, \
873 }
874
875 #define _side_field(_name, _type) \
876 { \
877 .field_name = SIDE_PTR_INIT(_name), \
878 .side_type = _type, \
879 }
880
881 #define side_option_range(_range_begin, _range_end, _type) \
882 { \
883 .range_begin = _range_begin, \
884 .range_end = _range_end, \
885 .side_type = _type, \
886 }
887
888 #define side_option(_value, _type) \
889 side_option_range(_value, _value, SIDE_PARAM(_type))
890
891 /* Host endian */
892 #define side_type_u8(_attr...) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
893 #define side_type_u16(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
894 #define side_type_u32(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
895 #define side_type_u64(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
896 #define side_type_s8(_attr...) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
897 #define side_type_s16(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
898 #define side_type_s32(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
899 #define side_type_s64(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
900 #define side_type_pointer(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
901 #define side_type_float_binary16(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
902 #define side_type_float_binary32(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
903 #define side_type_float_binary64(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
904 #define side_type_float_binary128(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
905 #define side_type_string(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF8, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
906 #define side_type_string16(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
907 #define side_type_string32(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
908
909 #define side_field_null(_name, _attr...) _side_field(_name, side_type_null(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
910 #define side_field_bool(_name, _attr...) _side_field(_name, side_type_bool(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
911 #define side_field_u8(_name, _attr...) _side_field(_name, side_type_u8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
912 #define side_field_u16(_name, _attr...) _side_field(_name, side_type_u16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
913 #define side_field_u32(_name, _attr...) _side_field(_name, side_type_u32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
914 #define side_field_u64(_name, _attr...) _side_field(_name, side_type_u64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
915 #define side_field_s8(_name, _attr...) _side_field(_name, side_type_s8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
916 #define side_field_s16(_name, _attr...) _side_field(_name, side_type_s16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
917 #define side_field_s32(_name, _attr...) _side_field(_name, side_type_s32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
918 #define side_field_s64(_name, _attr...) _side_field(_name, side_type_s64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
919 #define side_field_byte(_name, _attr...) _side_field(_name, side_type_byte(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
920 #define side_field_pointer(_name, _attr...) _side_field(_name, side_type_pointer(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
921 #define side_field_float_binary16(_name, _attr...) _side_field(_name, side_type_float_binary16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
922 #define side_field_float_binary32(_name, _attr...) _side_field(_name, side_type_float_binary32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
923 #define side_field_float_binary64(_name, _attr...) _side_field(_name, side_type_float_binary64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
924 #define side_field_float_binary128(_name, _attr...) _side_field(_name, side_type_float_binary128(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
925 #define side_field_string(_name, _attr...) _side_field(_name, side_type_string(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
926 #define side_field_string16(_name, _attr...) _side_field(_name, side_type_string16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
927 #define side_field_string32(_name, _attr...) _side_field(_name, side_type_string32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
928 #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic())
929
930 /* Little endian */
931 #define side_type_u16_le(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
932 #define side_type_u32_le(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
933 #define side_type_u64_le(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
934 #define side_type_s16_le(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
935 #define side_type_s32_le(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
936 #define side_type_s64_le(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
937 #define side_type_pointer_le(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
938 #define side_type_float_binary16_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
939 #define side_type_float_binary32_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
940 #define side_type_float_binary64_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
941 #define side_type_float_binary128_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
942 #define side_type_string16_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
943 #define side_type_string32_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
944
945 #define side_field_u16_le(_name, _attr...) _side_field(_name, side_type_u16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
946 #define side_field_u32_le(_name, _attr...) _side_field(_name, side_type_u32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
947 #define side_field_u64_le(_name, _attr...) _side_field(_name, side_type_u64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
948 #define side_field_s16_le(_name, _attr...) _side_field(_name, side_type_s16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
949 #define side_field_s32_le(_name, _attr...) _side_field(_name, side_type_s32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
950 #define side_field_s64_le(_name, _attr...) _side_field(_name, side_type_s64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
951 #define side_field_pointer_le(_name, _attr...) _side_field(_name, side_type_pointer_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
952 #define side_field_float_binary16_le(_name, _attr...) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
953 #define side_field_float_binary32_le(_name, _attr...) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
954 #define side_field_float_binary64_le(_name, _attr...) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
955 #define side_field_float_binary128_le(_name, _attr...) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
956 #define side_field_string16_le(_name, _attr...) _side_field(_name, side_type_string16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
957 #define side_field_string32_le(_name, _attr...) _side_field(_name, side_type_string32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
958
959 /* Big endian */
960 #define side_type_u16_be(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
961 #define side_type_u32_be(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
962 #define side_type_u64_be(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
963 #define side_type_s16_be(_attr...) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
964 #define side_type_s32_be(_attr...) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
965 #define side_type_s64_be(_attr...) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
966 #define side_type_pointer_be(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
967 #define side_type_float_binary16_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
968 #define side_type_float_binary32_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
969 #define side_type_float_binary64_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
970 #define side_type_float_binary128_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
971 #define side_type_string16_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
972 #define side_type_string32_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
973
974 #define side_field_u16_be(_name, _attr...) _side_field(_name, side_type_u16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
975 #define side_field_u32_be(_name, _attr...) _side_field(_name, side_type_u32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
976 #define side_field_u64_be(_name, _attr...) _side_field(_name, side_type_u64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
977 #define side_field_s16_be(_name, _attr...) _side_field(_name, side_type_s16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
978 #define side_field_s32_be(_name, _attr...) _side_field(_name, side_type_s32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
979 #define side_field_s64_be(_name, _attr...) _side_field(_name, side_type_s64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
980 #define side_field_pointer_be(_name, _attr...) _side_field(_name, side_type_pointer_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
981 #define side_field_float_binary16_be(_name, _attr...) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
982 #define side_field_float_binary32_be(_name, _attr...) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
983 #define side_field_float_binary64_be(_name, _attr...) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
984 #define side_field_float_binary128_be(_name, _attr...) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
985 #define side_field_string16_be(_name, _attr...) _side_field(_name, side_type_string16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
986 #define side_field_string32_be(_name, _attr...) _side_field(_name, side_type_string32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
987
988 #define side_type_enum(_mappings, _elem_type) \
989 { \
990 .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM), \
991 .u = { \
992 .side_enum = { \
993 .mappings = SIDE_PTR_INIT(_mappings), \
994 .elem_type = SIDE_PTR_INIT(_elem_type), \
995 }, \
996 }, \
997 }
998 #define side_field_enum(_name, _mappings, _elem_type) \
999 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1000
1001 #define side_type_enum_bitmap(_mappings, _elem_type) \
1002 { \
1003 .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM_BITMAP), \
1004 .u = { \
1005 .side_enum_bitmap = { \
1006 .mappings = SIDE_PTR_INIT(_mappings), \
1007 .elem_type = SIDE_PTR_INIT(_elem_type), \
1008 }, \
1009 }, \
1010 }
1011 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
1012 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1013
1014 #define side_type_struct(_struct) \
1015 { \
1016 .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), \
1017 .u = { \
1018 .side_struct = SIDE_PTR_INIT(_struct), \
1019 }, \
1020 }
1021 #define side_field_struct(_name, _struct) \
1022 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
1023
1024 #define _side_type_struct_define(_fields, _attr) \
1025 { \
1026 .fields = SIDE_PTR_INIT(_fields), \
1027 .attr = SIDE_PTR_INIT(_attr), \
1028 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1029 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1030 }
1031
1032 #define side_define_struct(_identifier, _fields, _attr...) \
1033 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1034
1035 #define side_struct_literal(_fields, _attr...) \
1036 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
1037 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1038
1039 #define side_type_variant(_variant) \
1040 { \
1041 .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \
1042 .u = { \
1043 .side_variant = SIDE_PTR_INIT(_variant), \
1044 }, \
1045 }
1046 #define side_field_variant(_name, _variant) \
1047 _side_field(_name, side_type_variant(SIDE_PARAM(_variant)))
1048
1049 #define _side_type_variant_define(_selector, _options, _attr) \
1050 { \
1051 .selector = _selector, \
1052 .options = SIDE_PTR_INIT(_options), \
1053 .attr = SIDE_PTR_INIT(_attr), \
1054 .nr_options = SIDE_ARRAY_SIZE(SIDE_PARAM(_options)), \
1055 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1056 }
1057
1058 #define side_define_variant(_identifier, _selector, _options, _attr...) \
1059 const struct side_type_variant _identifier = \
1060 _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1061
1062 #define side_variant_literal(_selector, _options, _attr...) \
1063 SIDE_COMPOUND_LITERAL(const struct side_type_variant, \
1064 _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1065
1066 #define side_type_array(_elem_type, _length, _attr...) \
1067 { \
1068 .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), \
1069 .u = { \
1070 .side_array = { \
1071 .elem_type = SIDE_PTR_INIT(_elem_type), \
1072 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1073 .length = _length, \
1074 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1075 }, \
1076 }, \
1077 }
1078 #define side_field_array(_name, _elem_type, _length, _attr...) \
1079 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1080
1081 #define side_type_vla(_elem_type, _attr...) \
1082 { \
1083 .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), \
1084 .u = { \
1085 .side_vla = { \
1086 .elem_type = SIDE_PTR_INIT(_elem_type), \
1087 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1088 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1089 }, \
1090 }, \
1091 }
1092 #define side_field_vla(_name, _elem_type, _attr...) \
1093 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1094
1095 #define side_type_vla_visitor(_elem_type, _visitor, _attr...) \
1096 { \
1097 .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), \
1098 .u = { \
1099 .side_vla_visitor = { \
1100 .elem_type = SIDE_PTR_INIT(_elem_type), \
1101 .visitor = _visitor, \
1102 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1103 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1104 }, \
1105 }, \
1106 }
1107 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr...) \
1108 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1109
1110 /* Gather field and type definitions */
1111
1112 #define side_type_gather_byte(_offset, _access_mode, _attr...) \
1113 { \
1114 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), \
1115 .u = { \
1116 .side_gather = { \
1117 .u = { \
1118 .side_byte = { \
1119 .offset = _offset, \
1120 .access_mode = _access_mode, \
1121 .type = { \
1122 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1123 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1124 }, \
1125 }, \
1126 }, \
1127 }, \
1128 }, \
1129 }
1130 #define side_field_gather_byte(_name, _offset, _access_mode, _attr...) \
1131 _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1132
1133 #define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1134 { \
1135 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), \
1136 .u = { \
1137 .side_gather = { \
1138 .u = { \
1139 .side_bool = { \
1140 .offset = _offset, \
1141 .access_mode = _access_mode, \
1142 .type = { \
1143 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1144 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1145 .bool_size = _bool_size, \
1146 .len_bits = _len_bits, \
1147 .byte_order = SIDE_ENUM_INIT(_byte_order), \
1148 }, \
1149 .offset_bits = _offset_bits, \
1150 }, \
1151 }, \
1152 }, \
1153 }, \
1154 }
1155 #define side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1156 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_HOST, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1157 #define side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1158 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_LE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1159 #define side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1160 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_BE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1161
1162 #define side_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1163 _side_field(_name, side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))))
1164 #define side_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1165 _side_field(_name, side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))))
1166 #define side_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1167 _side_field(_name, side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))))
1168
1169 #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
1170 _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1171 { \
1172 .type = SIDE_ENUM_INIT(_type), \
1173 .u = { \
1174 .side_gather = { \
1175 .u = { \
1176 .side_integer = { \
1177 .offset = _offset, \
1178 .access_mode = _access_mode, \
1179 .type = { \
1180 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1181 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1182 .integer_size = _integer_size, \
1183 .len_bits = _len_bits, \
1184 .signedness = _signedness, \
1185 .byte_order = SIDE_ENUM_INIT(_byte_order), \
1186 }, \
1187 .offset_bits = _offset_bits, \
1188 }, \
1189 }, \
1190 }, \
1191 }, \
1192 }
1193
1194 #define side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1195 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1196 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1197 #define side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1198 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, \
1199 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1200
1201 #define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1202 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_LE, \
1203 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1204 #define side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1205 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_LE, \
1206 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1207
1208 #define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1209 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_BE, \
1210 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1211 #define side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1212 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_BE, \
1213 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1214
1215 #define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1216 _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1217 #define side_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1218 _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1219
1220 #define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1221 _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1222 #define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1223 _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1224
1225 #define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1226 _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1227 #define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1228 _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1229
1230 #define side_type_gather_pointer(_offset, _access_mode, _attr...) \
1231 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1232 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1233 #define side_field_gather_pointer(_name, _offset, _access_mode, _attr...) \
1234 _side_field(_name, side_type_gather_pointer(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1235
1236 #define side_type_gather_pointer_le(_offset, _access_mode, _attr...) \
1237 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, \
1238 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1239 #define side_field_gather_pointer_le(_name, _offset, _access_mode, _attr...) \
1240 _side_field(_name, side_type_gather_pointer_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1241
1242 #define side_type_gather_pointer_be(_offset, _access_mode, _attr...) \
1243 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, \
1244 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1245 #define side_field_gather_pointer_be(_name, _offset, _access_mode, _attr...) \
1246 _side_field(_name, side_type_gather_pointer_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1247
1248 #define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr...) \
1249 { \
1250 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), \
1251 .u = { \
1252 .side_gather = { \
1253 .u = { \
1254 .side_float = { \
1255 .offset = _offset, \
1256 .access_mode = _access_mode, \
1257 .type = { \
1258 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1259 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1260 .float_size = _float_size, \
1261 .byte_order = SIDE_ENUM_INIT(_byte_order), \
1262 }, \
1263 }, \
1264 }, \
1265 }, \
1266 }, \
1267 }
1268
1269 #define side_type_gather_float(_offset, _float_size, _access_mode, _attr...) \
1270 _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1271 #define side_type_gather_float_le(_offset, _float_size, _access_mode, _attr...) \
1272 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1273 #define side_type_gather_float_be(_offset, _float_size, _access_mode, _attr...) \
1274 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1275
1276 #define side_field_gather_float(_name, _offset, _float_size, _access_mode, _attr...) \
1277 _side_field(_name, side_type_gather_float(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1278 #define side_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr...) \
1279 _side_field(_name, side_type_gather_float_le(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1280 #define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr...) \
1281 _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1282
1283 #define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr...) \
1284 { \
1285 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), \
1286 .u = { \
1287 .side_gather = { \
1288 .u = { \
1289 .side_string = { \
1290 .offset = _offset, \
1291 .access_mode = _access_mode, \
1292 .type = { \
1293 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1294 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1295 .unit_size = _unit_size, \
1296 .byte_order = SIDE_ENUM_INIT(_byte_order), \
1297 }, \
1298 }, \
1299 }, \
1300 }, \
1301 }, \
1302 }
1303 #define side_type_gather_string(_offset, _access_mode, _attr...) \
1304 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1305 #define side_field_gather_string(_name, _offset, _access_mode, _attr...) \
1306 _side_field(_name, side_type_gather_string(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1307
1308 #define side_type_gather_string16(_offset, _access_mode, _attr...) \
1309 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1310 #define side_type_gather_string16_le(_offset, _access_mode, _attr...) \
1311 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1312 #define side_type_gather_string16_be(_offset, _access_mode, _attr...) \
1313 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1314
1315 #define side_field_gather_string16(_name, _offset, _access_mode, _attr...) \
1316 _side_field(_name, side_type_gather_string16(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1317 #define side_field_gather_string16_le(_name, _offset, _access_mode, _attr...) \
1318 _side_field(_name, side_type_gather_string16_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1319 #define side_field_gather_string16_be(_name, _offset, _access_mode, _attr...) \
1320 _side_field(_name, side_type_gather_string16_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1321
1322 #define side_type_gather_string32(_offset, _access_mode, _attr...) \
1323 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1324 #define side_type_gather_string32_le(_offset, _access_mode, _attr...) \
1325 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1326 #define side_type_gather_string32_be(_offset, _access_mode, _attr...) \
1327 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1328
1329 #define side_field_gather_string32(_name, _offset, _access_mode, _attr...) \
1330 _side_field(_name, side_type_gather_string32(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1331 #define side_field_gather_string32_le(_name, _offset, _access_mode, _attr...) \
1332 _side_field(_name, side_type_gather_string32_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1333 #define side_field_gather_string32_be(_name, _offset, _access_mode, _attr...) \
1334 _side_field(_name, side_type_gather_string32_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1335
1336 #define side_type_gather_enum(_mappings, _elem_type) \
1337 { \
1338 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ENUM), \
1339 .u = { \
1340 .side_enum = { \
1341 .mappings = SIDE_PTR_INIT(_mappings), \
1342 .elem_type = SIDE_PTR_INIT(_elem_type), \
1343 }, \
1344 }, \
1345 }
1346 #define side_field_gather_enum(_name, _mappings, _elem_type) \
1347 _side_field(_name, side_type_gather_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1348
1349 #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
1350 { \
1351 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), \
1352 .u = { \
1353 .side_gather = { \
1354 .u = { \
1355 .side_struct = { \
1356 .offset = _offset, \
1357 .access_mode = _access_mode, \
1358 .type = SIDE_PTR_INIT(_struct_gather), \
1359 .size = _size, \
1360 }, \
1361 }, \
1362 }, \
1363 }, \
1364 }
1365 #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \
1366 _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode))
1367
1368 #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr...) \
1369 { \
1370 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), \
1371 .u = { \
1372 .side_gather = { \
1373 .u = { \
1374 .side_array = { \
1375 .offset = _offset, \
1376 .access_mode = _access_mode, \
1377 .type = { \
1378 .elem_type = SIDE_PTR_INIT(_elem_type_gather), \
1379 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1380 .length = _length, \
1381 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1382 }, \
1383 }, \
1384 }, \
1385 }, \
1386 }, \
1387 }
1388 #define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr...) \
1389 _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1390
1391 #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \
1392 { \
1393 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), \
1394 .u = { \
1395 .side_gather = { \
1396 .u = { \
1397 .side_vla = { \
1398 .length_type = SIDE_PTR_INIT(_length_type_gather), \
1399 .offset = _offset, \
1400 .access_mode = _access_mode, \
1401 .type = { \
1402 .elem_type = SIDE_PTR_INIT(_elem_type_gather), \
1403 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1404 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1405 }, \
1406 }, \
1407 }, \
1408 }, \
1409 }, \
1410 }
1411 #define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \
1412 _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1413
1414 #define side_elem(...) \
1415 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1416
1417 #define side_length(...) \
1418 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1419
1420 #define side_field_list(...) \
1421 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
1422
1423 #define side_option_list(...) \
1424 SIDE_COMPOUND_LITERAL(const struct side_variant_option, __VA_ARGS__)
1425
1426 /* Stack-copy field arguments */
1427
1428 #define side_arg_null(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL) }
1429 #define side_arg_bool(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } }
1430 #define side_arg_byte(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), .u = { .side_static = { .byte_value = (_val) } } }
1431 #define side_arg_string(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF8), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
1432 #define side_arg_string16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF16), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
1433 #define side_arg_string32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF32), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
1434
1435 #define side_arg_u8(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U8), .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1436 #define side_arg_u16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U16), .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1437 #define side_arg_u32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U32), .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1438 #define side_arg_u64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U64), .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1439 #define side_arg_s8(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S8), .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
1440 #define side_arg_s16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S16), .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
1441 #define side_arg_s32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S32), .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
1442 #define side_arg_s64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S64), .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
1443 #define side_arg_pointer(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_POINTER), .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } }
1444 #define side_arg_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY16), .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
1445 #define side_arg_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY32), .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
1446 #define side_arg_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY64), .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
1447 #define side_arg_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY128), .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
1448
1449 #define side_arg_struct(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), .u = { .side_static = { .side_struct = SIDE_PTR_INIT(_side_type) } } }
1450
1451 #define side_arg_define_variant(_identifier, _selector_val, _option) \
1452 const struct side_arg_variant _identifier = { \
1453 .selector = _selector_val, \
1454 .option = _option, \
1455 }
1456 #define side_arg_variant(_side_variant) \
1457 { \
1458 .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \
1459 .u = { \
1460 .side_static = { \
1461 .side_variant = SIDE_PTR_INIT(_side_variant), \
1462 }, \
1463 }, \
1464 }
1465
1466 #define side_arg_array(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), .u = { .side_static = { .side_array = SIDE_PTR_INIT(_side_type) } } }
1467 #define side_arg_vla(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), .u = { .side_static = { .side_vla = SIDE_PTR_INIT(_side_type) } } }
1468 #define side_arg_vla_visitor(_ctx) { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
1469
1470 /* Gather field arguments */
1471
1472 #define side_arg_gather_bool(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), .u = { .side_static = { .side_bool_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1473 #define side_arg_gather_byte(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), .u = { .side_static = { .side_byte_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1474 #define side_arg_gather_pointer(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_POINTER), .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1475 #define side_arg_gather_integer(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_INTEGER), .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1476 #define side_arg_gather_float(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), .u = { .side_static = { .side_float_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1477 #define side_arg_gather_string(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), .u = { .side_static = { .side_string_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1478 #define side_arg_gather_struct(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), .u = { .side_static = { .side_struct_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1479 #define side_arg_gather_array(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), .u = { .side_static = { .side_array_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1480 #define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), .u = { .side_static = { .side_vla_gather = { .ptr = SIDE_PTR_INIT(_ptr), .length_ptr = SIDE_PTR_INIT(_length_ptr) } } } }
1481
1482 /* Dynamic field arguments */
1483
1484 #define side_arg_dynamic_null(_attr...) \
1485 { \
1486 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_NULL), \
1487 .u = { \
1488 .side_dynamic = { \
1489 .side_null = { \
1490 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1491 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1492 }, \
1493 }, \
1494 }, \
1495 }
1496
1497 #define side_arg_dynamic_bool(_val, _attr...) \
1498 { \
1499 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BOOL), \
1500 .u = { \
1501 .side_dynamic = { \
1502 .side_bool = { \
1503 .type = { \
1504 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1505 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1506 .bool_size = sizeof(uint8_t), \
1507 .len_bits = 0, \
1508 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
1509 }, \
1510 .value = { \
1511 .side_bool8 = !!(_val), \
1512 }, \
1513 }, \
1514 }, \
1515 }, \
1516 }
1517
1518 #define side_arg_dynamic_byte(_val, _attr...) \
1519 { \
1520 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BYTE), \
1521 .u = { \
1522 .side_dynamic = { \
1523 .side_byte = { \
1524 .type = { \
1525 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1526 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1527 }, \
1528 .value = (_val), \
1529 }, \
1530 }, \
1531 }, \
1532 }
1533
1534 #define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr...) \
1535 { \
1536 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRING), \
1537 .u = { \
1538 .side_dynamic = { \
1539 .side_string = { \
1540 .type = { \
1541 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1542 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1543 .unit_size = _unit_size, \
1544 .byte_order = SIDE_ENUM_INIT(_byte_order), \
1545 }, \
1546 .value = (uintptr_t) (_val), \
1547 }, \
1548 }, \
1549 }, \
1550 }
1551 #define side_arg_dynamic_string(_val, _attr...) \
1552 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1553 #define side_arg_dynamic_string16(_val, _attr...) \
1554 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1555 #define side_arg_dynamic_string16_le(_val, _attr...) \
1556 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1557 #define side_arg_dynamic_string16_be(_val, _attr...) \
1558 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1559 #define side_arg_dynamic_string32(_val, _attr...) \
1560 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1561 #define side_arg_dynamic_string32_le(_val, _attr...) \
1562 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1563 #define side_arg_dynamic_string32_be(_val, _attr...) \
1564 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1565
1566 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr...) \
1567 { \
1568 .type = SIDE_ENUM_INIT(_type), \
1569 .u = { \
1570 .side_dynamic = { \
1571 .side_integer = { \
1572 .type = { \
1573 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1574 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1575 .integer_size = _integer_size, \
1576 .len_bits = _len_bits, \
1577 .signedness = _signedness, \
1578 .byte_order = SIDE_ENUM_INIT(_byte_order), \
1579 }, \
1580 .value = { \
1581 _field = (_val), \
1582 }, \
1583 }, \
1584 }, \
1585 }, \
1586 }
1587
1588 #define side_arg_dynamic_u8(_val, _attr...) \
1589 _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1590 #define side_arg_dynamic_s8(_val, _attr...) \
1591 _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1592
1593 #define _side_arg_dynamic_u16(_val, _byte_order, _attr...) \
1594 _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1595 #define _side_arg_dynamic_u32(_val, _byte_order, _attr...) \
1596 _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1597 #define _side_arg_dynamic_u64(_val, _byte_order, _attr...) \
1598 _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1599
1600 #define _side_arg_dynamic_s16(_val, _byte_order, _attr...) \
1601 _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1602 #define _side_arg_dynamic_s32(_val, _byte_order, _attr...) \
1603 _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1604 #define _side_arg_dynamic_s64(_val, _byte_order, _attr...) \
1605 _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1606
1607 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr...) \
1608 _side_arg_dynamic_integer(.side_uptr, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER, false, _byte_order, \
1609 sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1610
1611 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr...) \
1612 { \
1613 .type = SIDE_ENUM_INIT(_type), \
1614 .u = { \
1615 .side_dynamic = { \
1616 .side_float = { \
1617 .type = { \
1618 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1619 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1620 .float_size = _float_size, \
1621 .byte_order = SIDE_ENUM_INIT(_byte_order), \
1622 }, \
1623 .value = { \
1624 _field = (_val), \
1625 }, \
1626 }, \
1627 }, \
1628 }, \
1629 }
1630
1631 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr...) \
1632 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1633 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr...) \
1634 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1635 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr...) \
1636 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1637 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr...) \
1638 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1639
1640 /* Host endian */
1641 #define side_arg_dynamic_u16(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1642 #define side_arg_dynamic_u32(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1643 #define side_arg_dynamic_u64(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1644 #define side_arg_dynamic_s16(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1645 #define side_arg_dynamic_s32(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1646 #define side_arg_dynamic_s64(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1647 #define side_arg_dynamic_pointer(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1648 #define side_arg_dynamic_float_binary16(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1649 #define side_arg_dynamic_float_binary32(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1650 #define side_arg_dynamic_float_binary64(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1651 #define side_arg_dynamic_float_binary128(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1652
1653 /* Little endian */
1654 #define side_arg_dynamic_u16_le(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1655 #define side_arg_dynamic_u32_le(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1656 #define side_arg_dynamic_u64_le(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1657 #define side_arg_dynamic_s16_le(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1658 #define side_arg_dynamic_s32_le(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1659 #define side_arg_dynamic_s64_le(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1660 #define side_arg_dynamic_pointer_le(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1661 #define side_arg_dynamic_float_binary16_le(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1662 #define side_arg_dynamic_float_binary32_le(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1663 #define side_arg_dynamic_float_binary64_le(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1664 #define side_arg_dynamic_float_binary128_le(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1665
1666 /* Big endian */
1667 #define side_arg_dynamic_u16_be(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1668 #define side_arg_dynamic_u32_be(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1669 #define side_arg_dynamic_u64_be(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1670 #define side_arg_dynamic_s16_be(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1671 #define side_arg_dynamic_s32_be(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1672 #define side_arg_dynamic_s64_be(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1673 #define side_arg_dynamic_pointer_be(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1674 #define side_arg_dynamic_float_binary16_be(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1675 #define side_arg_dynamic_float_binary32_be(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1676 #define side_arg_dynamic_float_binary64_be(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1677 #define side_arg_dynamic_float_binary128_be(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1678
1679 #define side_arg_dynamic_vla(_vla) \
1680 { \
1681 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA), \
1682 .u = { \
1683 .side_dynamic = { \
1684 .side_dynamic_vla = SIDE_PTR_INIT(_vla), \
1685 }, \
1686 }, \
1687 }
1688
1689 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr...) \
1690 { \
1691 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA_VISITOR), \
1692 .u = { \
1693 .side_dynamic = { \
1694 .side_dynamic_vla_visitor = { \
1695 .app_ctx = _ctx, \
1696 .visitor = _dynamic_vla_visitor, \
1697 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1698 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1699 }, \
1700 }, \
1701 }, \
1702 }
1703
1704 #define side_arg_dynamic_struct(_struct) \
1705 { \
1706 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT), \
1707 .u = { \
1708 .side_dynamic = { \
1709 .side_dynamic_struct = SIDE_PTR_INIT(_struct), \
1710 }, \
1711 }, \
1712 }
1713
1714 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr...) \
1715 { \
1716 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT_VISITOR), \
1717 .u = { \
1718 .side_dynamic = { \
1719 .side_dynamic_struct_visitor = { \
1720 .app_ctx = _ctx, \
1721 .visitor = _dynamic_struct_visitor, \
1722 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1723 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1724 }, \
1725 }, \
1726 }, \
1727 }
1728
1729 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr...) \
1730 const struct side_arg _identifier##_vec[] = { _sav }; \
1731 const struct side_arg_dynamic_vla _identifier = { \
1732 .sav = SIDE_PTR_INIT(_identifier##_vec), \
1733 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1734 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1735 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1736 }
1737
1738 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr...) \
1739 const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \
1740 const struct side_arg_dynamic_struct _identifier = { \
1741 .fields = SIDE_PTR_INIT(_identifier##_fields), \
1742 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1743 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1744 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1745 }
1746
1747 #define side_arg_define_vec(_identifier, _sav) \
1748 const struct side_arg _identifier##_vec[] = { _sav }; \
1749 const struct side_arg_vec _identifier = { \
1750 .sav = SIDE_PTR_INIT(_identifier##_vec), \
1751 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1752 }
1753
1754 #define side_arg_dynamic_field(_name, _elem) \
1755 { \
1756 .field_name = SIDE_PTR_INIT(_name), \
1757 .elem = _elem, \
1758 }
1759
1760 /*
1761 * Event instrumentation description registration, runtime enabled state
1762 * check, and instrumentation invocation.
1763 */
1764
1765 #define side_arg_list(...) __VA_ARGS__
1766
1767 #define side_event_cond(_identifier) \
1768 if (side_unlikely(__atomic_load_n(&side_event_state__##_identifier.enabled, \
1769 __ATOMIC_RELAXED)))
1770
1771 #define side_event_call(_identifier, _sav) \
1772 { \
1773 const struct side_arg side_sav[] = { _sav }; \
1774 const struct side_arg_vec side_arg_vec = { \
1775 .sav = SIDE_PTR_INIT(side_sav), \
1776 .len = SIDE_ARRAY_SIZE(side_sav), \
1777 }; \
1778 side_call(&(_identifier), &side_arg_vec); \
1779 }
1780
1781 #define side_event(_identifier, _sav) \
1782 side_event_cond(_identifier) \
1783 side_event_call(_identifier, SIDE_PARAM(_sav))
1784
1785 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr...) \
1786 { \
1787 const struct side_arg side_sav[] = { _sav }; \
1788 const struct side_arg_vec side_arg_vec = { \
1789 .sav = SIDE_PTR_INIT(side_sav), \
1790 .len = SIDE_ARRAY_SIZE(side_sav), \
1791 }; \
1792 const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \
1793 const struct side_arg_dynamic_struct var_struct = { \
1794 .fields = SIDE_PTR_INIT(side_fields), \
1795 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1796 .len = SIDE_ARRAY_SIZE(side_fields), \
1797 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1798 }; \
1799 side_call_variadic(&(_identifier), &side_arg_vec, &var_struct); \
1800 }
1801
1802 #define side_event_variadic(_identifier, _sav, _var, _attr...) \
1803 side_event_cond(_identifier) \
1804 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1805
1806 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _flags, _attr...) \
1807 _linkage struct side_event_state __attribute__((section("side_event_state"))) \
1808 side_event_state__##_identifier = { \
1809 .enabled = 0, \
1810 .callbacks = &side_empty_callback, \
1811 .nr_callbacks = 0, \
1812 }; \
1813 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1814 _identifier = { \
1815 .state = SIDE_PTR_INIT(&(side_event_state__##_identifier)), \
1816 .provider_name = SIDE_PTR_INIT(_provider), \
1817 .event_name = SIDE_PTR_INIT(_event), \
1818 .fields = SIDE_PTR_INIT(_fields), \
1819 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1820 .flags = (_flags), \
1821 .version = 0, \
1822 .loglevel = SIDE_ENUM_INIT(_loglevel), \
1823 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1824 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
1825 }; \
1826 static const struct side_event_description *side_event_ptr__##_identifier \
1827 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1828
1829 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1830 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1831 0, ##_attr)
1832
1833 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1834 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1835 SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1836
1837 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1838 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1839 _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1840
1841 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1842 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1843 _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1844
1845 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1846 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1847 _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1848
1849 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
1850 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1851 _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1852
1853 #define side_declare_event(_identifier) \
1854 extern struct side_event_state side_event_state_##_identifier; \
1855 extern struct side_event_description _identifier
1856
1857 #ifdef __cplusplus
1858 extern "C" {
1859 #endif
1860
1861 extern const struct side_callback side_empty_callback;
1862
1863 void side_call(const struct side_event_description *desc,
1864 const struct side_arg_vec *side_arg_vec);
1865 void side_call_variadic(const struct side_event_description *desc,
1866 const struct side_arg_vec *side_arg_vec,
1867 const struct side_arg_dynamic_struct *var_struct);
1868
1869 struct side_events_register_handle *side_events_register(struct side_event_description **events,
1870 uint32_t nr_events);
1871 void side_events_unregister(struct side_events_register_handle *handle);
1872
1873 /*
1874 * Userspace tracer registration API. This allows userspace tracers to
1875 * register event notification callbacks to be notified of the currently
1876 * registered instrumentation, and to register their callbacks to
1877 * specific events.
1878 */
1879 typedef void (*side_tracer_callback_func)(const struct side_event_description *desc,
1880 const struct side_arg_vec *side_arg_vec,
1881 void *priv);
1882 typedef void (*side_tracer_callback_variadic_func)(const struct side_event_description *desc,
1883 const struct side_arg_vec *side_arg_vec,
1884 const struct side_arg_dynamic_struct *var_struct,
1885 void *priv);
1886
1887 int side_tracer_callback_register(struct side_event_description *desc,
1888 side_tracer_callback_func call,
1889 void *priv);
1890 int side_tracer_callback_variadic_register(struct side_event_description *desc,
1891 side_tracer_callback_variadic_func call_variadic,
1892 void *priv);
1893 int side_tracer_callback_unregister(struct side_event_description *desc,
1894 side_tracer_callback_func call,
1895 void *priv);
1896 int side_tracer_callback_variadic_unregister(struct side_event_description *desc,
1897 side_tracer_callback_variadic_func call_variadic,
1898 void *priv);
1899
1900 enum side_tracer_notification {
1901 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS,
1902 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS,
1903 };
1904
1905 /* Callback is invoked with side library internal lock held. */
1906 struct side_tracer_handle *side_tracer_event_notification_register(
1907 void (*cb)(enum side_tracer_notification notif,
1908 struct side_event_description **events, uint32_t nr_events, void *priv),
1909 void *priv);
1910 void side_tracer_event_notification_unregister(struct side_tracer_handle *handle);
1911
1912 /*
1913 * Explicit hooks to initialize/finalize the side instrumentation
1914 * library. Those are also library constructor/destructor.
1915 */
1916 void side_init(void) __attribute__((constructor));
1917 void side_exit(void) __attribute__((destructor));
1918
1919 /*
1920 * The following constructors/destructors perform automatic registration
1921 * of the declared side events. Those may have to be called explicitly
1922 * in a statically linked library.
1923 */
1924
1925 /*
1926 * These weak symbols, the constructor, and destructor take care of
1927 * registering only _one_ instance of the side instrumentation per
1928 * shared-ojbect (or for the whole main program).
1929 */
1930 extern struct side_event_description * __start_side_event_description_ptr[]
1931 __attribute__((weak, visibility("hidden")));
1932 extern struct side_event_description * __stop_side_event_description_ptr[]
1933 __attribute__((weak, visibility("hidden")));
1934 int side_event_description_ptr_registered
1935 __attribute__((weak, visibility("hidden")));
1936 struct side_events_register_handle *side_events_handle
1937 __attribute__((weak, visibility("hidden")));
1938
1939 static void
1940 side_event_description_ptr_init(void)
1941 __attribute__((no_instrument_function))
1942 __attribute__((constructor));
1943 static void
1944 side_event_description_ptr_init(void)
1945 {
1946 if (side_event_description_ptr_registered++)
1947 return;
1948 side_events_handle = side_events_register(__start_side_event_description_ptr,
1949 __stop_side_event_description_ptr - __start_side_event_description_ptr);
1950 }
1951
1952 static void
1953 side_event_description_ptr_exit(void)
1954 __attribute__((no_instrument_function))
1955 __attribute__((destructor));
1956 static void
1957 side_event_description_ptr_exit(void)
1958 {
1959 if (--side_event_description_ptr_registered)
1960 return;
1961 side_events_unregister(side_events_handle);
1962 side_events_handle = NULL;
1963 }
1964
1965 #ifdef __cplusplus
1966 }
1967 #endif
1968
1969 #endif /* _SIDE_TRACE_H */
This page took 0.10589 seconds and 4 git commands to generate.