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