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