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