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