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