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