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