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