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