Move type descriptions in header file
[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 <side/macros.h>
15 #include <side/endian.h>
16
17 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
18
19 //TODO: as those structures will be ABI, we need to either consider them
20 //fixed forever, or think of a scheme that would allow their binary
21 //representation to be extended if need be.
22
23 struct side_arg_vec;
24 struct side_arg_vec_description;
25 struct side_arg_dynamic_vec;
26 struct side_arg_dynamic_vec_vla;
27 struct side_type_description;
28 struct side_event_field;
29 struct side_event_field_sg;
30 struct side_tracer_visitor_ctx;
31 struct side_tracer_dynamic_struct_visitor_ctx;
32 struct side_tracer_dynamic_vla_visitor_ctx;
33 struct side_event_description;
34 struct side_arg_dynamic_event_struct;
35 struct side_events_register_handle;
36
37 enum side_type {
38 /* Basic types */
39 SIDE_TYPE_NULL,
40 SIDE_TYPE_BOOL,
41 SIDE_TYPE_U8,
42 SIDE_TYPE_U16,
43 SIDE_TYPE_U32,
44 SIDE_TYPE_U64,
45 SIDE_TYPE_S8,
46 SIDE_TYPE_S16,
47 SIDE_TYPE_S32,
48 SIDE_TYPE_S64,
49 SIDE_TYPE_BYTE,
50 SIDE_TYPE_POINTER32,
51 SIDE_TYPE_POINTER64,
52 SIDE_TYPE_FLOAT_BINARY16,
53 SIDE_TYPE_FLOAT_BINARY32,
54 SIDE_TYPE_FLOAT_BINARY64,
55 SIDE_TYPE_FLOAT_BINARY128,
56 SIDE_TYPE_STRING,
57
58 /* Compound types */
59 SIDE_TYPE_STRUCT,
60 SIDE_TYPE_STRUCT_SG,
61 SIDE_TYPE_ARRAY,
62 SIDE_TYPE_VLA,
63 SIDE_TYPE_VLA_VISITOR,
64
65 SIDE_TYPE_ARRAY_U8,
66 SIDE_TYPE_ARRAY_U16,
67 SIDE_TYPE_ARRAY_U32,
68 SIDE_TYPE_ARRAY_U64,
69 SIDE_TYPE_ARRAY_S8,
70 SIDE_TYPE_ARRAY_S16,
71 SIDE_TYPE_ARRAY_S32,
72 SIDE_TYPE_ARRAY_S64,
73 SIDE_TYPE_ARRAY_BYTE,
74 SIDE_TYPE_ARRAY_POINTER32,
75 SIDE_TYPE_ARRAY_POINTER64,
76
77 SIDE_TYPE_VLA_U8,
78 SIDE_TYPE_VLA_U16,
79 SIDE_TYPE_VLA_U32,
80 SIDE_TYPE_VLA_U64,
81 SIDE_TYPE_VLA_S8,
82 SIDE_TYPE_VLA_S16,
83 SIDE_TYPE_VLA_S32,
84 SIDE_TYPE_VLA_S64,
85 SIDE_TYPE_VLA_BYTE,
86 SIDE_TYPE_VLA_POINTER32,
87 SIDE_TYPE_VLA_POINTER64,
88
89 /* Enumeration types */
90 SIDE_TYPE_ENUM,
91 SIDE_TYPE_ENUM_BITMAP,
92
93 /* Dynamic type */
94 SIDE_TYPE_DYNAMIC,
95 };
96
97 enum side_dynamic_type {
98 /* Basic types */
99 SIDE_DYNAMIC_TYPE_NULL,
100 SIDE_DYNAMIC_TYPE_BOOL,
101 SIDE_DYNAMIC_TYPE_U8,
102 SIDE_DYNAMIC_TYPE_U16,
103 SIDE_DYNAMIC_TYPE_U32,
104 SIDE_DYNAMIC_TYPE_U64,
105 SIDE_DYNAMIC_TYPE_S8,
106 SIDE_DYNAMIC_TYPE_S16,
107 SIDE_DYNAMIC_TYPE_S32,
108 SIDE_DYNAMIC_TYPE_S64,
109 SIDE_DYNAMIC_TYPE_BYTE,
110 SIDE_DYNAMIC_TYPE_POINTER32,
111 SIDE_DYNAMIC_TYPE_POINTER64,
112 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16,
113 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32,
114 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64,
115 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128,
116 SIDE_DYNAMIC_TYPE_STRING,
117
118 /* Compound types */
119 SIDE_DYNAMIC_TYPE_STRUCT,
120 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR,
121 SIDE_DYNAMIC_TYPE_VLA,
122 SIDE_DYNAMIC_TYPE_VLA_VISITOR,
123 };
124
125 enum side_attr_type {
126 SIDE_ATTR_TYPE_NULL,
127 SIDE_ATTR_TYPE_BOOL,
128 SIDE_ATTR_TYPE_U8,
129 SIDE_ATTR_TYPE_U16,
130 SIDE_ATTR_TYPE_U32,
131 SIDE_ATTR_TYPE_U64,
132 SIDE_ATTR_TYPE_S8,
133 SIDE_ATTR_TYPE_S16,
134 SIDE_ATTR_TYPE_S32,
135 SIDE_ATTR_TYPE_S64,
136 SIDE_ATTR_TYPE_POINTER32,
137 SIDE_ATTR_TYPE_POINTER64,
138 SIDE_ATTR_TYPE_FLOAT_BINARY16,
139 SIDE_ATTR_TYPE_FLOAT_BINARY32,
140 SIDE_ATTR_TYPE_FLOAT_BINARY64,
141 SIDE_ATTR_TYPE_FLOAT_BINARY128,
142 SIDE_ATTR_TYPE_STRING,
143 };
144
145 enum side_type_sg {
146 SIDE_TYPE_SG_NULL,
147 SIDE_TYPE_SG_UNSIGNED_INT,
148 SIDE_TYPE_SG_SIGNED_INT,
149 };
150
151 enum side_loglevel {
152 SIDE_LOGLEVEL_EMERG = 0,
153 SIDE_LOGLEVEL_ALERT = 1,
154 SIDE_LOGLEVEL_CRIT = 2,
155 SIDE_LOGLEVEL_ERR = 3,
156 SIDE_LOGLEVEL_WARNING = 4,
157 SIDE_LOGLEVEL_NOTICE = 5,
158 SIDE_LOGLEVEL_INFO = 6,
159 SIDE_LOGLEVEL_DEBUG = 7,
160 };
161
162 enum side_visitor_status {
163 SIDE_VISITOR_STATUS_OK = 0,
164 SIDE_VISITOR_STATUS_ERROR = -1,
165 };
166
167 enum side_error {
168 SIDE_ERROR_OK = 0,
169 SIDE_ERROR_INVAL = 1,
170 SIDE_ERROR_EXIST = 2,
171 SIDE_ERROR_NOMEM = 3,
172 SIDE_ERROR_NOENT = 4,
173 SIDE_ERROR_EXITING = 5,
174 };
175
176 enum side_type_byte_order {
177 SIDE_TYPE_BYTE_ORDER_LE = 0,
178 SIDE_TYPE_BYTE_ORDER_BE = 1,
179 };
180
181 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
182 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
183 #else
184 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
185 #endif
186
187 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
188 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
189 #else
190 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
191 #endif
192
193 typedef enum side_visitor_status (*side_visitor)(
194 const struct side_tracer_visitor_ctx *tracer_ctx,
195 void *app_ctx);
196 typedef enum side_visitor_status (*side_dynamic_struct_visitor)(
197 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
198 void *app_ctx);
199 typedef enum side_visitor_status (*side_dynamic_vla_visitor)(
200 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
201 void *app_ctx);
202
203 union side_integer_value {
204 uint8_t side_u8;
205 uint16_t side_u16;
206 uint32_t side_u32;
207 uint64_t side_u64;
208 int8_t side_s8;
209 int16_t side_s16;
210 int32_t side_s32;
211 int64_t side_s64;
212 } SIDE_PACKED;
213
214 union side_float_value {
215 #if __HAVE_FLOAT16
216 _Float16 side_float_binary16;
217 #endif
218 #if __HAVE_FLOAT32
219 _Float32 side_float_binary32;
220 #endif
221 #if __HAVE_FLOAT64
222 _Float64 side_float_binary64;
223 #endif
224 #if __HAVE_FLOAT128
225 _Float128 side_float_binary128;
226 #endif
227 } SIDE_PACKED;
228
229 struct side_attr_value {
230 uint32_t type; /* enum side_attr_type */
231 union {
232 uint8_t bool_value;
233 uint64_t string_value; /* const char * */
234 union side_integer_value integer_value;
235 union side_float_value float_value;
236 } SIDE_PACKED u;
237 };
238
239 /* User attributes. */
240 struct side_attr {
241 const char *key;
242 const struct side_attr_value value;
243 } SIDE_PACKED;
244
245 /* Type descriptions */
246 struct side_type_null {
247 const struct side_attr *attr;
248 uint32_t nr_attr;
249 } SIDE_PACKED;
250
251 struct side_type_bool {
252 const struct side_attr *attr;
253 uint32_t nr_attr;
254 } SIDE_PACKED;
255
256 struct side_type_byte {
257 const struct side_attr *attr;
258 uint32_t nr_attr;
259 } SIDE_PACKED;
260
261 struct side_type_dynamic {
262 const struct side_attr *attr;
263 uint32_t nr_attr;
264 } SIDE_PACKED;
265
266 struct side_type_string {
267 const struct side_attr *attr;
268 uint32_t nr_attr;
269 } SIDE_PACKED;
270
271 struct side_type_integer {
272 const struct side_attr *attr;
273 uint32_t nr_attr;
274 uint16_t integer_size_bits; /* bits */
275 uint16_t len_bits; /* bits */
276 uint8_t signedness; /* true/false */
277 uint8_t byte_order; /* enum side_type_byte_order */
278 } SIDE_PACKED;
279
280 struct side_type_float {
281 const struct side_attr *attr;
282 uint32_t nr_attr;
283 uint32_t byte_order; /* enum side_type_byte_order */
284 uint16_t float_size_bits; /* bits */
285 } SIDE_PACKED;
286
287 struct side_enum_mapping {
288 int64_t range_begin;
289 int64_t range_end;
290 const char *label;
291 } SIDE_PACKED;
292
293 struct side_enum_mappings {
294 const struct side_enum_mapping *mappings;
295 const struct side_attr *attr;
296 uint32_t nr_mappings;
297 uint32_t nr_attr;
298 } SIDE_PACKED;
299
300 struct side_enum_bitmap_mapping {
301 uint64_t range_begin;
302 uint64_t range_end;
303 const char *label;
304 } SIDE_PACKED;
305
306 struct side_enum_bitmap_mappings {
307 const struct side_enum_bitmap_mapping *mappings;
308 const struct side_attr *attr;
309 uint32_t nr_mappings;
310 uint32_t nr_attr;
311 } SIDE_PACKED;
312
313 struct side_type_struct {
314 uint32_t nr_fields;
315 uint32_t nr_attr;
316 const struct side_event_field *fields;
317 const struct side_attr *attr;
318 } SIDE_PACKED;
319
320 struct side_type_sg_description {
321 uint64_t offset; /* bytes */
322 uint32_t type; /* enum side_type_sg */
323 union {
324 struct side_type_null side_null;
325 struct {
326 struct side_type_integer type;
327 uint16_t offset_bits; /* bits */
328 } SIDE_PACKED side_integer;
329 } SIDE_PACKED u;
330 } SIDE_PACKED;
331
332 struct side_struct_field_sg {
333 const char *field_name;
334 struct side_type_sg_description side_type;
335 } SIDE_PACKED;
336
337 /* Structure fields scatter-gather. */
338 struct side_type_struct_sg {
339 uint32_t nr_fields;
340 uint32_t nr_attr;
341 const struct side_struct_field_sg *fields_sg;
342 const struct side_attr *attr;
343 } SIDE_PACKED;
344
345 struct side_type_description {
346 uint32_t type; /* enum side_type */
347 union {
348 /* Basic types */
349 struct side_type_null side_null;
350 struct side_type_bool side_bool;
351 struct side_type_byte side_byte;
352 struct side_type_dynamic side_dynamic;
353 struct side_type_string side_string;
354 struct side_type_integer side_integer;
355 struct side_type_float side_float;
356
357 /* Compound types */
358 struct {
359 const struct side_type_description *elem_type;
360 const struct side_attr *attr;
361 uint32_t length;
362 uint32_t nr_attr;
363 } SIDE_PACKED side_array;
364 struct {
365 const struct side_type_description *elem_type;
366 const struct side_attr *attr;
367 uint32_t nr_attr;
368 } SIDE_PACKED side_vla;
369 struct {
370 const struct side_type_description *elem_type;
371 side_visitor visitor;
372 const struct side_attr *attr;
373 uint32_t nr_attr;
374 } SIDE_PACKED side_vla_visitor;
375 const struct side_type_struct *side_struct;
376 const struct side_type_struct_sg *side_struct_sg;
377
378 /* Enumeration types */
379 struct {
380 const struct side_enum_mappings *mappings;
381 const struct side_type_description *elem_type;
382 } SIDE_PACKED side_enum;
383 struct {
384 const struct side_enum_bitmap_mappings *mappings;
385 const struct side_type_description *elem_type;
386 } SIDE_PACKED side_enum_bitmap;
387 } SIDE_PACKED u;
388 } SIDE_PACKED;
389
390 struct side_event_field {
391 const char *field_name;
392 struct side_type_description side_type;
393 } SIDE_PACKED;
394
395 enum side_event_flags {
396 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
397 };
398
399 struct side_callback {
400 union {
401 void (*call)(const struct side_event_description *desc,
402 const struct side_arg_vec_description *sav_desc,
403 void *priv);
404 void (*call_variadic)(const struct side_event_description *desc,
405 const struct side_arg_vec_description *sav_desc,
406 const struct side_arg_dynamic_event_struct *var_struct,
407 void *priv);
408 } SIDE_PACKED u;
409 void *priv;
410 } SIDE_PACKED;
411
412 struct side_event_description {
413 uintptr_t *enabled;
414 const char *provider_name;
415 const char *event_name;
416 const struct side_event_field *fields;
417 const struct side_attr *attr;
418 const struct side_callback *callbacks;
419 uint64_t flags;
420 uint32_t version;
421 uint32_t loglevel; /* enum side_loglevel */
422 uint32_t nr_fields;
423 uint32_t nr_attr;
424 uint32_t nr_callbacks;
425 } SIDE_PACKED;
426
427 struct side_arg_dynamic_vec {
428 uint32_t dynamic_type; /* enum side_dynamic_type */
429 union {
430 struct side_type_null side_null;
431
432 /* Basic types */
433 struct {
434 struct side_type_bool type;
435 uint8_t value;
436 } SIDE_PACKED side_bool;
437
438 struct {
439 struct side_type_byte type;
440 uint8_t value;
441 } SIDE_PACKED side_byte;
442
443 struct {
444 struct side_type_string type;
445 uint64_t value; /* const char * */
446 } SIDE_PACKED side_string;
447
448 /* Integer type */
449 struct {
450 struct side_type_integer type;
451 union side_integer_value value;
452 } SIDE_PACKED side_integer;
453
454 struct {
455 struct side_type_float type;
456 union side_float_value value;
457 } SIDE_PACKED side_float;
458
459 /* Compound types */
460 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
461 struct {
462 void *app_ctx;
463 side_dynamic_struct_visitor visitor;
464 const struct side_attr *attr;
465 uint32_t nr_attr;
466 } SIDE_PACKED side_dynamic_struct_visitor;
467 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
468 struct {
469 void *app_ctx;
470 side_dynamic_vla_visitor visitor;
471 const struct side_attr *attr;
472 uint32_t nr_attr;
473 } SIDE_PACKED side_dynamic_vla_visitor;
474 } SIDE_PACKED u;
475 } SIDE_PACKED;
476
477 struct side_arg_dynamic_vec_vla {
478 const struct side_arg_dynamic_vec *sav;
479 const struct side_attr *attr;
480 uint32_t len;
481 uint32_t nr_attr;
482 } SIDE_PACKED;
483
484 struct side_arg_dynamic_event_field {
485 const char *field_name;
486 const struct side_arg_dynamic_vec elem;
487 } SIDE_PACKED;
488
489 struct side_arg_dynamic_event_struct {
490 const struct side_arg_dynamic_event_field *fields;
491 const struct side_attr *attr;
492 uint32_t len;
493 uint32_t nr_attr;
494 } SIDE_PACKED;
495
496 struct side_arg_vec {
497 enum side_type type;
498 union {
499 /* Basic types */
500 uint8_t bool_value;
501 uint8_t byte_value;
502 uint64_t string_value; /* const char * */
503 union side_integer_value integer_value;
504 union side_float_value float_value;
505
506 /* Compound types */
507 const struct side_arg_vec_description *side_struct;
508 const struct side_arg_vec_description *side_array;
509 const struct side_arg_vec_description *side_vla;
510 void *side_vla_app_visitor_ctx;
511 void *side_array_fixint;
512 struct {
513 void *p;
514 uint32_t length;
515 } SIDE_PACKED side_vla_fixint;
516 void *side_struct_sg_ptr;
517
518 /* Dynamic type */
519 struct side_arg_dynamic_vec dynamic_value;
520 } SIDE_PACKED u;
521 } SIDE_PACKED;
522
523 struct side_arg_vec_description {
524 const struct side_arg_vec *sav;
525 uint32_t len;
526 } SIDE_PACKED;
527
528 /* The visitor pattern is a double-dispatch visitor. */
529 struct side_tracer_visitor_ctx {
530 enum side_visitor_status (*write_elem)(
531 const struct side_tracer_visitor_ctx *tracer_ctx,
532 const struct side_arg_vec *elem);
533 void *priv; /* Private tracer context. */
534 } SIDE_PACKED;
535
536 struct side_tracer_dynamic_struct_visitor_ctx {
537 enum side_visitor_status (*write_field)(
538 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
539 const struct side_arg_dynamic_event_field *dynamic_field);
540 void *priv; /* Private tracer context. */
541 } SIDE_PACKED;
542
543 struct side_tracer_dynamic_vla_visitor_ctx {
544 enum side_visitor_status (*write_elem)(
545 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
546 const struct side_arg_dynamic_vec *elem);
547 void *priv; /* Private tracer context. */
548 } SIDE_PACKED;
549
550 /* Event and type attributes */
551
552 #if SIDE_BITS_PER_LONG == 64
553 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
554 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
555 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
556 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER64
557 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
558 # define SIDE_PTR_HOST .side_u64
559 #else
560 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
561 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
562 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
563 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER32
564 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
565 # define SIDE_PTR_HOST .side_u32
566 #endif
567
568 #define side_attr(_key, _value) \
569 { \
570 .key = _key, \
571 .value = SIDE_PARAM(_value), \
572 }
573
574 #define side_attr_list(...) \
575 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
576
577 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
578 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
579 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
580 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
581 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
582 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
583 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
584 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
585 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
586 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
587 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
588 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
589 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
590 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
591 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
592 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string_value = (uintptr_t) (_val) } }
593
594 /* Static field definition */
595
596 #define side_type_null(_attr) \
597 { \
598 .type = SIDE_TYPE_NULL, \
599 .u = { \
600 .side_null = { \
601 .attr = _attr, \
602 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
603 }, \
604 }, \
605 }
606
607 #define side_type_bool(_attr) \
608 { \
609 .type = SIDE_TYPE_BOOL, \
610 .u = { \
611 .side_bool = { \
612 .attr = _attr, \
613 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
614 }, \
615 }, \
616 }
617
618 #define side_type_byte(_attr) \
619 { \
620 .type = SIDE_TYPE_BYTE, \
621 .u = { \
622 .side_byte = { \
623 .attr = _attr, \
624 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
625 }, \
626 }, \
627 }
628
629 #define side_type_string(_attr) \
630 { \
631 .type = SIDE_TYPE_STRING, \
632 .u = { \
633 .side_string = { \
634 .attr = _attr, \
635 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
636 }, \
637 }, \
638 }
639
640 #define side_type_dynamic(_attr) \
641 { \
642 .type = SIDE_TYPE_DYNAMIC, \
643 .u = { \
644 .side_dynamic = { \
645 .attr = _attr, \
646 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
647 }, \
648 }, \
649 }
650
651 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
652 { \
653 .type = _type, \
654 .u = { \
655 .side_integer = { \
656 .attr = _attr, \
657 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
658 .integer_size_bits = _integer_size_bits, \
659 .len_bits = _len_bits, \
660 .signedness = _signedness, \
661 .byte_order = _byte_order, \
662 }, \
663 }, \
664 }
665
666 #define _side_type_float(_type, _byte_order, _float_size_bits, _attr) \
667 { \
668 .type = _type, \
669 .u = { \
670 .side_float = { \
671 .attr = _attr, \
672 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
673 .byte_order = _byte_order, \
674 .float_size_bits = _float_size_bits, \
675 }, \
676 }, \
677 }
678
679 #define _side_field(_name, _type) \
680 { \
681 .field_name = _name, \
682 .side_type = _type, \
683 }
684
685 /* Host endian */
686 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
687 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
688 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
689 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
690 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
691 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
692 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
693 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
694 #define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_BITS_PER_LONG, \
695 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
696 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 16, SIDE_PARAM(_attr))
697 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 32, SIDE_PARAM(_attr))
698 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 64, SIDE_PARAM(_attr))
699 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 128, SIDE_PARAM(_attr))
700
701 #define side_field_null(_name, _attr) _side_field(_name, side_type_null(SIDE_PARAM(_attr)))
702 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
703 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
704 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
705 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
706 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
707 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
708 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
709 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
710 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
711 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
712 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
713 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
714 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
715 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
716 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
717 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
718 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
719
720 /* Little endian */
721 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
722 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
723 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
724 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
725 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
726 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
727 #define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_LE, SIDE_BITS_PER_LONG, \
728 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
729 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, 16, SIDE_PARAM(_attr))
730 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, 32, SIDE_PARAM(_attr))
731 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, 64, SIDE_PARAM(_attr))
732 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 128, SIDE_PARAM(_attr))
733
734 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
735 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
736 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
737 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
738 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
739 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
740 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
741 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
742 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
743 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
744 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
745
746 /* Big endian */
747 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
748 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
749 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
750 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
751 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
752 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
753 #define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_BE, SIDE_BITS_PER_LONG, \
754 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
755 #define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, 16, SIDE_PARAM(_attr))
756 #define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, 32, SIDE_PARAM(_attr))
757 #define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, 64, SIDE_PARAM(_attr))
758 #define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, 128, SIDE_PARAM(_attr))
759
760 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
761 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
762 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
763 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
764 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
765 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
766 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
767 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
768 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
769 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
770 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
771
772 #define side_type_enum(_mappings, _elem_type) \
773 { \
774 .type = SIDE_TYPE_ENUM, \
775 .u = { \
776 .side_enum = { \
777 .mappings = _mappings, \
778 .elem_type = _elem_type, \
779 }, \
780 }, \
781 }
782 #define side_field_enum(_name, _mappings, _elem_type) \
783 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
784
785 #define side_type_enum_bitmap(_mappings, _elem_type) \
786 { \
787 .type = SIDE_TYPE_ENUM_BITMAP, \
788 .u = { \
789 .side_enum_bitmap = { \
790 .mappings = _mappings, \
791 .elem_type = _elem_type, \
792 }, \
793 }, \
794 }
795 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
796 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
797
798 #define side_type_struct(_struct) \
799 { \
800 .type = SIDE_TYPE_STRUCT, \
801 .u = { \
802 .side_struct = _struct, \
803 }, \
804 }
805 #define side_field_struct(_name, _struct) \
806 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
807
808 #define _side_type_struct_define(_fields, _attr) \
809 { \
810 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
811 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
812 .fields = _fields, \
813 .attr = _attr, \
814 }
815
816 #define side_define_struct(_identifier, _fields, _attr) \
817 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
818
819 #define side_struct_literal(_fields, _attr) \
820 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
821 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
822
823 /* Scatter-gather struct */
824
825 #define _side_field_sg(_name, _type) \
826 { \
827 .field_name = _name, \
828 .side_type = _type, \
829 }
830
831 #define side_type_sg_null(_attr) \
832 { \
833 .offset = 0, \
834 .type = SIDE_TYPE_SG_NULL, \
835 .u = { \
836 .side_null = { \
837 .attr = _attr, \
838 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
839 }, \
840 }, \
841 }
842
843 #define side_field_sg_null(_name, _attr) \
844 _side_field_sg(_name, side_type_sg_null(SIDE_PARAM(_attr)))
845
846 #define _side_type_sg_integer(_type, _signedness, _byte_order, _offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
847 { \
848 .offset = _offset, \
849 .type = _type, \
850 .u = { \
851 .side_integer = { \
852 .type = { \
853 .attr = _attr, \
854 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
855 .integer_size_bits = _integer_size_bits, \
856 .len_bits = _len_bits, \
857 .signedness = _signedness, \
858 .byte_order = _byte_order, \
859 }, \
860 .offset_bits = _offset_bits, \
861 }, \
862 }, \
863 }
864
865 #define side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
866 _side_type_sg_integer(SIDE_TYPE_SG_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_HOST, \
867 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
868 #define side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
869 _side_type_sg_integer(SIDE_TYPE_SG_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_HOST, \
870 _integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr))
871
872 #define side_field_sg_unsigned_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
873 _side_field_sg(_name, side_type_sg_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
874 #define side_field_sg_signed_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _attr) \
875 _side_field_sg(_name, side_type_sg_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, SIDE_PARAM(_attr)))
876
877 #define side_type_struct_sg(_struct_sg) \
878 { \
879 .type = SIDE_TYPE_STRUCT_SG, \
880 .u = { \
881 .side_struct_sg = _struct_sg, \
882 }, \
883 }
884 #define side_field_struct_sg(_name, _struct_sg) \
885 _side_field(_name, side_type_struct_sg(SIDE_PARAM(_struct_sg)))
886
887 #define _side_type_struct_sg_define(_fields_sg, _attr) \
888 { \
889 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields_sg)), \
890 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
891 .fields_sg = _fields_sg, \
892 .attr = _attr, \
893 }
894
895 #define side_define_struct_sg(_identifier, _fields_sg, _attr) \
896 const struct side_type_struct_sg _identifier = _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr))
897
898 #define side_struct_sg_literal(_fields_sg, _attr) \
899 SIDE_COMPOUND_LITERAL(const struct side_type_struct_sg, \
900 _side_type_struct_sg_define(SIDE_PARAM(_fields_sg), SIDE_PARAM(_attr)))
901
902 #define side_type_array(_elem_type, _length, _attr) \
903 { \
904 .type = SIDE_TYPE_ARRAY, \
905 .u = { \
906 .side_array = { \
907 .elem_type = _elem_type, \
908 .attr = _attr, \
909 .length = _length, \
910 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
911 }, \
912 }, \
913 }
914 #define side_field_array(_name, _elem_type, _length, _attr) \
915 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
916
917 #define side_type_vla(_elem_type, _attr) \
918 { \
919 .type = SIDE_TYPE_VLA, \
920 .u = { \
921 .side_vla = { \
922 .elem_type = _elem_type, \
923 .attr = _attr, \
924 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
925 }, \
926 }, \
927 }
928 #define side_field_vla(_name, _elem_type, _attr) \
929 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
930
931 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
932 { \
933 .type = SIDE_TYPE_VLA_VISITOR, \
934 .u = { \
935 .side_vla_visitor = { \
936 .elem_type = SIDE_PARAM(_elem_type), \
937 .visitor = _visitor, \
938 .attr = _attr, \
939 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
940 }, \
941 }, \
942 }
943 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
944 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
945
946 #define side_elem(...) \
947 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
948
949 #define side_field_list(...) \
950 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
951
952 #define side_field_sg_list(...) \
953 SIDE_COMPOUND_LITERAL(const struct side_struct_field_sg, __VA_ARGS__)
954
955 /* Static field arguments */
956
957 #define side_arg_null(_val) { .type = SIDE_TYPE_NULL }
958 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
959 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .byte_value = (_val) } }
960 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string_value = (uintptr_t) (_val) } }
961 #define side_arg_dynamic(_dynamic_arg_type) { .type = SIDE_TYPE_DYNAMIC, .u = { .dynamic_value = _dynamic_arg_type } }
962
963 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
964 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
965 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
966 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
967 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
968 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
969 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
970 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
971 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
972 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .integer_value = { .side_u8 = (_val) } } }
973 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .integer_value = { .side_u16 = (_val) } } }
974 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .integer_value = { .side_u32 = (_val) } } }
975 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .integer_value = { .side_u64 = (_val) } } }
976 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
977 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
978 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
979 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
980 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
981 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
982
983 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
984 #define side_arg_struct_sg(_ptr) { .type = SIDE_TYPE_STRUCT_SG, .u = { .side_struct_sg_ptr = (_ptr) } }
985 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
986 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
987 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
988
989 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
990 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
991 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
992 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
993 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
994 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
995 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
996 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
997 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
998 #define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_array_fixint = (_ptr) } }
999
1000 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
1001 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1002 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1003 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1004 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1005 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1006 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1007 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1008 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1009 #define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
1010
1011 /* Dynamic field arguments */
1012
1013 #define side_arg_dynamic_null(_attr) \
1014 { \
1015 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
1016 .u = { \
1017 .side_null = { \
1018 .attr = _attr, \
1019 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1020 }, \
1021 }, \
1022 }
1023
1024 #define side_arg_dynamic_bool(_val, _attr) \
1025 { \
1026 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
1027 .u = { \
1028 .side_bool = { \
1029 .type = { \
1030 .attr = _attr, \
1031 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1032 }, \
1033 .value = !!(_val), \
1034 }, \
1035 }, \
1036 }
1037
1038 #define side_arg_dynamic_byte(_val, _attr) \
1039 { \
1040 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
1041 .u = { \
1042 .side_byte = { \
1043 .type = { \
1044 .attr = _attr, \
1045 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1046 }, \
1047 .value = (_val), \
1048 }, \
1049 }, \
1050 }
1051 #define side_arg_dynamic_string(_val, _attr) \
1052 { \
1053 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
1054 .u = { \
1055 .side_string = { \
1056 .type = { \
1057 .attr = _attr, \
1058 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1059 }, \
1060 .value = (uintptr_t) (_val), \
1061 }, \
1062 }, \
1063 }
1064
1065 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
1066 { \
1067 .dynamic_type = _type, \
1068 .u = { \
1069 .side_integer = { \
1070 .type = { \
1071 .attr = _attr, \
1072 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1073 .integer_size_bits = _integer_size_bits, \
1074 .len_bits = _len_bits, \
1075 .signedness = _signedness, \
1076 .byte_order = _byte_order, \
1077 }, \
1078 .value = { \
1079 _field = (_val), \
1080 }, \
1081 }, \
1082 }, \
1083 }
1084
1085 #define side_arg_dynamic_u8(_val, _attr) \
1086 _side_arg_dynamic_integer(.side_u8, _val, SIDE_DYNAMIC_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1087 #define side_arg_dynamic_s8(_val, _attr) \
1088 _side_arg_dynamic_integer(.side_s8, _val, SIDE_DYNAMIC_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1089
1090 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1091 _side_arg_dynamic_integer(.side_u16, _val, SIDE_DYNAMIC_TYPE_U16, false, _byte_order, 16, 16, SIDE_PARAM(_attr))
1092 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1093 _side_arg_dynamic_integer(.side_u32, _val, SIDE_DYNAMIC_TYPE_U32, false, _byte_order, 32, 32, SIDE_PARAM(_attr))
1094 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1095 _side_arg_dynamic_integer(.side_u64, _val, SIDE_DYNAMIC_TYPE_U64, false, _byte_order, 64, 64, SIDE_PARAM(_attr))
1096
1097 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1098 _side_arg_dynamic_integer(.side_s16, _val, SIDE_DYNAMIC_TYPE_S16, true, _byte_order, 16, 16, SIDE_PARAM(_attr))
1099 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1100 _side_arg_dynamic_integer(.side_s32, _val, SIDE_DYNAMIC_TYPE_S32, true, _byte_order, 32, 32, SIDE_PARAM(_attr))
1101 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1102 _side_arg_dynamic_integer(.side_s64, _val, SIDE_DYNAMIC_TYPE_S64, true, _byte_order, 64, 64, SIDE_PARAM(_attr))
1103
1104 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1105 _side_arg_dynamic_integer(SIDE_PTR_HOST, (uintptr_t) (_val), SIDE_DYNAMIC_TYPE_POINTER_HOST, false, _byte_order, \
1106 SIDE_BITS_PER_LONG, SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
1107
1108 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size_bits, _attr) \
1109 { \
1110 .dynamic_type = _type, \
1111 .u = { \
1112 .side_float = { \
1113 .type = { \
1114 .attr = _attr, \
1115 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1116 .byte_order = _byte_order, \
1117 .float_size_bits = _float_size_bits, \
1118 }, \
1119 .value = { \
1120 _field = (_val), \
1121 }, \
1122 }, \
1123 }, \
1124 }
1125
1126 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1127 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, _byte_order, 16, SIDE_PARAM(_attr))
1128 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1129 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, _byte_order, 32, SIDE_PARAM(_attr))
1130 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1131 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, _byte_order, 64, SIDE_PARAM(_attr))
1132 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1133 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, _byte_order, 128, SIDE_PARAM(_attr))
1134
1135 /* Host endian */
1136 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1137 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1138 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1139 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1140 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1141 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1142 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1143 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1144 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1145 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1146 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1147
1148 /* Little endian */
1149 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1150 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1151 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1152 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1153 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1154 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1155 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1156 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1157 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1158 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1159 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1160
1161 /* Big endian */
1162 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1163 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1164 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1165 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1166 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1167 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1168 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1169 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1170 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1171 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1172 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1173
1174 #define side_arg_dynamic_vla(_vla) \
1175 { \
1176 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1177 .u = { \
1178 .side_dynamic_vla = (_vla), \
1179 }, \
1180 }
1181
1182 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1183 { \
1184 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1185 .u = { \
1186 .side_dynamic_vla_visitor = { \
1187 .app_ctx = _ctx, \
1188 .visitor = _dynamic_vla_visitor, \
1189 .attr = _attr, \
1190 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1191 }, \
1192 }, \
1193 }
1194
1195 #define side_arg_dynamic_struct(_struct) \
1196 { \
1197 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1198 .u = { \
1199 .side_dynamic_struct = (_struct), \
1200 }, \
1201 }
1202
1203 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1204 { \
1205 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1206 .u = { \
1207 .side_dynamic_struct_visitor = { \
1208 .app_ctx = _ctx, \
1209 .visitor = _dynamic_struct_visitor, \
1210 .attr = _attr, \
1211 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1212 }, \
1213 }, \
1214 }
1215
1216 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1217 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1218 const struct side_arg_dynamic_vec_vla _identifier = { \
1219 .sav = _identifier##_vec, \
1220 .attr = _attr, \
1221 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1222 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1223 }
1224
1225 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1226 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1227 const struct side_arg_dynamic_event_struct _identifier = { \
1228 .fields = _identifier##_fields, \
1229 .attr = _attr, \
1230 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1231 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1232 }
1233
1234 #define side_arg_define_vec(_identifier, _sav) \
1235 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1236 const struct side_arg_vec_description _identifier = { \
1237 .sav = _identifier##_vec, \
1238 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1239 }
1240
1241 #define side_arg_dynamic_field(_name, _elem) \
1242 { \
1243 .field_name = _name, \
1244 .elem = _elem, \
1245 }
1246
1247 #define side_arg_list(...) __VA_ARGS__
1248
1249 #define side_define_enum(_identifier, _mappings, _attr) \
1250 const struct side_enum_mappings _identifier = { \
1251 .mappings = _mappings, \
1252 .attr = _attr, \
1253 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1254 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1255 }
1256
1257 #define side_enum_mapping_list(...) \
1258 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1259
1260 #define side_enum_mapping_range(_label, _begin, _end) \
1261 { \
1262 .range_begin = _begin, \
1263 .range_end = _end, \
1264 .label = _label, \
1265 }
1266
1267 #define side_enum_mapping_value(_label, _value) \
1268 { \
1269 .range_begin = _value, \
1270 .range_end = _value, \
1271 .label = _label, \
1272 }
1273
1274 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1275 const struct side_enum_bitmap_mappings _identifier = { \
1276 .mappings = _mappings, \
1277 .attr = _attr, \
1278 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1279 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1280 }
1281
1282 #define side_enum_bitmap_mapping_list(...) \
1283 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1284
1285 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1286 { \
1287 .range_begin = _begin, \
1288 .range_end = _end, \
1289 .label = _label, \
1290 }
1291
1292 #define side_enum_bitmap_mapping_value(_label, _value) \
1293 { \
1294 .range_begin = _value, \
1295 .range_end = _value, \
1296 .label = _label, \
1297 }
1298
1299 #define side_event_cond(_identifier) \
1300 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1301 __ATOMIC_RELAXED)))
1302
1303 #define side_event_call(_identifier, _sav) \
1304 { \
1305 const struct side_arg_vec side_sav[] = { _sav }; \
1306 const struct side_arg_vec_description sav_desc = { \
1307 .sav = side_sav, \
1308 .len = SIDE_ARRAY_SIZE(side_sav), \
1309 }; \
1310 side_call(&(_identifier), &sav_desc); \
1311 }
1312
1313 #define side_event(_identifier, _sav) \
1314 side_event_cond(_identifier) \
1315 side_event_call(_identifier, SIDE_PARAM(_sav))
1316
1317 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1318 { \
1319 const struct side_arg_vec side_sav[] = { _sav }; \
1320 const struct side_arg_vec_description sav_desc = { \
1321 .sav = side_sav, \
1322 .len = SIDE_ARRAY_SIZE(side_sav), \
1323 }; \
1324 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1325 const struct side_arg_dynamic_event_struct var_struct = { \
1326 .fields = side_fields, \
1327 .attr = _attr, \
1328 .len = SIDE_ARRAY_SIZE(side_fields), \
1329 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1330 }; \
1331 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1332 }
1333
1334 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1335 side_event_cond(_identifier) \
1336 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1337
1338 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1339 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1340 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1341 _identifier = { \
1342 .enabled = &(side_event_enable__##_identifier), \
1343 .provider_name = _provider, \
1344 .event_name = _event, \
1345 .fields = _fields, \
1346 .attr = _attr, \
1347 .callbacks = &side_empty_callback, \
1348 .flags = (_flags), \
1349 .version = 0, \
1350 .loglevel = _loglevel, \
1351 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1352 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1353 .nr_callbacks = 0, \
1354 }; \
1355 static const struct side_event_description *side_event_ptr__##_identifier \
1356 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1357
1358 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1359 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1360 SIDE_PARAM(_attr), 0)
1361
1362 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1363 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1364 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1365
1366 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1367 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1368 SIDE_PARAM(_attr), 0)
1369
1370 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1371 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1372 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1373
1374 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1375 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1376 SIDE_PARAM(_attr), 0)
1377
1378 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1379 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1380 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1381
1382 #define side_declare_event(_identifier) \
1383 extern uintptr_t side_event_enable_##_identifier; \
1384 extern struct side_event_description _identifier
1385
1386 extern const struct side_callback side_empty_callback;
1387
1388 void side_call(const struct side_event_description *desc,
1389 const struct side_arg_vec_description *sav_desc);
1390 void side_call_variadic(const struct side_event_description *desc,
1391 const struct side_arg_vec_description *sav_desc,
1392 const struct side_arg_dynamic_event_struct *var_struct);
1393
1394 int side_tracer_callback_register(struct side_event_description *desc,
1395 void (*call)(const struct side_event_description *desc,
1396 const struct side_arg_vec_description *sav_desc,
1397 void *priv),
1398 void *priv);
1399 int side_tracer_callback_variadic_register(struct side_event_description *desc,
1400 void (*call_variadic)(const struct side_event_description *desc,
1401 const struct side_arg_vec_description *sav_desc,
1402 const struct side_arg_dynamic_event_struct *var_struct,
1403 void *priv),
1404 void *priv);
1405 int side_tracer_callback_unregister(struct side_event_description *desc,
1406 void (*call)(const struct side_event_description *desc,
1407 const struct side_arg_vec_description *sav_desc,
1408 void *priv),
1409 void *priv);
1410 int side_tracer_callback_variadic_unregister(struct side_event_description *desc,
1411 void (*call_variadic)(const struct side_event_description *desc,
1412 const struct side_arg_vec_description *sav_desc,
1413 const struct side_arg_dynamic_event_struct *var_struct,
1414 void *priv),
1415 void *priv);
1416
1417 struct side_events_register_handle *side_events_register(struct side_event_description **events, uint32_t nr_events);
1418 void side_events_unregister(struct side_events_register_handle *handle);
1419
1420 enum side_tracer_notification {
1421 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS,
1422 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS,
1423 };
1424
1425 /* Callback is invoked with side library internal lock held. */
1426 struct side_tracer_handle *side_tracer_event_notification_register(
1427 void (*cb)(enum side_tracer_notification notif,
1428 struct side_event_description **events, uint32_t nr_events, void *priv),
1429 void *priv);
1430 void side_tracer_event_notification_unregister(struct side_tracer_handle *handle);
1431
1432 void side_init(void);
1433 void side_exit(void);
1434
1435 /*
1436 * These weak symbols, the constructor, and destructor take care of
1437 * registering only _one_ instance of the side instrumentation per
1438 * shared-ojbect (or for the whole main program).
1439 */
1440 extern struct side_event_description * __start_side_event_description_ptr[]
1441 __attribute__((weak, visibility("hidden")));
1442 extern struct side_event_description * __stop_side_event_description_ptr[]
1443 __attribute__((weak, visibility("hidden")));
1444 int side_event_description_ptr_registered
1445 __attribute__((weak, visibility("hidden")));
1446 struct side_events_register_handle *side_events_handle
1447 __attribute__((weak, visibility("hidden")));
1448
1449 static void
1450 side_event_description_ptr_init(void)
1451 __attribute__((no_instrument_function))
1452 __attribute__((constructor));
1453 static void
1454 side_event_description_ptr_init(void)
1455 {
1456 if (side_event_description_ptr_registered++)
1457 return;
1458 side_events_handle = side_events_register(__start_side_event_description_ptr,
1459 __stop_side_event_description_ptr - __start_side_event_description_ptr);
1460 }
1461
1462 static void
1463 side_event_description_ptr_exit(void)
1464 __attribute__((no_instrument_function))
1465 __attribute__((destructor));
1466 static void
1467 side_event_description_ptr_exit(void)
1468 {
1469 if (--side_event_description_ptr_registered)
1470 return;
1471 side_events_unregister(side_events_handle);
1472 side_events_handle = NULL;
1473 }
1474
1475 #endif /* _SIDE_TRACE_H */
This page took 0.058906 seconds and 5 git commands to generate.