Remove byte order from basic 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 } side_basic;
324
325 struct side_type_integer side_integer;
326 struct side_type_float side_float;
327
328 /* Compound types */
329 struct {
330 const struct side_type_description *elem_type;
331 const struct side_attr *attr;
332 uint32_t length;
333 uint32_t nr_attr;
334 } side_array;
335 struct {
336 const struct side_type_description *elem_type;
337 const struct side_attr *attr;
338 uint32_t nr_attr;
339 } side_vla;
340 struct {
341 const struct side_type_description *elem_type;
342 side_visitor visitor;
343 const struct side_attr *attr;
344 uint32_t nr_attr;
345 } side_vla_visitor;
346 const struct side_type_struct *side_struct;
347 const struct side_type_struct_sg *side_struct_sg;
348
349 /* Enumeration types */
350 struct {
351 const struct side_enum_mappings *mappings;
352 const struct side_type_description *elem_type;
353 } side_enum;
354 struct {
355 const struct side_enum_bitmap_mappings *mappings;
356 const struct side_type_description *elem_type;
357 } side_enum_bitmap;
358 } u;
359 };
360
361 struct side_event_field {
362 const char *field_name;
363 struct side_type_description side_type;
364 };
365
366 enum side_event_flags {
367 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
368 };
369
370 struct side_callback {
371 union {
372 void (*call)(const struct side_event_description *desc,
373 const struct side_arg_vec_description *sav_desc,
374 void *priv);
375 void (*call_variadic)(const struct side_event_description *desc,
376 const struct side_arg_vec_description *sav_desc,
377 const struct side_arg_dynamic_event_struct *var_struct,
378 void *priv);
379 } u;
380 void *priv;
381 };
382
383 struct side_event_description {
384 uintptr_t *enabled;
385 const char *provider_name;
386 const char *event_name;
387 const struct side_event_field *fields;
388 const struct side_attr *attr;
389 const struct side_callback *callbacks;
390 uint64_t flags;
391 uint32_t version;
392 uint32_t loglevel; /* enum side_loglevel */
393 uint32_t nr_fields;
394 uint32_t nr_attr;
395 uint32_t nr_callbacks;
396 };
397
398 struct side_arg_dynamic_vec {
399 uint32_t dynamic_type; /* enum side_dynamic_type */
400 union {
401 /* Basic types */
402 struct {
403 const struct side_attr *attr;
404 uint32_t nr_attr;
405 union {
406 uint8_t side_bool;
407 uint8_t side_byte;
408 uint64_t string; /* const char * */
409 } u;
410 } side_basic;
411
412 /* Integer type */
413 struct {
414 struct side_type_integer type;
415 union side_integer_value value;
416 } side_integer;
417
418 struct {
419 struct side_type_float type;
420 union side_float_value value;
421 } side_float;
422
423 /* Compound types */
424 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
425 struct {
426 void *app_ctx;
427 side_dynamic_struct_visitor visitor;
428 const struct side_attr *attr;
429 uint32_t nr_attr;
430 } side_dynamic_struct_visitor;
431 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
432 struct {
433 void *app_ctx;
434 side_dynamic_vla_visitor visitor;
435 const struct side_attr *attr;
436 uint32_t nr_attr;
437 } side_dynamic_vla_visitor;
438 } u;
439 };
440
441 struct side_arg_dynamic_vec_vla {
442 const struct side_arg_dynamic_vec *sav;
443 const struct side_attr *attr;
444 uint32_t len;
445 uint32_t nr_attr;
446 };
447
448 struct side_arg_dynamic_event_field {
449 const char *field_name;
450 const struct side_arg_dynamic_vec elem;
451 };
452
453 struct side_arg_dynamic_event_struct {
454 const struct side_arg_dynamic_event_field *fields;
455 const struct side_attr *attr;
456 uint32_t len;
457 uint32_t nr_attr;
458 };
459
460 struct side_arg_vec {
461 enum side_type type;
462 union {
463 /* Integer types */
464 union side_integer_value integer_value;
465
466 /* Basic types */
467 union side_float_value float_value;
468 uint8_t side_bool;
469 uint8_t side_byte;
470 uint64_t string; /* const char * */
471
472 /* Compound types */
473 const struct side_arg_vec_description *side_struct;
474 const struct side_arg_vec_description *side_array;
475 const struct side_arg_vec_description *side_vla;
476 void *side_vla_app_visitor_ctx;
477 void *side_array_fixint;
478 struct {
479 void *p;
480 uint32_t length;
481 } side_vla_fixint;
482 void *side_struct_sg_ptr;
483
484 /* Dynamic type */
485 struct side_arg_dynamic_vec dynamic;
486 } u;
487 };
488
489 struct side_arg_vec_description {
490 const struct side_arg_vec *sav;
491 uint32_t len;
492 };
493
494 /* The visitor pattern is a double-dispatch visitor. */
495 struct side_tracer_visitor_ctx {
496 enum side_visitor_status (*write_elem)(
497 const struct side_tracer_visitor_ctx *tracer_ctx,
498 const struct side_arg_vec *elem);
499 void *priv; /* Private tracer context. */
500 };
501
502 struct side_tracer_dynamic_struct_visitor_ctx {
503 enum side_visitor_status (*write_field)(
504 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
505 const struct side_arg_dynamic_event_field *dynamic_field);
506 void *priv; /* Private tracer context. */
507 };
508
509 struct side_tracer_dynamic_vla_visitor_ctx {
510 enum side_visitor_status (*write_elem)(
511 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
512 const struct side_arg_dynamic_vec *elem);
513 void *priv; /* Private tracer context. */
514 };
515
516 /* Event and type attributes */
517
518 #if SIDE_BITS_PER_LONG == 64
519 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64
520 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64
521 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64
522 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER64
523 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64
524 # define SIDE_PTR_HOST .side_u64
525 #else
526 # define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32
527 # define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32
528 # define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32
529 # define SIDE_DYNAMIC_TYPE_POINTER_HOST SIDE_DYNAMIC_TYPE_POINTER32
530 # define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32
531 # define SIDE_PTR_HOST .side_u32
532 #endif
533
534 #define side_attr(_key, _value) \
535 { \
536 .key = _key, \
537 .value = SIDE_PARAM(_value), \
538 }
539
540 #define side_attr_list(...) \
541 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
542
543 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
544 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
545 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
546 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
547 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
548 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
549 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
550 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
551 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
552 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
553 #define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } }
554 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
555 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
556 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
557 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
558 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (uintptr_t) (_val) } }
559
560 /* Static field definition */
561
562 #define _side_type_basic(_type, _attr) \
563 { \
564 .type = _type, \
565 .u = { \
566 .side_basic = { \
567 .attr = _attr, \
568 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
569 }, \
570 }, \
571 }
572
573 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
574 { \
575 .type = _type, \
576 .u = { \
577 .side_integer = { \
578 .attr = _attr, \
579 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
580 .integer_size_bits = _integer_size_bits, \
581 .len_bits = _len_bits, \
582 .signedness = _signedness, \
583 .byte_order = _byte_order, \
584 }, \
585 }, \
586 }
587
588 #define _side_type_float(_type, _byte_order, _float_size_bits, _attr) \
589 { \
590 .type = _type, \
591 .u = { \
592 .side_float = { \
593 .attr = _attr, \
594 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
595 .byte_order = _byte_order, \
596 .float_size_bits = _float_size_bits, \
597 }, \
598 }, \
599 }
600
601 #define _side_field(_name, _type) \
602 { \
603 .field_name = _name, \
604 .side_type = _type, \
605 }
606
607 /* Host endian */
608 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_PARAM(_attr))
609 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
610 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
611 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
612 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
613 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
614 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr))
615 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr))
616 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr))
617 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_PARAM(_attr))
618 #define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_BITS_PER_LONG, \
619 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
620 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 16, SIDE_PARAM(_attr))
621 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 32, SIDE_PARAM(_attr))
622 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 64, SIDE_PARAM(_attr))
623 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 128, SIDE_PARAM(_attr))
624 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_PARAM(_attr))
625 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_PARAM(_attr))
626
627 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
628 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
629 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
630 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
631 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
632 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
633 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
634 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
635 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
636 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
637 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
638 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
639 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
640 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
641 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
642 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
643 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
644
645 /* Little endian */
646 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
647 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
648 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
649 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr))
650 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr))
651 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr))
652 #define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_LE, SIDE_BITS_PER_LONG, \
653 SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
654 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, 16, SIDE_PARAM(_attr))
655 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, 32, SIDE_PARAM(_attr))
656 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, 64, SIDE_PARAM(_attr))
657 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 128, SIDE_PARAM(_attr))
658
659 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
660 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
661 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
662 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
663 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
664 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
665 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
666 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
667 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
668 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
669 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
670
671 /* Big endian */
672 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
673 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
674 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
675 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr))
676 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr))
677 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr))
678 #define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_BE, SIDE_BITS_PER_LONG, \
679 SIDE_BITS_PER_LONG, 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 }, \
936 }, \
937 }
938
939 #define side_arg_dynamic_bool(_val, _attr) \
940 { \
941 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
942 .u = { \
943 .side_basic = { \
944 .attr = _attr, \
945 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
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 .u = { \
961 .side_byte = (_val), \
962 }, \
963 }, \
964 }, \
965 }
966 #define side_arg_dynamic_string(_val, _attr) \
967 { \
968 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
969 .u = { \
970 .side_basic = { \
971 .attr = _attr, \
972 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
973 .u = { \
974 .string = (uintptr_t) (_val), \
975 }, \
976 }, \
977 }, \
978 }
979
980 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \
981 { \
982 .dynamic_type = _type, \
983 .u = { \
984 .side_integer = { \
985 .type = { \
986 .attr = _attr, \
987 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
988 .integer_size_bits = _integer_size_bits, \
989 .len_bits = _len_bits, \
990 .signedness = _signedness, \
991 .byte_order = _byte_order, \
992 }, \
993 .value = { \
994 _field = (_val), \
995 }, \
996 }, \
997 }, \
998 }
999
1000 #define side_arg_dynamic_u8(_val, _attr) \
1001 _side_arg_dynamic_integer(.side_u8, _val, SIDE_DYNAMIC_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1002 #define side_arg_dynamic_s8(_val, _attr) \
1003 _side_arg_dynamic_integer(.side_s8, _val, SIDE_DYNAMIC_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr))
1004
1005 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1006 _side_arg_dynamic_integer(.side_u16, _val, SIDE_DYNAMIC_TYPE_U16, false, _byte_order, 16, 16, SIDE_PARAM(_attr))
1007 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1008 _side_arg_dynamic_integer(.side_u32, _val, SIDE_DYNAMIC_TYPE_U32, false, _byte_order, 32, 32, SIDE_PARAM(_attr))
1009 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1010 _side_arg_dynamic_integer(.side_u64, _val, SIDE_DYNAMIC_TYPE_U64, false, _byte_order, 64, 64, SIDE_PARAM(_attr))
1011
1012 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1013 _side_arg_dynamic_integer(.side_s16, _val, SIDE_DYNAMIC_TYPE_S16, true, _byte_order, 16, 16, SIDE_PARAM(_attr))
1014 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1015 _side_arg_dynamic_integer(.side_s32, _val, SIDE_DYNAMIC_TYPE_S32, true, _byte_order, 32, 32, SIDE_PARAM(_attr))
1016 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1017 _side_arg_dynamic_integer(.side_s64, _val, SIDE_DYNAMIC_TYPE_S64, true, _byte_order, 64, 64, SIDE_PARAM(_attr))
1018
1019 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1020 _side_arg_dynamic_integer(SIDE_PTR_HOST, (uintptr_t) (_val), SIDE_DYNAMIC_TYPE_POINTER_HOST, false, _byte_order, \
1021 SIDE_BITS_PER_LONG, SIDE_BITS_PER_LONG, SIDE_PARAM(_attr))
1022
1023 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size_bits, _attr) \
1024 { \
1025 .dynamic_type = _type, \
1026 .u = { \
1027 .side_float = { \
1028 .type = { \
1029 .attr = _attr, \
1030 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1031 .byte_order = _byte_order, \
1032 .float_size_bits = _float_size_bits, \
1033 }, \
1034 .value = { \
1035 _field = (_val), \
1036 }, \
1037 }, \
1038 }, \
1039 }
1040
1041 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1042 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, _byte_order, 16, SIDE_PARAM(_attr))
1043 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1044 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, _byte_order, 32, SIDE_PARAM(_attr))
1045 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1046 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, _byte_order, 64, SIDE_PARAM(_attr))
1047 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1048 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, _byte_order, 128, SIDE_PARAM(_attr))
1049
1050 /* Host endian */
1051 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1052 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1053 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1054 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1055 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1056 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1057 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1058 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1059 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1060 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1061 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1062
1063 /* Little endian */
1064 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1065 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1066 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1067 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1068 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1069 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1070 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1071 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1072 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1073 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1074 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1075
1076 /* Big endian */
1077 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1078 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1079 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1080 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1081 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1082 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1083 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1084 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1085 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1086 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1087 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1088
1089 #define side_arg_dynamic_vla(_vla) \
1090 { \
1091 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1092 .u = { \
1093 .side_dynamic_vla = (_vla), \
1094 }, \
1095 }
1096
1097 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1098 { \
1099 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1100 .u = { \
1101 .side_dynamic_vla_visitor = { \
1102 .app_ctx = _ctx, \
1103 .visitor = _dynamic_vla_visitor, \
1104 .attr = _attr, \
1105 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1106 }, \
1107 }, \
1108 }
1109
1110 #define side_arg_dynamic_struct(_struct) \
1111 { \
1112 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1113 .u = { \
1114 .side_dynamic_struct = (_struct), \
1115 }, \
1116 }
1117
1118 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1119 { \
1120 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1121 .u = { \
1122 .side_dynamic_struct_visitor = { \
1123 .app_ctx = _ctx, \
1124 .visitor = _dynamic_struct_visitor, \
1125 .attr = _attr, \
1126 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1127 }, \
1128 }, \
1129 }
1130
1131 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1132 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1133 const struct side_arg_dynamic_vec_vla _identifier = { \
1134 .sav = _identifier##_vec, \
1135 .attr = _attr, \
1136 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1137 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1138 }
1139
1140 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1141 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1142 const struct side_arg_dynamic_event_struct _identifier = { \
1143 .fields = _identifier##_fields, \
1144 .attr = _attr, \
1145 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1146 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1147 }
1148
1149 #define side_arg_define_vec(_identifier, _sav) \
1150 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1151 const struct side_arg_vec_description _identifier = { \
1152 .sav = _identifier##_vec, \
1153 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1154 }
1155
1156 #define side_arg_dynamic_field(_name, _elem) \
1157 { \
1158 .field_name = _name, \
1159 .elem = _elem, \
1160 }
1161
1162 #define side_arg_list(...) __VA_ARGS__
1163
1164 #define side_define_enum(_identifier, _mappings, _attr) \
1165 const struct side_enum_mappings _identifier = { \
1166 .mappings = _mappings, \
1167 .attr = _attr, \
1168 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1169 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1170 }
1171
1172 #define side_enum_mapping_list(...) \
1173 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1174
1175 #define side_enum_mapping_range(_label, _begin, _end) \
1176 { \
1177 .range_begin = _begin, \
1178 .range_end = _end, \
1179 .label = _label, \
1180 }
1181
1182 #define side_enum_mapping_value(_label, _value) \
1183 { \
1184 .range_begin = _value, \
1185 .range_end = _value, \
1186 .label = _label, \
1187 }
1188
1189 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1190 const struct side_enum_bitmap_mappings _identifier = { \
1191 .mappings = _mappings, \
1192 .attr = _attr, \
1193 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1194 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1195 }
1196
1197 #define side_enum_bitmap_mapping_list(...) \
1198 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1199
1200 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1201 { \
1202 .range_begin = _begin, \
1203 .range_end = _end, \
1204 .label = _label, \
1205 }
1206
1207 #define side_enum_bitmap_mapping_value(_label, _value) \
1208 { \
1209 .range_begin = _value, \
1210 .range_end = _value, \
1211 .label = _label, \
1212 }
1213
1214 #define side_event_cond(_identifier) \
1215 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1216 __ATOMIC_RELAXED)))
1217
1218 #define side_event_call(_identifier, _sav) \
1219 { \
1220 const struct side_arg_vec side_sav[] = { _sav }; \
1221 const struct side_arg_vec_description sav_desc = { \
1222 .sav = side_sav, \
1223 .len = SIDE_ARRAY_SIZE(side_sav), \
1224 }; \
1225 side_call(&(_identifier), &sav_desc); \
1226 }
1227
1228 #define side_event(_identifier, _sav) \
1229 side_event_cond(_identifier) \
1230 side_event_call(_identifier, SIDE_PARAM(_sav))
1231
1232 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1233 { \
1234 const struct side_arg_vec side_sav[] = { _sav }; \
1235 const struct side_arg_vec_description sav_desc = { \
1236 .sav = side_sav, \
1237 .len = SIDE_ARRAY_SIZE(side_sav), \
1238 }; \
1239 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1240 const struct side_arg_dynamic_event_struct var_struct = { \
1241 .fields = side_fields, \
1242 .attr = _attr, \
1243 .len = SIDE_ARRAY_SIZE(side_fields), \
1244 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1245 }; \
1246 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1247 }
1248
1249 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1250 side_event_cond(_identifier) \
1251 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1252
1253 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1254 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1255 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1256 _identifier = { \
1257 .enabled = &(side_event_enable__##_identifier), \
1258 .provider_name = _provider, \
1259 .event_name = _event, \
1260 .fields = _fields, \
1261 .attr = _attr, \
1262 .callbacks = &side_empty_callback, \
1263 .flags = (_flags), \
1264 .version = 0, \
1265 .loglevel = _loglevel, \
1266 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1267 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1268 .nr_callbacks = 0, \
1269 }; \
1270 static const struct side_event_description *side_event_ptr__##_identifier \
1271 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1272
1273 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1274 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1275 SIDE_PARAM(_attr), 0)
1276
1277 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1278 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1279 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1280
1281 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1282 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1283 SIDE_PARAM(_attr), 0)
1284
1285 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1286 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1287 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1288
1289 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1290 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1291 SIDE_PARAM(_attr), 0)
1292
1293 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1294 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1295 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1296
1297 #define side_declare_event(_identifier) \
1298 extern uintptr_t side_event_enable_##_identifier; \
1299 extern struct side_event_description _identifier
1300
1301 extern const struct side_callback side_empty_callback;
1302
1303 void side_call(const struct side_event_description *desc,
1304 const struct side_arg_vec_description *sav_desc);
1305 void side_call_variadic(const struct side_event_description *desc,
1306 const struct side_arg_vec_description *sav_desc,
1307 const struct side_arg_dynamic_event_struct *var_struct);
1308
1309 int side_tracer_callback_register(struct side_event_description *desc,
1310 void (*call)(const struct side_event_description *desc,
1311 const struct side_arg_vec_description *sav_desc,
1312 void *priv),
1313 void *priv);
1314 int side_tracer_callback_variadic_register(struct side_event_description *desc,
1315 void (*call_variadic)(const struct side_event_description *desc,
1316 const struct side_arg_vec_description *sav_desc,
1317 const struct side_arg_dynamic_event_struct *var_struct,
1318 void *priv),
1319 void *priv);
1320 int side_tracer_callback_unregister(struct side_event_description *desc,
1321 void (*call)(const struct side_event_description *desc,
1322 const struct side_arg_vec_description *sav_desc,
1323 void *priv),
1324 void *priv);
1325 int side_tracer_callback_variadic_unregister(struct side_event_description *desc,
1326 void (*call_variadic)(const struct side_event_description *desc,
1327 const struct side_arg_vec_description *sav_desc,
1328 const struct side_arg_dynamic_event_struct *var_struct,
1329 void *priv),
1330 void *priv);
1331
1332 struct side_events_register_handle *side_events_register(struct side_event_description **events, uint32_t nr_events);
1333 void side_events_unregister(struct side_events_register_handle *handle);
1334
1335 enum side_tracer_notification {
1336 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS,
1337 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS,
1338 };
1339
1340 /* Callback is invoked with side library internal lock held. */
1341 struct side_tracer_handle *side_tracer_event_notification_register(
1342 void (*cb)(enum side_tracer_notification notif,
1343 struct side_event_description **events, uint32_t nr_events, void *priv),
1344 void *priv);
1345 void side_tracer_event_notification_unregister(struct side_tracer_handle *handle);
1346
1347 void side_init(void);
1348 void side_exit(void);
1349
1350 /*
1351 * These weak symbols, the constructor, and destructor take care of
1352 * registering only _one_ instance of the side instrumentation per
1353 * shared-ojbect (or for the whole main program).
1354 */
1355 extern struct side_event_description * __start_side_event_description_ptr[]
1356 __attribute__((weak, visibility("hidden")));
1357 extern struct side_event_description * __stop_side_event_description_ptr[]
1358 __attribute__((weak, visibility("hidden")));
1359 int side_event_description_ptr_registered
1360 __attribute__((weak, visibility("hidden")));
1361 struct side_events_register_handle *side_events_handle
1362 __attribute__((weak, visibility("hidden")));
1363
1364 static void
1365 side_event_description_ptr_init(void)
1366 __attribute__((no_instrument_function))
1367 __attribute__((constructor));
1368 static void
1369 side_event_description_ptr_init(void)
1370 {
1371 if (side_event_description_ptr_registered++)
1372 return;
1373 side_events_handle = side_events_register(__start_side_event_description_ptr,
1374 __stop_side_event_description_ptr - __start_side_event_description_ptr);
1375 }
1376
1377 static void
1378 side_event_description_ptr_exit(void)
1379 __attribute__((no_instrument_function))
1380 __attribute__((destructor));
1381 static void
1382 side_event_description_ptr_exit(void)
1383 {
1384 if (--side_event_description_ptr_registered)
1385 return;
1386 side_events_unregister(side_events_handle);
1387 side_events_handle = NULL;
1388 }
1389
1390 #endif /* _SIDE_TRACE_H */
This page took 0.055945 seconds and 5 git commands to generate.