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