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