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