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