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