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