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