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