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