Add extern C to public headers
[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 /*
18 * SIDE stands for "Static Instrumentation Dynamically Enabled"
19 *
20 * This is an instrumentation API for Linux user-space, which exposes an
21 * instrumentation type system and facilities allowing a kernel or
22 * user-space tracer to consume user-space instrumentation.
23 *
24 * This instrumentation API exposes 3 type systems:
25 *
26 * * Stack-copy type system: This is the core type system which can
27 * represent all supported types and into which all other type systems
28 * can be nested. This type system requires that every type is
29 * statically or dynamically declared and then registered, thus giving
30 * tracers a complete description of the events and their associated
31 * fields before the associated instrumentation is invoked. The
32 * application needs to copy each argument (side_arg_...()) onto the
33 * stack when calling the instrumentation.
34 *
35 * This is the most expressive of the 3 type systems, althrough not the
36 * fastest due to the extra copy of the arguments.
37 *
38 * * Data-gathering type system: This type system requires every type to
39 * be statically or dynamically declared and registered, but does not
40 * require the application to copy its arguments onto the stack.
41 * Instead, the type description contains all the required information
42 * to fetch the data from the application memory. The only argument
43 * required from the instrumentation is the base pointer from which
44 * the data should be fetched.
45 *
46 * This type system can be used as an event field, or nested within
47 * the stack-copy type system. Nesting of gather-vla within
48 * gather-array and gather-vla types is not allowed.
49 *
50 * This type system is has the least overhead of the 3 type systems.
51 *
52 * * Dynamic type system: This type system receives both type
53 * description and actual data onto the stack at runtime. It has more
54 * overhead that the 2 other type systems, but does not require a
55 * prior registration of event field description. This makes it useful
56 * for seldom used types which are not performance critical, but for
57 * which registering each individual events would needlessly grow the
58 * number of events to declare and register.
59 *
60 * Another use-case for this type system is for use by dynamically
61 * typed language runtimes, where the field type is only known when
62 * the instrumentation is called.
63 *
64 * Those dynamic types can be either used as arguments to a variadic
65 * field list, or as on-stack instrumentation argument for a static
66 * type SIDE_TYPE_DYNAMIC place holder in the stack-copy type system.
67 */
68
69 //TODO: as those structures will be ABI, we need to either consider them
70 //fixed forever, or think of a scheme that would allow their binary
71 //representation to be extended if need be.
72
73 struct side_arg;
74 struct side_arg_vec;
75 struct side_arg_dynamic;
76 struct side_arg_dynamic_field;
77 struct side_arg_dynamic_vla;
78 struct side_type;
79 struct side_event_field;
80 struct side_tracer_visitor_ctx;
81 struct side_tracer_dynamic_struct_visitor_ctx;
82 struct side_event_description;
83 struct side_arg_dynamic_struct;
84 struct side_events_register_handle;
85
86 enum side_type_label {
87 /* Stack-copy basic types */
88 SIDE_TYPE_NULL,
89 SIDE_TYPE_BOOL,
90 SIDE_TYPE_U8,
91 SIDE_TYPE_U16,
92 SIDE_TYPE_U32,
93 SIDE_TYPE_U64,
94 SIDE_TYPE_S8,
95 SIDE_TYPE_S16,
96 SIDE_TYPE_S32,
97 SIDE_TYPE_S64,
98 SIDE_TYPE_BYTE,
99 SIDE_TYPE_POINTER,
100 SIDE_TYPE_FLOAT_BINARY16,
101 SIDE_TYPE_FLOAT_BINARY32,
102 SIDE_TYPE_FLOAT_BINARY64,
103 SIDE_TYPE_FLOAT_BINARY128,
104 SIDE_TYPE_STRING,
105
106 /* Stack-copy compound types */
107 SIDE_TYPE_STRUCT,
108 SIDE_TYPE_ARRAY,
109 SIDE_TYPE_VLA,
110 SIDE_TYPE_VLA_VISITOR,
111
112 /* Stack-copy enumeration types */
113 SIDE_TYPE_ENUM,
114 SIDE_TYPE_ENUM_BITMAP,
115
116 /* Stack-copy place holder for dynamic types */
117 SIDE_TYPE_DYNAMIC,
118
119 /* Gather basic types */
120 SIDE_TYPE_GATHER_BOOL,
121 SIDE_TYPE_GATHER_INTEGER,
122 SIDE_TYPE_GATHER_BYTE,
123 SIDE_TYPE_GATHER_POINTER,
124 SIDE_TYPE_GATHER_FLOAT,
125
126 /* Gather compound types */
127 SIDE_TYPE_GATHER_STRUCT,
128 SIDE_TYPE_GATHER_ARRAY,
129 SIDE_TYPE_GATHER_VLA,
130
131 /* Dynamic basic types */
132 SIDE_TYPE_DYNAMIC_NULL,
133 SIDE_TYPE_DYNAMIC_BOOL,
134 SIDE_TYPE_DYNAMIC_INTEGER,
135 SIDE_TYPE_DYNAMIC_BYTE,
136 SIDE_TYPE_DYNAMIC_POINTER,
137 SIDE_TYPE_DYNAMIC_FLOAT,
138 SIDE_TYPE_DYNAMIC_STRING,
139
140 /* Dynamic compound types */
141 SIDE_TYPE_DYNAMIC_STRUCT,
142 SIDE_TYPE_DYNAMIC_STRUCT_VISITOR,
143 SIDE_TYPE_DYNAMIC_VLA,
144 SIDE_TYPE_DYNAMIC_VLA_VISITOR,
145 };
146
147 enum side_attr_type {
148 SIDE_ATTR_TYPE_NULL,
149 SIDE_ATTR_TYPE_BOOL,
150 SIDE_ATTR_TYPE_U8,
151 SIDE_ATTR_TYPE_U16,
152 SIDE_ATTR_TYPE_U32,
153 SIDE_ATTR_TYPE_U64,
154 SIDE_ATTR_TYPE_S8,
155 SIDE_ATTR_TYPE_S16,
156 SIDE_ATTR_TYPE_S32,
157 SIDE_ATTR_TYPE_S64,
158 SIDE_ATTR_TYPE_FLOAT_BINARY16,
159 SIDE_ATTR_TYPE_FLOAT_BINARY32,
160 SIDE_ATTR_TYPE_FLOAT_BINARY64,
161 SIDE_ATTR_TYPE_FLOAT_BINARY128,
162 SIDE_ATTR_TYPE_STRING,
163 };
164
165 enum side_loglevel {
166 SIDE_LOGLEVEL_EMERG = 0,
167 SIDE_LOGLEVEL_ALERT = 1,
168 SIDE_LOGLEVEL_CRIT = 2,
169 SIDE_LOGLEVEL_ERR = 3,
170 SIDE_LOGLEVEL_WARNING = 4,
171 SIDE_LOGLEVEL_NOTICE = 5,
172 SIDE_LOGLEVEL_INFO = 6,
173 SIDE_LOGLEVEL_DEBUG = 7,
174 };
175
176 enum side_visitor_status {
177 SIDE_VISITOR_STATUS_OK = 0,
178 SIDE_VISITOR_STATUS_ERROR = -1,
179 };
180
181 enum side_error {
182 SIDE_ERROR_OK = 0,
183 SIDE_ERROR_INVAL = 1,
184 SIDE_ERROR_EXIST = 2,
185 SIDE_ERROR_NOMEM = 3,
186 SIDE_ERROR_NOENT = 4,
187 SIDE_ERROR_EXITING = 5,
188 };
189
190 enum side_type_label_byte_order {
191 SIDE_TYPE_BYTE_ORDER_LE = 0,
192 SIDE_TYPE_BYTE_ORDER_BE = 1,
193 };
194
195 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
196 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
197 #else
198 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
199 #endif
200
201 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
202 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
203 #else
204 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
205 #endif
206
207 enum side_type_gather_access_mode {
208 SIDE_TYPE_GATHER_ACCESS_DIRECT,
209 SIDE_TYPE_GATHER_ACCESS_POINTER, /* Pointer dereference */
210 };
211
212 typedef enum side_visitor_status (*side_visitor_func)(
213 const struct side_tracer_visitor_ctx *tracer_ctx,
214 void *app_ctx);
215 typedef enum side_visitor_status (*side_dynamic_struct_visitor_func)(
216 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
217 void *app_ctx);
218
219 union side_integer_value {
220 uint8_t side_u8;
221 uint16_t side_u16;
222 uint32_t side_u32;
223 uint64_t side_u64;
224 int8_t side_s8;
225 int16_t side_s16;
226 int32_t side_s32;
227 int64_t side_s64;
228 uintptr_t side_uptr;
229 } SIDE_PACKED;
230
231 union side_bool_value {
232 uint8_t side_bool8;
233 uint16_t side_bool16;
234 uint32_t side_bool32;
235 uint64_t side_bool64;
236 } SIDE_PACKED;
237
238 union side_float_value {
239 #if __HAVE_FLOAT16
240 _Float16 side_float_binary16;
241 #endif
242 #if __HAVE_FLOAT32
243 _Float32 side_float_binary32;
244 #endif
245 #if __HAVE_FLOAT64
246 _Float64 side_float_binary64;
247 #endif
248 #if __HAVE_FLOAT128
249 _Float128 side_float_binary128;
250 #endif
251 } SIDE_PACKED;
252
253 struct side_attr_value {
254 uint32_t type; /* enum side_attr_type */
255 union {
256 uint8_t bool_value;
257 uint64_t string_value; /* const char * */
258 union side_integer_value integer_value;
259 union side_float_value float_value;
260 } SIDE_PACKED u;
261 };
262
263 /* User attributes. */
264 struct side_attr {
265 const char *key;
266 const struct side_attr_value value;
267 } SIDE_PACKED;
268
269 /* Type descriptions */
270 struct side_type_null {
271 const struct side_attr *attr;
272 uint32_t nr_attr;
273 } SIDE_PACKED;
274
275 struct side_type_bool {
276 const struct side_attr *attr;
277 uint32_t nr_attr;
278 uint16_t bool_size; /* bytes */
279 uint16_t len_bits; /* bits. 0 for (bool_size * CHAR_BITS) */
280 uint8_t byte_order; /* enum side_type_label_byte_order */
281 } SIDE_PACKED;
282
283 struct side_type_byte {
284 const struct side_attr *attr;
285 uint32_t nr_attr;
286 } SIDE_PACKED;
287
288 struct side_type_string {
289 const struct side_attr *attr;
290 uint32_t nr_attr;
291 } SIDE_PACKED;
292
293 struct side_type_integer {
294 const struct side_attr *attr;
295 uint32_t nr_attr;
296 uint16_t integer_size; /* bytes */
297 uint16_t len_bits; /* bits. 0 for (integer_size * CHAR_BITS) */
298 uint8_t signedness; /* true/false */
299 uint8_t byte_order; /* enum side_type_label_byte_order */
300 } SIDE_PACKED;
301
302 struct side_type_float {
303 const struct side_attr *attr;
304 uint32_t nr_attr;
305 uint16_t float_size; /* bytes */
306 uint8_t byte_order; /* enum side_type_label_byte_order */
307 } SIDE_PACKED;
308
309 struct side_enum_mapping {
310 int64_t range_begin;
311 int64_t range_end;
312 const char *label;
313 } SIDE_PACKED;
314
315 struct side_enum_mappings {
316 const struct side_enum_mapping *mappings;
317 const struct side_attr *attr;
318 uint32_t nr_mappings;
319 uint32_t nr_attr;
320 } SIDE_PACKED;
321
322 struct side_enum_bitmap_mapping {
323 uint64_t range_begin;
324 uint64_t range_end;
325 const char *label;
326 } SIDE_PACKED;
327
328 struct side_enum_bitmap_mappings {
329 const struct side_enum_bitmap_mapping *mappings;
330 const struct side_attr *attr;
331 uint32_t nr_mappings;
332 uint32_t nr_attr;
333 } SIDE_PACKED;
334
335 struct side_type_struct {
336 const struct side_event_field *fields;
337 const struct side_attr *attr;
338 uint32_t nr_fields;
339 uint32_t nr_attr;
340 } SIDE_PACKED;
341
342 struct side_type_array {
343 const struct side_type *elem_type;
344 const struct side_attr *attr;
345 uint32_t length;
346 uint32_t nr_attr;
347 } SIDE_PACKED;
348
349 struct side_type_vla {
350 const struct side_type *elem_type;
351 const struct side_attr *attr;
352 uint32_t nr_attr;
353 } SIDE_PACKED;
354
355 struct side_type_vla_visitor {
356 const struct side_type *elem_type;
357 side_visitor_func visitor;
358 const struct side_attr *attr;
359 uint32_t nr_attr;
360 } SIDE_PACKED;
361
362 struct side_type_enum {
363 const struct side_enum_mappings *mappings;
364 const struct side_type *elem_type;
365 } SIDE_PACKED;
366
367 struct side_type_enum_bitmap {
368 const struct side_enum_bitmap_mappings *mappings;
369 const struct side_type *elem_type;
370 } SIDE_PACKED;
371
372 struct side_type_gather_bool {
373 uint64_t offset; /* bytes */
374 uint8_t access_mode; /* enum side_type_gather_access_mode */
375 struct side_type_bool type;
376 uint16_t offset_bits; /* bits */
377 } SIDE_PACKED;
378
379 struct side_type_gather_byte {
380 uint64_t offset; /* bytes */
381 uint8_t access_mode; /* enum side_type_gather_access_mode */
382 struct side_type_byte type;
383 } SIDE_PACKED;
384
385 struct side_type_gather_integer {
386 uint64_t offset; /* bytes */
387 uint8_t access_mode; /* enum side_type_gather_access_mode */
388 struct side_type_integer type;
389 uint16_t offset_bits; /* bits */
390 } SIDE_PACKED;
391
392 struct side_type_gather_float {
393 uint64_t offset; /* bytes */
394 uint8_t access_mode; /* enum side_type_gather_access_mode */
395 struct side_type_float type;
396 } SIDE_PACKED;
397
398 struct side_type_gather_struct {
399 uint64_t offset; /* bytes */
400 uint8_t access_mode; /* enum side_type_gather_access_mode */
401 const struct side_type_struct *type;
402 uint32_t size; /* bytes */
403 } SIDE_PACKED;
404
405 struct side_type_gather_array {
406 uint64_t offset; /* bytes */
407 uint8_t access_mode; /* enum side_type_gather_access_mode */
408 struct side_type_array type;
409 } SIDE_PACKED;
410
411 struct side_type_gather_vla {
412 const struct side_type *length_type; /* side_length() */
413
414 uint64_t offset; /* bytes */
415 uint8_t access_mode; /* enum side_type_gather_access_mode */
416 struct side_type_vla type;
417 } SIDE_PACKED;
418
419 struct side_type_gather {
420 union {
421 struct side_type_gather_bool side_bool;
422 struct side_type_gather_byte side_byte;
423 struct side_type_gather_integer side_integer;
424 struct side_type_gather_float side_float;
425 struct side_type_gather_array side_array;
426 struct side_type_gather_vla side_vla;
427 struct side_type_gather_struct side_struct;
428 } SIDE_PACKED u;
429 } SIDE_PACKED;
430
431 struct side_type {
432 uint32_t type; /* enum side_type_label */
433 union {
434 /* Stack-copy basic types */
435 struct side_type_null side_null;
436 struct side_type_bool side_bool;
437 struct side_type_byte side_byte;
438 struct side_type_string side_string;
439 struct side_type_integer side_integer;
440 struct side_type_float side_float;
441
442 /* Stack-copy compound types */
443 struct side_type_array side_array;
444 struct side_type_vla side_vla;
445 struct side_type_vla_visitor side_vla_visitor;
446 const struct side_type_struct *side_struct;
447
448 /* Stack-copy enumeration types */
449 struct side_type_enum side_enum;
450 struct side_type_enum_bitmap side_enum_bitmap;
451
452 /* Gather types */
453 struct side_type_gather side_gather;
454 } SIDE_PACKED u;
455 } SIDE_PACKED;
456
457 struct side_event_field {
458 const char *field_name;
459 struct side_type side_type;
460 } SIDE_PACKED;
461
462 enum side_event_flags {
463 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
464 };
465
466 struct side_callback {
467 union {
468 void (*call)(const struct side_event_description *desc,
469 const struct side_arg_vec *side_arg_vec,
470 void *priv);
471 void (*call_variadic)(const struct side_event_description *desc,
472 const struct side_arg_vec *side_arg_vec,
473 const struct side_arg_dynamic_struct *var_struct,
474 void *priv);
475 } SIDE_PACKED u;
476 void *priv;
477 } SIDE_PACKED;
478
479 struct side_arg_static {
480 /* Stack-copy basic types */
481 union side_bool_value bool_value;
482 uint8_t byte_value;
483 uint64_t string_value; /* const char * */
484 union side_integer_value integer_value;
485 union side_float_value float_value;
486
487 /* Stack-copy compound types */
488 const struct side_arg_vec *side_struct;
489 const struct side_arg_vec *side_array;
490 const struct side_arg_vec *side_vla;
491 void *side_vla_app_visitor_ctx;
492
493 /* Gather basic types */
494 void *side_bool_gather_ptr;
495 void *side_byte_gather_ptr;
496 void *side_integer_gather_ptr;
497 void *side_float_gather_ptr;
498
499 /* Gather compound types */
500 void *side_array_gather_ptr;
501 void *side_struct_gather_ptr;
502 struct {
503 void *ptr;
504 void *length_ptr;
505 } SIDE_PACKED side_vla_gather;
506 } SIDE_PACKED;
507
508 struct side_arg_dynamic_vla {
509 const struct side_arg *sav;
510 const struct side_attr *attr;
511 uint32_t len;
512 uint32_t nr_attr;
513 } SIDE_PACKED;
514
515 struct side_arg_dynamic_struct {
516 const struct side_arg_dynamic_field *fields;
517 const struct side_attr *attr;
518 uint32_t len;
519 uint32_t nr_attr;
520 } SIDE_PACKED;
521
522 struct side_dynamic_struct_visitor {
523 void *app_ctx;
524 side_dynamic_struct_visitor_func visitor;
525 const struct side_attr *attr;
526 uint32_t nr_attr;
527 } SIDE_PACKED;
528
529 struct side_dynamic_vla_visitor {
530 void *app_ctx;
531 side_visitor_func visitor;
532 const struct side_attr *attr;
533 uint32_t nr_attr;
534 } SIDE_PACKED;
535
536 struct side_arg_dynamic {
537 /* Dynamic basic types */
538 struct side_type_null side_null;
539 struct {
540 struct side_type_bool type;
541 union side_bool_value value;
542 } SIDE_PACKED side_bool;
543 struct {
544 struct side_type_byte type;
545 uint8_t value;
546 } SIDE_PACKED side_byte;
547 struct {
548 struct side_type_string type;
549 uint64_t value; /* const char * */
550 } SIDE_PACKED side_string;
551 struct {
552 struct side_type_integer type;
553 union side_integer_value value;
554 } SIDE_PACKED side_integer;
555 struct {
556 struct side_type_float type;
557 union side_float_value value;
558 } SIDE_PACKED side_float;
559
560 /* Dynamic compound types */
561 const struct side_arg_dynamic_struct *side_dynamic_struct;
562 const struct side_arg_dynamic_vla *side_dynamic_vla;
563
564 struct side_dynamic_struct_visitor side_dynamic_struct_visitor;
565 struct side_dynamic_vla_visitor side_dynamic_vla_visitor;
566 } SIDE_PACKED;
567
568 struct side_arg {
569 uint32_t type; /* enum side_type_label */
570 union {
571 struct side_arg_static side_static;
572 struct side_arg_dynamic side_dynamic;
573 } SIDE_PACKED u;
574 } SIDE_PACKED;
575
576 struct side_arg_vec {
577 const struct side_arg *sav;
578 uint32_t len;
579 } SIDE_PACKED;
580
581 struct side_arg_dynamic_field {
582 const char *field_name;
583 const struct side_arg elem;
584 } SIDE_PACKED;
585
586 /* The visitor pattern is a double-dispatch visitor. */
587 struct side_tracer_visitor_ctx {
588 enum side_visitor_status (*write_elem)(
589 const struct side_tracer_visitor_ctx *tracer_ctx,
590 const struct side_arg *elem);
591 void *priv; /* Private tracer context. */
592 } SIDE_PACKED;
593
594 struct side_tracer_dynamic_struct_visitor_ctx {
595 enum side_visitor_status (*write_field)(
596 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
597 const struct side_arg_dynamic_field *dynamic_field);
598 void *priv; /* Private tracer context. */
599 } SIDE_PACKED;
600
601 struct side_event_description {
602 uintptr_t *enabled;
603 const char *provider_name;
604 const char *event_name;
605 const struct side_event_field *fields;
606 const struct side_attr *attr;
607 const struct side_callback *callbacks;
608 uint64_t flags;
609 uint32_t version;
610 uint32_t loglevel; /* enum side_loglevel */
611 uint32_t nr_fields;
612 uint32_t nr_attr;
613 uint32_t nr_callbacks;
614 } SIDE_PACKED;
615
616 /* Event and type attributes */
617
618 #define side_attr(_key, _value) \
619 { \
620 .key = _key, \
621 .value = SIDE_PARAM(_value), \
622 }
623
624 #define side_attr_list(...) \
625 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
626
627 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
628 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
629 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
630 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
631 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
632 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
633 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
634 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
635 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
636 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
637 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
638 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
639 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
640 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
641 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string_value = (uintptr_t) (_val) } }
642
643 /* Stack-copy enumeration type definitions */
644
645 #define side_define_enum(_identifier, _mappings, _attr) \
646 const struct side_enum_mappings _identifier = { \
647 .mappings = _mappings, \
648 .attr = _attr, \
649 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
650 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
651 }
652
653 #define side_enum_mapping_list(...) \
654 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
655
656 #define side_enum_mapping_range(_label, _begin, _end) \
657 { \
658 .range_begin = _begin, \
659 .range_end = _end, \
660 .label = _label, \
661 }
662
663 #define side_enum_mapping_value(_label, _value) \
664 { \
665 .range_begin = _value, \
666 .range_end = _value, \
667 .label = _label, \
668 }
669
670 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
671 const struct side_enum_bitmap_mappings _identifier = { \
672 .mappings = _mappings, \
673 .attr = _attr, \
674 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
675 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
676 }
677
678 #define side_enum_bitmap_mapping_list(...) \
679 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
680
681 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
682 { \
683 .range_begin = _begin, \
684 .range_end = _end, \
685 .label = _label, \
686 }
687
688 #define side_enum_bitmap_mapping_value(_label, _value) \
689 { \
690 .range_begin = _value, \
691 .range_end = _value, \
692 .label = _label, \
693 }
694
695 /* Stack-copy field and type definitions */
696
697 #define side_type_null(_attr) \
698 { \
699 .type = SIDE_TYPE_NULL, \
700 .u = { \
701 .side_null = { \
702 .attr = _attr, \
703 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
704 }, \
705 }, \
706 }
707
708 #define side_type_bool(_attr) \
709 { \
710 .type = SIDE_TYPE_BOOL, \
711 .u = { \
712 .side_bool = { \
713 .attr = _attr, \
714 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
715 .bool_size = sizeof(uint8_t), \
716 .len_bits = 0, \
717 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
718 }, \
719 }, \
720 }
721
722 #define side_type_byte(_attr) \
723 { \
724 .type = SIDE_TYPE_BYTE, \
725 .u = { \
726 .side_byte = { \
727 .attr = _attr, \
728 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
729 }, \
730 }, \
731 }
732
733 #define side_type_string(_attr) \
734 { \
735 .type = SIDE_TYPE_STRING, \
736 .u = { \
737 .side_string = { \
738 .attr = _attr, \
739 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
740 }, \
741 }, \
742 }
743
744 #define side_type_dynamic() \
745 { \
746 .type = SIDE_TYPE_DYNAMIC, \
747 }
748
749 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
750 { \
751 .type = _type, \
752 .u = { \
753 .side_integer = { \
754 .attr = _attr, \
755 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
756 .integer_size = _integer_size, \
757 .len_bits = _len_bits, \
758 .signedness = _signedness, \
759 .byte_order = _byte_order, \
760 }, \
761 }, \
762 }
763
764 #define _side_type_float(_type, _byte_order, _float_size, _attr) \
765 { \
766 .type = _type, \
767 .u = { \
768 .side_float = { \
769 .attr = _attr, \
770 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
771 .float_size = _float_size, \
772 .byte_order = _byte_order, \
773 }, \
774 }, \
775 }
776
777 #define _side_field(_name, _type) \
778 { \
779 .field_name = _name, \
780 .side_type = _type, \
781 }
782
783 /* Host endian */
784 #define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM(_attr))
785 #define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
786 #define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), 0, SIDE_PARAM(_attr))
787 #define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint64_t), 0, SIDE_PARAM(_attr))
788 #define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM(_attr))
789 #define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int16_t), 0, SIDE_PARAM(_attr))
790 #define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int32_t), 0, SIDE_PARAM(_attr))
791 #define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int64_t), 0, SIDE_PARAM(_attr))
792 #define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uintptr_t), 0, SIDE_PARAM(_attr))
793 #define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float16), SIDE_PARAM(_attr))
794 #define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), SIDE_PARAM(_attr))
795 #define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), SIDE_PARAM(_attr))
796 #define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), SIDE_PARAM(_attr))
797
798 #define side_field_null(_name, _attr) _side_field(_name, side_type_null(SIDE_PARAM(_attr)))
799 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
800 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
801 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
802 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
803 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
804 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
805 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
806 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
807 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
808 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
809 #define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr)))
810 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
811 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
812 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
813 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
814 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
815 #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic())
816
817 /* Little endian */
818 #define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
819 #define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), 0, SIDE_PARAM(_attr))
820 #define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint64_t), 0, SIDE_PARAM(_attr))
821 #define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int16_t), 0, SIDE_PARAM(_attr))
822 #define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int32_t), 0, SIDE_PARAM(_attr))
823 #define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int64_t), 0, SIDE_PARAM(_attr))
824 #define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uintptr_t), 0, SIDE_PARAM(_attr))
825 #define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float16), SIDE_PARAM(_attr))
826 #define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float32), SIDE_PARAM(_attr))
827 #define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float64), SIDE_PARAM(_attr))
828 #define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float128), SIDE_PARAM(_attr))
829
830 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
831 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
832 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
833 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
834 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
835 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
836 #define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr)))
837 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
838 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
839 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
840 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
841
842 /* Big endian */
843 #define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
844 #define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), 0, SIDE_PARAM(_attr))
845 #define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint64_t), 0, SIDE_PARAM(_attr))
846 #define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int16_t), 0, SIDE_PARAM(_attr))
847 #define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int32_t), 0, SIDE_PARAM(_attr))
848 #define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int64_t), 0, SIDE_PARAM(_attr))
849 #define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uintptr_t), 0, SIDE_PARAM(_attr))
850 #define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float16), SIDE_PARAM(_attr))
851 #define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float32), SIDE_PARAM(_attr))
852 #define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float64), SIDE_PARAM(_attr))
853 #define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float128), SIDE_PARAM(_attr))
854
855 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
856 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
857 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
858 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
859 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
860 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
861 #define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr)))
862 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
863 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
864 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
865 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
866
867 #define side_type_enum(_mappings, _elem_type) \
868 { \
869 .type = SIDE_TYPE_ENUM, \
870 .u = { \
871 .side_enum = { \
872 .mappings = _mappings, \
873 .elem_type = _elem_type, \
874 }, \
875 }, \
876 }
877 #define side_field_enum(_name, _mappings, _elem_type) \
878 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
879
880 #define side_type_enum_bitmap(_mappings, _elem_type) \
881 { \
882 .type = SIDE_TYPE_ENUM_BITMAP, \
883 .u = { \
884 .side_enum_bitmap = { \
885 .mappings = _mappings, \
886 .elem_type = _elem_type, \
887 }, \
888 }, \
889 }
890 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
891 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
892
893 #define side_type_struct(_struct) \
894 { \
895 .type = SIDE_TYPE_STRUCT, \
896 .u = { \
897 .side_struct = _struct, \
898 }, \
899 }
900 #define side_field_struct(_name, _struct) \
901 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
902
903 #define _side_type_struct_define(_fields, _attr) \
904 { \
905 .fields = _fields, \
906 .attr = _attr, \
907 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
908 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
909 }
910
911 #define side_define_struct(_identifier, _fields, _attr) \
912 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
913
914 #define side_struct_literal(_fields, _attr) \
915 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
916 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
917
918 #define side_type_array(_elem_type, _length, _attr) \
919 { \
920 .type = SIDE_TYPE_ARRAY, \
921 .u = { \
922 .side_array = { \
923 .elem_type = _elem_type, \
924 .attr = _attr, \
925 .length = _length, \
926 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
927 }, \
928 }, \
929 }
930 #define side_field_array(_name, _elem_type, _length, _attr) \
931 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
932
933 #define side_type_vla(_elem_type, _attr) \
934 { \
935 .type = SIDE_TYPE_VLA, \
936 .u = { \
937 .side_vla = { \
938 .elem_type = _elem_type, \
939 .attr = _attr, \
940 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
941 }, \
942 }, \
943 }
944 #define side_field_vla(_name, _elem_type, _attr) \
945 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
946
947 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
948 { \
949 .type = SIDE_TYPE_VLA_VISITOR, \
950 .u = { \
951 .side_vla_visitor = { \
952 .elem_type = SIDE_PARAM(_elem_type), \
953 .visitor = _visitor, \
954 .attr = _attr, \
955 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
956 }, \
957 }, \
958 }
959 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
960 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
961
962 /* Gather field and type definitions */
963
964 #define side_type_gather_byte(_offset, _access_mode, _attr) \
965 { \
966 .type = SIDE_TYPE_GATHER_BYTE, \
967 .u = { \
968 .side_gather = { \
969 .u = { \
970 .side_byte = { \
971 .offset = _offset, \
972 .access_mode = _access_mode, \
973 .type = { \
974 .attr = _attr, \
975 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
976 }, \
977 }, \
978 }, \
979 }, \
980 }, \
981 }
982 #define side_field_gather_byte(_name, _offset, _access_mode, _attr) \
983 _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM(_attr)))
984
985 #define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
986 { \
987 .type = SIDE_TYPE_GATHER_BOOL, \
988 .u = { \
989 .side_gather = { \
990 .u = { \
991 .side_bool = { \
992 .offset = _offset, \
993 .access_mode = _access_mode, \
994 .type = { \
995 .attr = _attr, \
996 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
997 .bool_size = _bool_size, \
998 .len_bits = _len_bits, \
999 .byte_order = _byte_order, \
1000 }, \
1001 .offset_bits = _offset_bits, \
1002 }, \
1003 }, \
1004 }, \
1005 }, \
1006 }
1007 #define side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1008 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_HOST, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1009 #define side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1010 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_LE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1011 #define side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1012 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_BE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1013
1014 #define side_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1015 _side_field(_name, side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1016 #define side_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1017 _side_field(_name, side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1018 #define side_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1019 _side_field(_name, side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1020
1021 #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
1022 _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1023 { \
1024 .type = _type, \
1025 .u = { \
1026 .side_gather = { \
1027 .u = { \
1028 .side_integer = { \
1029 .offset = _offset, \
1030 .access_mode = _access_mode, \
1031 .type = { \
1032 .attr = _attr, \
1033 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1034 .integer_size = _integer_size, \
1035 .len_bits = _len_bits, \
1036 .signedness = _signedness, \
1037 .byte_order = _byte_order, \
1038 }, \
1039 .offset_bits = _offset_bits, \
1040 }, \
1041 }, \
1042 }, \
1043 }, \
1044 }
1045
1046 #define side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1047 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1048 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1049 #define side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1050 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, \
1051 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1052
1053 #define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1054 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_LE, \
1055 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1056 #define side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1057 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_LE, \
1058 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1059
1060 #define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1061 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_BE, \
1062 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1063 #define side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1064 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_BE, \
1065 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))
1066
1067 #define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1068 _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1069 #define side_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1070 _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1071
1072 #define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1073 _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1074 #define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1075 _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1076
1077 #define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1078 _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1079 #define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1080 _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)))
1081
1082 #define side_type_gather_pointer(_offset, _access_mode, _attr) \
1083 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
1084 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM(_attr))
1085 #define side_field_gather_pointer(_name, _offset, _access_mode, _attr) \
1086 _side_field(_name, side_type_gather_pointer(_offset, _access_mode, SIDE_PARAM(_attr)))
1087
1088 #define side_type_gather_pointer_le(_offset, _access_mode, _attr) \
1089 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, \
1090 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM(_attr))
1091 #define side_field_gather_pointer_le(_name, _offset, _access_mode, _attr) \
1092 _side_field(_name, side_type_gather_pointer_le(_offset, _access_mode, SIDE_PARAM(_attr)))
1093
1094 #define side_type_gather_pointer_be(_offset, _access_mode, _attr) \
1095 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, \
1096 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM(_attr))
1097 #define side_field_gather_pointer_be(_name, _offset, _access_mode, _attr) \
1098 _side_field(_name, side_type_gather_pointer_be(_offset, _access_mode, SIDE_PARAM(_attr)))
1099
1100 #define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr) \
1101 { \
1102 .type = SIDE_TYPE_GATHER_FLOAT, \
1103 .u = { \
1104 .side_gather = { \
1105 .u = { \
1106 .side_float = { \
1107 .offset = _offset, \
1108 .access_mode = _access_mode, \
1109 .type = { \
1110 .attr = _attr, \
1111 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1112 .float_size = _float_size, \
1113 .byte_order = _byte_order, \
1114 }, \
1115 }, \
1116 }, \
1117 }, \
1118 }, \
1119 }
1120
1121 #define side_type_gather_float(_offset, _float_size, _access_mode, _attr) \
1122 _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, _attr)
1123 #define side_type_gather_float_le(_offset, _float_size, _access_mode, _attr) \
1124 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, _attr)
1125 #define side_type_gather_float_be(_offset, _float_size, _access_mode, _attr) \
1126 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, _attr)
1127
1128 #define side_field_gather_float(_name, _offset, _float_size, _access_mode, _attr) \
1129 _side_field(_name, side_type_gather_float(_offset, _float_size, _access_mode, _attr))
1130 #define side_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr) \
1131 _side_field(_name, side_type_gather_float_le(_offset, _float_size, _access_mode, _attr))
1132 #define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr) \
1133 _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, _attr))
1134
1135 #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
1136 { \
1137 .type = SIDE_TYPE_GATHER_STRUCT, \
1138 .u = { \
1139 .side_gather = { \
1140 .u = { \
1141 .side_struct = { \
1142 .offset = _offset, \
1143 .access_mode = _access_mode, \
1144 .type = _struct_gather, \
1145 .size = _size, \
1146 }, \
1147 }, \
1148 }, \
1149 }, \
1150 }
1151 #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \
1152 _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode))
1153
1154 #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr) \
1155 { \
1156 .type = SIDE_TYPE_GATHER_ARRAY, \
1157 .u = { \
1158 .side_gather = { \
1159 .u = { \
1160 .side_array = { \
1161 .offset = _offset, \
1162 .access_mode = _access_mode, \
1163 .type = { \
1164 .elem_type = _elem_type_gather, \
1165 .attr = _attr, \
1166 .length = _length, \
1167 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1168 }, \
1169 }, \
1170 }, \
1171 }, \
1172 }, \
1173 }
1174 #define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr) \
1175 _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM(_attr)))
1176
1177 #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1178 { \
1179 .type = SIDE_TYPE_GATHER_VLA, \
1180 .u = { \
1181 .side_gather = { \
1182 .u = { \
1183 .side_vla = { \
1184 .length_type = _length_type_gather, \
1185 .offset = _offset, \
1186 .access_mode = _access_mode, \
1187 .type = { \
1188 .elem_type = _elem_type_gather, \
1189 .attr = _attr, \
1190 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1191 }, \
1192 }, \
1193 }, \
1194 }, \
1195 }, \
1196 }
1197 #define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1198 _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM(_attr)))
1199
1200 #define side_elem(...) \
1201 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1202
1203 #define side_length(...) \
1204 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1205
1206 #define side_field_list(...) \
1207 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
1208
1209 /* Stack-copy field arguments */
1210
1211 #define side_arg_null(_val) { .type = SIDE_TYPE_NULL }
1212 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } }
1213 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_static = { .byte_value = (_val) } } }
1214 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
1215
1216 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1217 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1218 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1219 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1220 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
1221 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
1222 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
1223 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
1224 #define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER, .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } }
1225 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1226 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1227 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1228 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1229 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
1230 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
1231 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
1232 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
1233 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
1234 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
1235
1236 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = (_side_type) } } }
1237 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
1238 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
1239 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
1240
1241 /* Gather field arguments */
1242
1243 #define side_arg_gather_bool(_ptr) { .type = SIDE_TYPE_GATHER_BOOL, .u = { .side_static = { .side_bool_gather_ptr = (_ptr) } } }
1244 #define side_arg_gather_byte(_ptr) { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = (_ptr) } } }
1245 #define side_arg_gather_pointer(_ptr) { .type = SIDE_TYPE_GATHER_POINTER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1246 #define side_arg_gather_unsigned_integer(_ptr) { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1247 #define side_arg_gather_signed_integer(_ptr) { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
1248 #define side_arg_gather_float(_ptr) { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = (_ptr) } } }
1249 #define side_arg_gather_struct(_ptr) { .type = SIDE_TYPE_GATHER_STRUCT, .u = { .side_static = { .side_struct_gather_ptr = (_ptr) } } }
1250 #define side_arg_gather_array(_ptr) { .type = SIDE_TYPE_GATHER_ARRAY, .u = { .side_static = { .side_array_gather_ptr = (_ptr) } } }
1251 #define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_TYPE_GATHER_VLA, .u = { .side_static = { .side_vla_gather = { .ptr = (_ptr), .length_ptr = (_length_ptr) } } } }
1252
1253 /* Dynamic field arguments */
1254
1255 #define side_arg_dynamic_null(_attr) \
1256 { \
1257 .type = SIDE_TYPE_DYNAMIC_NULL, \
1258 .u = { \
1259 .side_dynamic = { \
1260 .side_null = { \
1261 .attr = _attr, \
1262 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1263 }, \
1264 }, \
1265 }, \
1266 }
1267
1268 #define side_arg_dynamic_bool(_val, _attr) \
1269 { \
1270 .type = SIDE_TYPE_DYNAMIC_BOOL, \
1271 .u = { \
1272 .side_dynamic = { \
1273 .side_bool = { \
1274 .type = { \
1275 .attr = _attr, \
1276 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1277 .bool_size = sizeof(uint8_t), \
1278 .len_bits = 0, \
1279 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
1280 }, \
1281 .value = { \
1282 .side_bool8 = !!(_val), \
1283 }, \
1284 }, \
1285 }, \
1286 }, \
1287 }
1288
1289 #define side_arg_dynamic_byte(_val, _attr) \
1290 { \
1291 .type = SIDE_TYPE_DYNAMIC_BYTE, \
1292 .u = { \
1293 .side_dynamic = { \
1294 .side_byte = { \
1295 .type = { \
1296 .attr = _attr, \
1297 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1298 }, \
1299 .value = (_val), \
1300 }, \
1301 }, \
1302 }, \
1303 }
1304 #define side_arg_dynamic_string(_val, _attr) \
1305 { \
1306 .type = SIDE_TYPE_DYNAMIC_STRING, \
1307 .u = { \
1308 .side_dynamic = { \
1309 .side_string = { \
1310 .type = { \
1311 .attr = _attr, \
1312 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1313 }, \
1314 .value = (uintptr_t) (_val), \
1315 }, \
1316 }, \
1317 }, \
1318 }
1319
1320 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
1321 { \
1322 .type = _type, \
1323 .u = { \
1324 .side_dynamic = { \
1325 .side_integer = { \
1326 .type = { \
1327 .attr = _attr, \
1328 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1329 .integer_size = _integer_size, \
1330 .len_bits = _len_bits, \
1331 .signedness = _signedness, \
1332 .byte_order = _byte_order, \
1333 }, \
1334 .value = { \
1335 _field = (_val), \
1336 }, \
1337 }, \
1338 }, \
1339 }, \
1340 }
1341
1342 #define side_arg_dynamic_u8(_val, _attr) \
1343 _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM(_attr))
1344 #define side_arg_dynamic_s8(_val, _attr) \
1345 _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM(_attr))
1346
1347 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
1348 _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
1349 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
1350 _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint32_t), 0, SIDE_PARAM(_attr))
1351 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
1352 _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint64_t), 0, SIDE_PARAM(_attr))
1353
1354 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
1355 _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int16_t), 0, SIDE_PARAM(_attr))
1356 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
1357 _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int32_t), 0, SIDE_PARAM(_attr))
1358 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
1359 _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int64_t), 0, SIDE_PARAM(_attr))
1360
1361 #define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \
1362 _side_arg_dynamic_integer(.side_uptr, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER, false, _byte_order, \
1363 sizeof(uintptr_t), 0, SIDE_PARAM(_attr))
1364
1365 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr) \
1366 { \
1367 .type = _type, \
1368 .u = { \
1369 .side_dynamic = { \
1370 .side_float = { \
1371 .type = { \
1372 .attr = _attr, \
1373 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1374 .float_size = _float_size, \
1375 .byte_order = _byte_order, \
1376 }, \
1377 .value = { \
1378 _field = (_val), \
1379 }, \
1380 }, \
1381 }, \
1382 }, \
1383 }
1384
1385 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1386 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), SIDE_PARAM(_attr))
1387 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1388 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), SIDE_PARAM(_attr))
1389 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1390 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), SIDE_PARAM(_attr))
1391 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1392 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), SIDE_PARAM(_attr))
1393
1394 /* Host endian */
1395 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1396 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1397 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1398 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1399 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1400 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1401 #define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
1402 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1403 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1404 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1405 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
1406
1407 /* Little endian */
1408 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1409 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1410 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1411 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1412 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1413 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1414 #define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1415 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1416 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1417 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1418 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1419
1420 /* Big endian */
1421 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1422 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1423 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1424 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1425 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1426 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1427 #define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1428 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1429 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1430 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1431 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1432
1433 #define side_arg_dynamic_vla(_vla) \
1434 { \
1435 .type = SIDE_TYPE_DYNAMIC_VLA, \
1436 .u = { \
1437 .side_dynamic = { \
1438 .side_dynamic_vla = (_vla), \
1439 }, \
1440 }, \
1441 }
1442
1443 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1444 { \
1445 .type = SIDE_TYPE_DYNAMIC_VLA_VISITOR, \
1446 .u = { \
1447 .side_dynamic = { \
1448 .side_dynamic_vla_visitor = { \
1449 .app_ctx = _ctx, \
1450 .visitor = _dynamic_vla_visitor, \
1451 .attr = _attr, \
1452 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1453 }, \
1454 }, \
1455 }, \
1456 }
1457
1458 #define side_arg_dynamic_struct(_struct) \
1459 { \
1460 .type = SIDE_TYPE_DYNAMIC_STRUCT, \
1461 .u = { \
1462 .side_dynamic = { \
1463 .side_dynamic_struct = (_struct), \
1464 }, \
1465 }, \
1466 }
1467
1468 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1469 { \
1470 .type = SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, \
1471 .u = { \
1472 .side_dynamic = { \
1473 .side_dynamic_struct_visitor = { \
1474 .app_ctx = _ctx, \
1475 .visitor = _dynamic_struct_visitor, \
1476 .attr = _attr, \
1477 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1478 }, \
1479 }, \
1480 }, \
1481 }
1482
1483 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1484 const struct side_arg _identifier##_vec[] = { _sav }; \
1485 const struct side_arg_dynamic_vla _identifier = { \
1486 .sav = _identifier##_vec, \
1487 .attr = _attr, \
1488 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1489 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1490 }
1491
1492 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1493 const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \
1494 const struct side_arg_dynamic_struct _identifier = { \
1495 .fields = _identifier##_fields, \
1496 .attr = _attr, \
1497 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1498 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1499 }
1500
1501 #define side_arg_define_vec(_identifier, _sav) \
1502 const struct side_arg _identifier##_vec[] = { _sav }; \
1503 const struct side_arg_vec _identifier = { \
1504 .sav = _identifier##_vec, \
1505 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1506 }
1507
1508 #define side_arg_dynamic_field(_name, _elem) \
1509 { \
1510 .field_name = _name, \
1511 .elem = _elem, \
1512 }
1513
1514 /*
1515 * Event instrumentation description registration, runtime enabled state
1516 * check, and instrumentation invocation.
1517 */
1518
1519 #define side_arg_list(...) __VA_ARGS__
1520
1521 #define side_event_cond(_identifier) \
1522 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1523 __ATOMIC_RELAXED)))
1524
1525 #define side_event_call(_identifier, _sav) \
1526 { \
1527 const struct side_arg side_sav[] = { _sav }; \
1528 const struct side_arg_vec side_arg_vec = { \
1529 .sav = side_sav, \
1530 .len = SIDE_ARRAY_SIZE(side_sav), \
1531 }; \
1532 side_call(&(_identifier), &side_arg_vec); \
1533 }
1534
1535 #define side_event(_identifier, _sav) \
1536 side_event_cond(_identifier) \
1537 side_event_call(_identifier, SIDE_PARAM(_sav))
1538
1539 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1540 { \
1541 const struct side_arg side_sav[] = { _sav }; \
1542 const struct side_arg_vec side_arg_vec = { \
1543 .sav = side_sav, \
1544 .len = SIDE_ARRAY_SIZE(side_sav), \
1545 }; \
1546 const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \
1547 const struct side_arg_dynamic_struct var_struct = { \
1548 .fields = side_fields, \
1549 .attr = _attr, \
1550 .len = SIDE_ARRAY_SIZE(side_fields), \
1551 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1552 }; \
1553 side_call_variadic(&(_identifier), &side_arg_vec, &var_struct); \
1554 }
1555
1556 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1557 side_event_cond(_identifier) \
1558 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1559
1560 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1561 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1562 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1563 _identifier = { \
1564 .enabled = &(side_event_enable__##_identifier), \
1565 .provider_name = _provider, \
1566 .event_name = _event, \
1567 .fields = _fields, \
1568 .attr = _attr, \
1569 .callbacks = &side_empty_callback, \
1570 .flags = (_flags), \
1571 .version = 0, \
1572 .loglevel = _loglevel, \
1573 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1574 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1575 .nr_callbacks = 0, \
1576 }; \
1577 static const struct side_event_description *side_event_ptr__##_identifier \
1578 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1579
1580 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1581 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1582 SIDE_PARAM(_attr), 0)
1583
1584 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1585 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1586 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1587
1588 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1589 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1590 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0)
1591
1592 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1593 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1594 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1595
1596 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1597 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1598 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0)
1599
1600 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1601 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1602 _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1603
1604 #define side_declare_event(_identifier) \
1605 extern uintptr_t side_event_enable_##_identifier; \
1606 extern struct side_event_description _identifier
1607
1608 #ifdef __cplusplus
1609 extern "C" {
1610 #endif
1611
1612 extern const struct side_callback side_empty_callback;
1613
1614 void side_call(const struct side_event_description *desc,
1615 const struct side_arg_vec *side_arg_vec);
1616 void side_call_variadic(const struct side_event_description *desc,
1617 const struct side_arg_vec *side_arg_vec,
1618 const struct side_arg_dynamic_struct *var_struct);
1619
1620 struct side_events_register_handle *side_events_register(struct side_event_description **events,
1621 uint32_t nr_events);
1622 void side_events_unregister(struct side_events_register_handle *handle);
1623
1624 /*
1625 * Userspace tracer registration API. This allows userspace tracers to
1626 * register event notification callbacks to be notified of the currently
1627 * registered instrumentation, and to register their callbacks to
1628 * specific events.
1629 */
1630 typedef void (*side_tracer_callback_func)(const struct side_event_description *desc,
1631 const struct side_arg_vec *side_arg_vec,
1632 void *priv);
1633 typedef void (*side_tracer_callback_variadic_func)(const struct side_event_description *desc,
1634 const struct side_arg_vec *side_arg_vec,
1635 const struct side_arg_dynamic_struct *var_struct,
1636 void *priv);
1637
1638 int side_tracer_callback_register(struct side_event_description *desc,
1639 side_tracer_callback_func call,
1640 void *priv);
1641 int side_tracer_callback_variadic_register(struct side_event_description *desc,
1642 side_tracer_callback_variadic_func call_variadic,
1643 void *priv);
1644 int side_tracer_callback_unregister(struct side_event_description *desc,
1645 side_tracer_callback_func call,
1646 void *priv);
1647 int side_tracer_callback_variadic_unregister(struct side_event_description *desc,
1648 side_tracer_callback_variadic_func call_variadic,
1649 void *priv);
1650
1651 enum side_tracer_notification {
1652 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS,
1653 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS,
1654 };
1655
1656 /* Callback is invoked with side library internal lock held. */
1657 struct side_tracer_handle *side_tracer_event_notification_register(
1658 void (*cb)(enum side_tracer_notification notif,
1659 struct side_event_description **events, uint32_t nr_events, void *priv),
1660 void *priv);
1661 void side_tracer_event_notification_unregister(struct side_tracer_handle *handle);
1662
1663 /*
1664 * Explicit hooks to initialize/finalize the side instrumentation
1665 * library. Those are also library constructor/destructor.
1666 */
1667 void side_init(void);
1668 void side_exit(void);
1669
1670 /*
1671 * The following constructors/destructors perform automatic registration
1672 * of the declared side events. Those may have to be called explicitly
1673 * in a statically linked library.
1674 */
1675
1676 /*
1677 * These weak symbols, the constructor, and destructor take care of
1678 * registering only _one_ instance of the side instrumentation per
1679 * shared-ojbect (or for the whole main program).
1680 */
1681 extern struct side_event_description * __start_side_event_description_ptr[]
1682 __attribute__((weak, visibility("hidden")));
1683 extern struct side_event_description * __stop_side_event_description_ptr[]
1684 __attribute__((weak, visibility("hidden")));
1685 int side_event_description_ptr_registered
1686 __attribute__((weak, visibility("hidden")));
1687 struct side_events_register_handle *side_events_handle
1688 __attribute__((weak, visibility("hidden")));
1689
1690 static void
1691 side_event_description_ptr_init(void)
1692 __attribute__((no_instrument_function))
1693 __attribute__((constructor));
1694 static void
1695 side_event_description_ptr_init(void)
1696 {
1697 if (side_event_description_ptr_registered++)
1698 return;
1699 side_events_handle = side_events_register(__start_side_event_description_ptr,
1700 __stop_side_event_description_ptr - __start_side_event_description_ptr);
1701 }
1702
1703 static void
1704 side_event_description_ptr_exit(void)
1705 __attribute__((no_instrument_function))
1706 __attribute__((destructor));
1707 static void
1708 side_event_description_ptr_exit(void)
1709 {
1710 if (--side_event_description_ptr_registered)
1711 return;
1712 side_events_unregister(side_events_handle);
1713 side_events_handle = NULL;
1714 }
1715
1716 #ifdef __cplusplus
1717 }
1718 #endif
1719
1720 #endif /* _SIDE_TRACE_H */
This page took 0.060981 seconds and 5 git commands to generate.