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