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