Enforce ABI size checks
[libside.git] / include / side / trace.h
CommitLineData
67337c4a
MD
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>
25ea4c79 14#include <stdbool.h>
67337c4a
MD
15#include <side/macros.h>
16#include <side/endian.h>
17
18/*
551d8244 19 * SIDE stands for "Software Instrumentation Dynamically Enabled"
67337c4a 20 *
2e197497 21 * This is an instrumentation ABI for Linux user-space, which exposes an
67337c4a
MD
22 * instrumentation type system and facilities allowing a kernel or
23 * user-space tracer to consume user-space instrumentation.
24 *
2e197497 25 * This instrumentation ABI exposes 3 type systems:
67337c4a
MD
26 *
27 * * Stack-copy type system: This is the core type system which can
28 * represent all supported types and into which all other type systems
29 * can be nested. This type system requires that every type is
30 * statically or dynamically declared and then registered, thus giving
31 * tracers a complete description of the events and their associated
32 * fields before the associated instrumentation is invoked. The
33 * application needs to copy each argument (side_arg_...()) onto the
34 * stack when calling the instrumentation.
35 *
36 * This is the most expressive of the 3 type systems, althrough not the
37 * fastest due to the extra copy of the arguments.
38 *
39 * * Data-gathering type system: This type system requires every type to
40 * be statically or dynamically declared and registered, but does not
41 * require the application to copy its arguments onto the stack.
42 * Instead, the type description contains all the required information
43 * to fetch the data from the application memory. The only argument
44 * required from the instrumentation is the base pointer from which
45 * the data should be fetched.
46 *
47 * This type system can be used as an event field, or nested within
48 * the stack-copy type system. Nesting of gather-vla within
49 * gather-array and gather-vla types is not allowed.
50 *
51 * This type system is has the least overhead of the 3 type systems.
52 *
53 * * Dynamic type system: This type system receives both type
54 * description and actual data onto the stack at runtime. It has more
55 * overhead that the 2 other type systems, but does not require a
56 * prior registration of event field description. This makes it useful
57 * for seldom used types which are not performance critical, but for
58 * which registering each individual events would needlessly grow the
59 * number of events to declare and register.
60 *
61 * Another use-case for this type system is for use by dynamically
62 * typed language runtimes, where the field type is only known when
63 * the instrumentation is called.
64 *
65 * Those dynamic types can be either used as arguments to a variadic
66 * field list, or as on-stack instrumentation argument for a static
67 * type SIDE_TYPE_DYNAMIC place holder in the stack-copy type system.
2e197497
MD
68 *
69 * The extensibility scheme for the SIDE ABI is as follows:
70 *
71 * * Existing field types are never changed nor extended. Field types
72 * can be added to the ABI by reserving a label within
73 * enum side_type_label.
74 * * Existing attribute types are never changed nor extended. Attribute
75 * types can be added to the ABI by reserving a label within
76 * enum side_attr_type.
77 * * Each union part of the ABI has an explicit side defined by a
78 * side_padding() member. Each structure and union have a static
79 * assert validating its size.
80 *
81 * Handling of unknown types by the tracers:
82 *
83 * * A tracer may choose to support only a subset of the types supported
84 * by libside. When encountering an unknown or unsupported type, the
85 * tracer has the option to either disallow the entire event or skip
86 * over the unknown type, both at event registration and when
87 * receiving the side_call arguments.
88 *
89 * TODO: extend event description with new fields ?
67337c4a
MD
90 */
91
92//TODO: as those structures will be ABI, we need to either consider them
93//fixed forever, or think of a scheme that would allow their binary
94//representation to be extended if need be.
95
96struct side_arg;
97struct side_arg_vec;
09515e04 98union side_arg_dynamic;
67337c4a
MD
99struct side_arg_dynamic_field;
100struct side_arg_dynamic_vla;
101struct side_type;
102struct side_event_field;
103struct side_tracer_visitor_ctx;
104struct side_tracer_dynamic_struct_visitor_ctx;
105struct side_event_description;
106struct side_arg_dynamic_struct;
107struct side_events_register_handle;
5530345d 108struct side_arg_variant;
0d747f98 109struct side_event_state;
2e197497 110struct side_callback;
67337c4a
MD
111
112enum side_type_label {
113 /* Stack-copy basic types */
114 SIDE_TYPE_NULL,
115 SIDE_TYPE_BOOL,
116 SIDE_TYPE_U8,
117 SIDE_TYPE_U16,
118 SIDE_TYPE_U32,
119 SIDE_TYPE_U64,
120 SIDE_TYPE_S8,
121 SIDE_TYPE_S16,
122 SIDE_TYPE_S32,
123 SIDE_TYPE_S64,
124 SIDE_TYPE_BYTE,
125 SIDE_TYPE_POINTER,
126 SIDE_TYPE_FLOAT_BINARY16,
127 SIDE_TYPE_FLOAT_BINARY32,
128 SIDE_TYPE_FLOAT_BINARY64,
129 SIDE_TYPE_FLOAT_BINARY128,
130 SIDE_TYPE_STRING_UTF8,
131 SIDE_TYPE_STRING_UTF16,
132 SIDE_TYPE_STRING_UTF32,
133
134 /* Stack-copy compound types */
135 SIDE_TYPE_STRUCT,
5530345d 136 SIDE_TYPE_VARIANT,
67337c4a
MD
137 SIDE_TYPE_ARRAY,
138 SIDE_TYPE_VLA,
139 SIDE_TYPE_VLA_VISITOR,
140
141 /* Stack-copy enumeration types */
142 SIDE_TYPE_ENUM,
143 SIDE_TYPE_ENUM_BITMAP,
144
145 /* Stack-copy place holder for dynamic types */
146 SIDE_TYPE_DYNAMIC,
147
148 /* Gather basic types */
149 SIDE_TYPE_GATHER_BOOL,
150 SIDE_TYPE_GATHER_INTEGER,
151 SIDE_TYPE_GATHER_BYTE,
152 SIDE_TYPE_GATHER_POINTER,
153 SIDE_TYPE_GATHER_FLOAT,
154 SIDE_TYPE_GATHER_STRING,
155
156 /* Gather compound types */
157 SIDE_TYPE_GATHER_STRUCT,
158 SIDE_TYPE_GATHER_ARRAY,
159 SIDE_TYPE_GATHER_VLA,
160
161 /* Gather enumeration types */
162 SIDE_TYPE_GATHER_ENUM,
163
164 /* Dynamic basic types */
165 SIDE_TYPE_DYNAMIC_NULL,
166 SIDE_TYPE_DYNAMIC_BOOL,
167 SIDE_TYPE_DYNAMIC_INTEGER,
168 SIDE_TYPE_DYNAMIC_BYTE,
169 SIDE_TYPE_DYNAMIC_POINTER,
170 SIDE_TYPE_DYNAMIC_FLOAT,
171 SIDE_TYPE_DYNAMIC_STRING,
172
173 /* Dynamic compound types */
174 SIDE_TYPE_DYNAMIC_STRUCT,
175 SIDE_TYPE_DYNAMIC_STRUCT_VISITOR,
176 SIDE_TYPE_DYNAMIC_VLA,
177 SIDE_TYPE_DYNAMIC_VLA_VISITOR,
178};
179
180enum side_attr_type {
181 SIDE_ATTR_TYPE_NULL,
182 SIDE_ATTR_TYPE_BOOL,
183 SIDE_ATTR_TYPE_U8,
184 SIDE_ATTR_TYPE_U16,
185 SIDE_ATTR_TYPE_U32,
186 SIDE_ATTR_TYPE_U64,
187 SIDE_ATTR_TYPE_S8,
188 SIDE_ATTR_TYPE_S16,
189 SIDE_ATTR_TYPE_S32,
190 SIDE_ATTR_TYPE_S64,
191 SIDE_ATTR_TYPE_FLOAT_BINARY16,
192 SIDE_ATTR_TYPE_FLOAT_BINARY32,
193 SIDE_ATTR_TYPE_FLOAT_BINARY64,
194 SIDE_ATTR_TYPE_FLOAT_BINARY128,
195 SIDE_ATTR_TYPE_STRING,
196};
197
198enum side_loglevel {
199 SIDE_LOGLEVEL_EMERG = 0,
200 SIDE_LOGLEVEL_ALERT = 1,
201 SIDE_LOGLEVEL_CRIT = 2,
202 SIDE_LOGLEVEL_ERR = 3,
203 SIDE_LOGLEVEL_WARNING = 4,
204 SIDE_LOGLEVEL_NOTICE = 5,
205 SIDE_LOGLEVEL_INFO = 6,
206 SIDE_LOGLEVEL_DEBUG = 7,
207};
208
209enum side_visitor_status {
210 SIDE_VISITOR_STATUS_OK = 0,
211 SIDE_VISITOR_STATUS_ERROR = -1,
212};
213
c0f105bf 214//TODO: side_error enum is currently unused.
67337c4a
MD
215enum 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
224enum 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
241enum side_type_gather_access_mode {
242 SIDE_TYPE_GATHER_ACCESS_DIRECT,
243 SIDE_TYPE_GATHER_ACCESS_POINTER, /* Pointer dereference */
244};
245
246typedef enum side_visitor_status (*side_visitor_func)(
247 const struct side_tracer_visitor_ctx *tracer_ctx,
248 void *app_ctx);
249typedef enum side_visitor_status (*side_dynamic_struct_visitor_func)(
250 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
251 void *app_ctx);
2e197497
MD
252typedef enum side_visitor_status (*side_write_elem_func)(
253 const struct side_tracer_visitor_ctx *tracer_ctx,
254 const struct side_arg *elem);
255typedef enum side_visitor_status (*side_write_field_func)(
256 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
257 const struct side_arg_dynamic_field *dynamic_field);
67337c4a
MD
258
259union side_integer_value {
260 uint8_t side_u8;
261 uint16_t side_u16;
262 uint32_t side_u32;
263 uint64_t side_u64;
264 int8_t side_s8;
265 int16_t side_s16;
266 int32_t side_s32;
267 int64_t side_s64;
268 uintptr_t side_uptr;
2e197497 269 side_padding(32);
67337c4a 270} SIDE_PACKED;
2e197497 271side_check_size(union side_integer_value, 32);
67337c4a
MD
272
273union side_bool_value {
274 uint8_t side_bool8;
275 uint16_t side_bool16;
276 uint32_t side_bool32;
277 uint64_t side_bool64;
2e197497 278 side_padding(32);
67337c4a 279} SIDE_PACKED;
2e197497 280side_check_size(union side_bool_value, 32);
67337c4a
MD
281
282union side_float_value {
283#if __HAVE_FLOAT16
284 _Float16 side_float_binary16;
285#endif
286#if __HAVE_FLOAT32
287 _Float32 side_float_binary32;
288#endif
289#if __HAVE_FLOAT64
290 _Float64 side_float_binary64;
291#endif
292#if __HAVE_FLOAT128
293 _Float128 side_float_binary128;
294#endif
2e197497 295 side_padding(32);
67337c4a 296} SIDE_PACKED;
2e197497 297side_check_size(union side_float_value, 32);
67337c4a
MD
298
299struct side_type_raw_string {
3db2d8a1 300 side_ptr_t(const void) p; /* pointer to string */
67337c4a 301 uint8_t unit_size; /* 1, 2, or 4 bytes */
3bc9ba43 302 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
67337c4a 303} SIDE_PACKED;
2e197497 304side_check_size(struct side_type_raw_string, 18);
67337c4a
MD
305
306struct side_attr_value {
15f17024 307 side_enum_t(enum side_attr_type, uint32_t) type;
67337c4a
MD
308 union {
309 uint8_t bool_value;
310 struct side_type_raw_string string_value;
311 union side_integer_value integer_value;
312 union side_float_value float_value;
2e197497 313 side_padding(32);
67337c4a
MD
314 } SIDE_PACKED u;
315};
2e197497 316side_check_size(struct side_attr_value, 36);
67337c4a
MD
317
318/* User attributes. */
319struct side_attr {
320 const struct side_type_raw_string key;
321 const struct side_attr_value value;
322} SIDE_PACKED;
2e197497 323side_check_size(struct side_attr, 54);
67337c4a
MD
324
325/* Type descriptions */
326struct side_type_null {
b313067b 327 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
328 uint32_t nr_attr;
329} SIDE_PACKED;
2e197497 330side_check_size(struct side_type_null, 20);
67337c4a
MD
331
332struct side_type_bool {
db8df9b5 333 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
334 uint32_t nr_attr;
335 uint16_t bool_size; /* bytes */
336 uint16_t len_bits; /* bits. 0 for (bool_size * CHAR_BITS) */
3bc9ba43 337 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
67337c4a 338} SIDE_PACKED;
2e197497 339side_check_size(struct side_type_bool, 25);
67337c4a
MD
340
341struct side_type_byte {
12d787db 342 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
343 uint32_t nr_attr;
344} SIDE_PACKED;
2e197497 345side_check_size(struct side_type_byte, 20);
67337c4a
MD
346
347struct side_type_string {
12d787db 348 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
349 uint32_t nr_attr;
350 uint8_t unit_size; /* 1, 2, or 4 bytes */
3bc9ba43 351 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
67337c4a 352} SIDE_PACKED;
2e197497 353side_check_size(struct side_type_string, 22);
67337c4a
MD
354
355struct side_type_integer {
12d787db 356 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
357 uint32_t nr_attr;
358 uint16_t integer_size; /* bytes */
359 uint16_t len_bits; /* bits. 0 for (integer_size * CHAR_BITS) */
360 uint8_t signedness; /* true/false */
3bc9ba43 361 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
67337c4a 362} SIDE_PACKED;
2e197497 363side_check_size(struct side_type_integer, 26);
67337c4a
MD
364
365struct side_type_float {
12d787db 366 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
367 uint32_t nr_attr;
368 uint16_t float_size; /* bytes */
3bc9ba43 369 side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
67337c4a 370} SIDE_PACKED;
2e197497 371side_check_size(struct side_type_float, 23);
67337c4a
MD
372
373struct side_enum_mapping {
374 int64_t range_begin;
375 int64_t range_end;
376 struct side_type_raw_string label;
377} SIDE_PACKED;
2e197497 378side_check_size(struct side_enum_mapping, 16 + sizeof(struct side_type_raw_string));
67337c4a
MD
379
380struct side_enum_mappings {
64037418 381 side_ptr_t(const struct side_enum_mapping) mappings;
12d787db 382 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
383 uint32_t nr_mappings;
384 uint32_t nr_attr;
385} SIDE_PACKED;
2e197497 386side_check_size(struct side_enum_mappings, 40);
67337c4a
MD
387
388struct side_enum_bitmap_mapping {
389 uint64_t range_begin;
390 uint64_t range_end;
391 struct side_type_raw_string label;
392} SIDE_PACKED;
2e197497 393side_check_size(struct side_enum_bitmap_mapping, 16 + sizeof(struct side_type_raw_string));
67337c4a
MD
394
395struct side_enum_bitmap_mappings {
64037418 396 side_ptr_t(const struct side_enum_bitmap_mapping) mappings;
12d787db 397 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
398 uint32_t nr_mappings;
399 uint32_t nr_attr;
400} SIDE_PACKED;
2e197497 401side_check_size(struct side_enum_bitmap_mappings, 40);
67337c4a
MD
402
403struct side_type_struct {
c5789285 404 side_ptr_t(const struct side_event_field) fields;
12d787db 405 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
406 uint32_t nr_fields;
407 uint32_t nr_attr;
408} SIDE_PACKED;
2e197497 409side_check_size(struct side_type_struct, 40);
67337c4a
MD
410
411struct side_type_array {
c5789285 412 side_ptr_t(const struct side_type) elem_type;
12d787db 413 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
414 uint32_t length;
415 uint32_t nr_attr;
416} SIDE_PACKED;
2e197497 417side_check_size(struct side_type_array, 40);
67337c4a
MD
418
419struct side_type_vla {
c5789285 420 side_ptr_t(const struct side_type) elem_type;
12d787db 421 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
422 uint32_t nr_attr;
423} SIDE_PACKED;
2e197497 424side_check_size(struct side_type_vla, 36);
67337c4a
MD
425
426struct side_type_vla_visitor {
c5789285 427 side_ptr_t(const struct side_type) elem_type;
2e197497 428 side_func_ptr_t(side_visitor_func) visitor;
12d787db 429 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
430 uint32_t nr_attr;
431} SIDE_PACKED;
2e197497 432side_check_size(struct side_type_vla_visitor, 52);
67337c4a
MD
433
434struct side_type_enum {
64037418 435 side_ptr_t(const struct side_enum_mappings) mappings;
c5789285 436 side_ptr_t(const struct side_type) elem_type;
67337c4a 437} SIDE_PACKED;
2e197497 438side_check_size(struct side_type_enum, 32);
67337c4a
MD
439
440struct side_type_enum_bitmap {
64037418 441 side_ptr_t(const struct side_enum_bitmap_mappings) mappings;
c5789285 442 side_ptr_t(const struct side_type) elem_type;
67337c4a 443} SIDE_PACKED;
2e197497 444side_check_size(struct side_type_enum_bitmap, 32);
67337c4a
MD
445
446struct side_type_gather_bool {
447 uint64_t offset; /* bytes */
2e197497 448 uint16_t offset_bits; /* bits */
67337c4a
MD
449 uint8_t access_mode; /* enum side_type_gather_access_mode */
450 struct side_type_bool type;
67337c4a 451} SIDE_PACKED;
2e197497 452side_check_size(struct side_type_gather_bool, 11 + sizeof(struct side_type_bool));
67337c4a
MD
453
454struct side_type_gather_byte {
455 uint64_t offset; /* bytes */
456 uint8_t access_mode; /* enum side_type_gather_access_mode */
457 struct side_type_byte type;
458} SIDE_PACKED;
2e197497 459side_check_size(struct side_type_gather_byte, 9 + sizeof(struct side_type_byte));
67337c4a
MD
460
461struct side_type_gather_integer {
462 uint64_t offset; /* bytes */
2e197497 463 uint16_t offset_bits; /* bits */
67337c4a
MD
464 uint8_t access_mode; /* enum side_type_gather_access_mode */
465 struct side_type_integer type;
67337c4a 466} SIDE_PACKED;
2e197497 467side_check_size(struct side_type_gather_integer, 11 + sizeof(struct side_type_integer));
67337c4a
MD
468
469struct side_type_gather_float {
470 uint64_t offset; /* bytes */
471 uint8_t access_mode; /* enum side_type_gather_access_mode */
472 struct side_type_float type;
473} SIDE_PACKED;
2e197497 474side_check_size(struct side_type_gather_float, 9 + sizeof(struct side_type_float));
67337c4a
MD
475
476struct side_type_gather_string {
477 uint64_t offset; /* bytes */
478 uint8_t access_mode; /* enum side_type_gather_access_mode */
479 struct side_type_string type;
480} SIDE_PACKED;
2e197497 481side_check_size(struct side_type_gather_string, 9 + sizeof(struct side_type_string));
67337c4a
MD
482
483struct side_type_gather_enum {
64037418 484 side_ptr_t(const struct side_enum_mappings) mappings;
c5789285 485 side_ptr_t(const struct side_type) elem_type;
67337c4a 486} SIDE_PACKED;
2e197497 487side_check_size(struct side_type_gather_enum, 32);
67337c4a
MD
488
489struct side_type_gather_struct {
2e197497 490 side_ptr_t(const struct side_type_struct) type;
67337c4a
MD
491 uint64_t offset; /* bytes */
492 uint8_t access_mode; /* enum side_type_gather_access_mode */
67337c4a
MD
493 uint32_t size; /* bytes */
494} SIDE_PACKED;
2e197497 495side_check_size(struct side_type_gather_struct, 29);
67337c4a
MD
496
497struct side_type_gather_array {
498 uint64_t offset; /* bytes */
499 uint8_t access_mode; /* enum side_type_gather_access_mode */
500 struct side_type_array type;
501} SIDE_PACKED;
2e197497 502side_check_size(struct side_type_gather_array, 9 + sizeof(struct side_type_array));
67337c4a
MD
503
504struct side_type_gather_vla {
c5789285 505 side_ptr_t(const struct side_type) length_type; /* side_length() */
67337c4a
MD
506 uint64_t offset; /* bytes */
507 uint8_t access_mode; /* enum side_type_gather_access_mode */
508 struct side_type_vla type;
509} SIDE_PACKED;
2e197497 510side_check_size(struct side_type_gather_vla, 25 + sizeof(struct side_type_vla));
67337c4a
MD
511
512struct side_type_gather {
513 union {
514 struct side_type_gather_bool side_bool;
515 struct side_type_gather_byte side_byte;
516 struct side_type_gather_integer side_integer;
517 struct side_type_gather_float side_float;
518 struct side_type_gather_string side_string;
519 struct side_type_gather_enum side_enum;
520 struct side_type_gather_array side_array;
521 struct side_type_gather_vla side_vla;
522 struct side_type_gather_struct side_struct;
2e197497 523 side_padding(61);
67337c4a
MD
524 } SIDE_PACKED u;
525} SIDE_PACKED;
2e197497 526side_check_size(struct side_type_gather, 61);
67337c4a
MD
527
528struct side_type {
2e197497 529 side_enum_t(enum side_type_label, uint16_t) type;
67337c4a
MD
530 union {
531 /* Stack-copy basic types */
532 struct side_type_null side_null;
533 struct side_type_bool side_bool;
534 struct side_type_byte side_byte;
535 struct side_type_string side_string;
536 struct side_type_integer side_integer;
537 struct side_type_float side_float;
538
539 /* Stack-copy compound types */
540 struct side_type_array side_array;
541 struct side_type_vla side_vla;
542 struct side_type_vla_visitor side_vla_visitor;
c5789285
MD
543 side_ptr_t(const struct side_type_struct) side_struct;
544 side_ptr_t(const struct side_type_variant) side_variant;
67337c4a
MD
545
546 /* Stack-copy enumeration types */
547 struct side_type_enum side_enum;
548 struct side_type_enum_bitmap side_enum_bitmap;
549
550 /* Gather types */
551 struct side_type_gather side_gather;
2e197497 552 side_padding(62);
67337c4a
MD
553 } SIDE_PACKED u;
554} SIDE_PACKED;
2e197497 555side_check_size(struct side_type, 64);
67337c4a 556
5530345d
MD
557struct side_variant_option {
558 int64_t range_begin;
559 int64_t range_end;
560 const struct side_type side_type;
561} SIDE_PACKED;
2e197497 562side_check_size(struct side_variant_option, 16 + sizeof(const struct side_type));
5530345d
MD
563
564struct side_type_variant {
c5789285 565 side_ptr_t(const struct side_variant_option) options;
12d787db 566 side_ptr_t(const struct side_attr) attr;
5530345d
MD
567 uint32_t nr_options;
568 uint32_t nr_attr;
2e197497 569 const struct side_type selector;
5530345d 570} SIDE_PACKED;
2e197497 571side_check_size(struct side_type_variant, 40 + sizeof(const struct side_type));
5530345d 572
67337c4a 573struct side_event_field {
c5789285 574 side_ptr_t(const char) field_name;
67337c4a
MD
575 struct side_type side_type;
576} SIDE_PACKED;
2e197497 577side_check_size(struct side_event_field, 16 + sizeof(struct side_type));
67337c4a
MD
578
579enum side_event_flags {
580 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
581};
582
09515e04 583union side_arg_static {
67337c4a
MD
584 /* Stack-copy basic types */
585 union side_bool_value bool_value;
586 uint8_t byte_value;
6910c28c 587 side_ptr_t(const void) string_value; /* const {uint8_t, uint16_t, uint32_t} * */
67337c4a
MD
588 union side_integer_value integer_value;
589 union side_float_value float_value;
590
591 /* Stack-copy compound types */
bac71609
MD
592 side_ptr_t(const struct side_arg_vec) side_struct;
593 side_ptr_t(const struct side_arg_variant) side_variant;
594 side_ptr_t(const struct side_arg_vec) side_array;
595 side_ptr_t(const struct side_arg_vec) side_vla;
67337c4a
MD
596 void *side_vla_app_visitor_ctx;
597
598 /* Gather basic types */
155b1756
MD
599 side_ptr_t(const void) side_bool_gather_ptr;
600 side_ptr_t(const void) side_byte_gather_ptr;
601 side_ptr_t(const void) side_integer_gather_ptr;
602 side_ptr_t(const void) side_float_gather_ptr;
603 side_ptr_t(const void) side_string_gather_ptr;
67337c4a
MD
604
605 /* Gather compound types */
155b1756
MD
606 side_ptr_t(const void) side_array_gather_ptr;
607 side_ptr_t(const void) side_struct_gather_ptr;
67337c4a 608 struct {
155b1756
MD
609 side_ptr_t(const void) ptr;
610 side_ptr_t(const void) length_ptr;
67337c4a 611 } SIDE_PACKED side_vla_gather;
2e197497 612 side_padding(32);
67337c4a 613} SIDE_PACKED;
2e197497 614side_check_size(union side_arg_static, 32);
67337c4a
MD
615
616struct side_arg_dynamic_vla {
f13253cb 617 side_ptr_t(const struct side_arg) sav;
12d787db 618 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
619 uint32_t len;
620 uint32_t nr_attr;
621} SIDE_PACKED;
2e197497 622side_check_size(struct side_arg_dynamic_vla, 40);
67337c4a
MD
623
624struct side_arg_dynamic_struct {
f13253cb 625 side_ptr_t(const struct side_arg_dynamic_field) fields;
12d787db 626 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
627 uint32_t len;
628 uint32_t nr_attr;
629} SIDE_PACKED;
2e197497 630side_check_size(struct side_arg_dynamic_struct, 40);
67337c4a
MD
631
632struct side_dynamic_struct_visitor {
2e197497
MD
633 side_func_ptr_t(side_dynamic_struct_visitor_func) visitor;
634 side_ptr_t(void) app_ctx;
12d787db 635 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
636 uint32_t nr_attr;
637} SIDE_PACKED;
2e197497 638side_check_size(struct side_dynamic_struct_visitor, 52);
67337c4a
MD
639
640struct side_dynamic_vla_visitor {
2e197497
MD
641 side_func_ptr_t(side_visitor_func) visitor;
642 side_ptr_t(void) app_ctx;
12d787db 643 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
644 uint32_t nr_attr;
645} SIDE_PACKED;
2e197497 646side_check_size(struct side_dynamic_vla_visitor, 52);
67337c4a 647
09515e04 648union side_arg_dynamic {
67337c4a
MD
649 /* Dynamic basic types */
650 struct side_type_null side_null;
651 struct {
652 struct side_type_bool type;
653 union side_bool_value value;
654 } SIDE_PACKED side_bool;
655 struct {
656 struct side_type_byte type;
657 uint8_t value;
658 } SIDE_PACKED side_byte;
659 struct {
660 struct side_type_string type;
661 uint64_t value; /* const char * */
662 } SIDE_PACKED side_string;
663 struct {
664 struct side_type_integer type;
665 union side_integer_value value;
666 } SIDE_PACKED side_integer;
667 struct {
668 struct side_type_float type;
669 union side_float_value value;
670 } SIDE_PACKED side_float;
671
672 /* Dynamic compound types */
f13253cb
MD
673 side_ptr_t(const struct side_arg_dynamic_struct) side_dynamic_struct;
674 side_ptr_t(const struct side_arg_dynamic_vla) side_dynamic_vla;
67337c4a
MD
675
676 struct side_dynamic_struct_visitor side_dynamic_struct_visitor;
677 struct side_dynamic_vla_visitor side_dynamic_vla_visitor;
2e197497
MD
678
679 side_padding(58);
67337c4a 680} SIDE_PACKED;
2e197497 681side_check_size(union side_arg_dynamic, 58);
67337c4a
MD
682
683struct side_arg {
2e197497 684 side_enum_t(enum side_type_label, uint16_t) type;
67337c4a 685 union {
09515e04
MD
686 union side_arg_static side_static;
687 union side_arg_dynamic side_dynamic;
2e197497 688 side_padding(62);
67337c4a
MD
689 } SIDE_PACKED u;
690} SIDE_PACKED;
2e197497 691side_check_size(struct side_arg, 64);
67337c4a 692
5530345d
MD
693struct side_arg_variant {
694 struct side_arg selector;
695 struct side_arg option;
696} SIDE_PACKED;
2e197497 697side_check_size(struct side_arg_variant, 128);
5530345d 698
67337c4a 699struct side_arg_vec {
f13253cb 700 side_ptr_t(const struct side_arg) sav;
67337c4a
MD
701 uint32_t len;
702} SIDE_PACKED;
2e197497 703side_check_size(struct side_arg_vec, 20);
67337c4a
MD
704
705struct side_arg_dynamic_field {
f13253cb 706 side_ptr_t(const char) field_name;
67337c4a
MD
707 const struct side_arg elem;
708} SIDE_PACKED;
2e197497 709side_check_size(struct side_arg_dynamic_field, 16 + sizeof(const struct side_arg));
67337c4a
MD
710
711struct side_event_description {
0b9e59d6
MD
712 side_ptr_t(struct side_event_state) state;
713 side_ptr_t(const char) provider_name;
714 side_ptr_t(const char) event_name;
715 side_ptr_t(const struct side_event_field) fields;
12d787db 716 side_ptr_t(const struct side_attr) attr;
67337c4a
MD
717 uint64_t flags;
718 uint32_t version;
1f7aaefb 719 side_enum_t(enum side_loglevel, uint32_t) loglevel;
67337c4a
MD
720 uint32_t nr_fields;
721 uint32_t nr_attr;
f8188f94 722 uint32_t nr_callbacks;
67337c4a
MD
723} SIDE_PACKED;
724
0d747f98
MD
725/*
726 * This structure is _not_ packed to allow atomic operations on its
727 * fields.
728 */
729struct side_event_state {
730 uintptr_t enabled;
731 const struct side_callback *callbacks;
732 struct side_event_description *desc;
733};
734
67337c4a
MD
735/* Event and type attributes */
736
737#define side_attr(_key, _value) \
738 { \
739 .key = { \
d1251f44 740 .p = SIDE_PTR_INIT(_key), \
67337c4a 741 .unit_size = sizeof(uint8_t), \
3bc9ba43 742 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
67337c4a
MD
743 }, \
744 .value = SIDE_PARAM(_value), \
745 }
746
747#define side_attr_list(...) \
748 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
749
750#define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
15f17024
MD
751#define side_attr_bool(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_BOOL), .u = { .bool_value = !!(_val) } }
752#define side_attr_u8(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U8), .u = { .integer_value = { .side_u8 = (_val) } } }
753#define side_attr_u16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U16), .u = { .integer_value = { .side_u16 = (_val) } } }
754#define side_attr_u32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U32), .u = { .integer_value = { .side_u32 = (_val) } } }
755#define side_attr_u64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U64), .u = { .integer_value = { .side_u64 = (_val) } } }
756#define side_attr_s8(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S8), .u = { .integer_value = { .side_s8 = (_val) } } }
757#define side_attr_s16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S16), .u = { .integer_value = { .side_s16 = (_val) } } }
758#define side_attr_s32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S32), .u = { .integer_value = { .side_s32 = (_val) } } }
759#define side_attr_s64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S64), .u = { .integer_value = { .side_s64 = (_val) } } }
760#define side_attr_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY16), .u = { .float_value = { .side_float_binary16 = (_val) } } }
761#define side_attr_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY32), .u = { .float_value = { .side_float_binary32 = (_val) } } }
762#define side_attr_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY64), .u = { .float_value = { .side_float_binary64 = (_val) } } }
763#define side_attr_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY128), .u = { .float_value = { .side_float_binary128 = (_val) } } }
67337c4a
MD
764
765#define _side_attr_string(_val, _byte_order, _unit_size) \
766 { \
15f17024 767 .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_STRING), \
67337c4a
MD
768 .u = { \
769 .string_value = { \
d1251f44 770 .p = SIDE_PTR_INIT(_val), \
67337c4a 771 .unit_size = _unit_size, \
3bc9ba43 772 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
773 }, \
774 }, \
775 }
776
777#define side_attr_string(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t))
778#define side_attr_string16(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t))
779#define side_attr_string32(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t))
780
781/* Stack-copy enumeration type definitions */
782
d5a4e361 783#define side_define_enum(_identifier, _mappings, _attr...) \
67337c4a 784 const struct side_enum_mappings _identifier = { \
64037418 785 .mappings = SIDE_PTR_INIT(_mappings), \
12d787db 786 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 787 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
d5a4e361 788 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
789 }
790
791#define side_enum_mapping_list(...) \
792 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
793
794#define side_enum_mapping_range(_label, _begin, _end) \
795 { \
796 .range_begin = _begin, \
797 .range_end = _end, \
798 .label = { \
d1251f44 799 .p = SIDE_PTR_INIT(_label), \
67337c4a 800 .unit_size = sizeof(uint8_t), \
3bc9ba43 801 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
67337c4a
MD
802 }, \
803 }
804
805#define side_enum_mapping_value(_label, _value) \
806 { \
807 .range_begin = _value, \
808 .range_end = _value, \
809 .label = { \
d1251f44 810 .p = SIDE_PTR_INIT(_label), \
67337c4a 811 .unit_size = sizeof(uint8_t), \
3bc9ba43 812 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
67337c4a
MD
813 }, \
814 }
815
d5a4e361 816#define side_define_enum_bitmap(_identifier, _mappings, _attr...) \
67337c4a 817 const struct side_enum_bitmap_mappings _identifier = { \
64037418 818 .mappings = SIDE_PTR_INIT(_mappings), \
12d787db 819 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 820 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
d5a4e361 821 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
822 }
823
824#define side_enum_bitmap_mapping_list(...) \
825 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
826
827#define side_enum_bitmap_mapping_range(_label, _begin, _end) \
828 { \
829 .range_begin = _begin, \
830 .range_end = _end, \
831 .label = { \
d1251f44 832 .p = SIDE_PTR_INIT(_label), \
67337c4a 833 .unit_size = sizeof(uint8_t), \
3bc9ba43 834 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
67337c4a
MD
835 }, \
836 }
837
838#define side_enum_bitmap_mapping_value(_label, _value) \
839 { \
840 .range_begin = _value, \
841 .range_end = _value, \
842 .label = { \
d1251f44 843 .p = SIDE_PTR_INIT(_label), \
67337c4a 844 .unit_size = sizeof(uint8_t), \
3bc9ba43 845 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
67337c4a
MD
846 }, \
847 }
848
849/* Stack-copy field and type definitions */
850
d5a4e361 851#define side_type_null(_attr...) \
67337c4a 852 { \
3ce69bfa 853 .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL), \
67337c4a
MD
854 .u = { \
855 .side_null = { \
b313067b 856 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 857 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
858 }, \
859 }, \
860 }
861
d5a4e361 862#define side_type_bool(_attr...) \
67337c4a 863 { \
3ce69bfa 864 .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), \
67337c4a
MD
865 .u = { \
866 .side_bool = { \
db8df9b5 867 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 868 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
869 .bool_size = sizeof(uint8_t), \
870 .len_bits = 0, \
3bc9ba43 871 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
67337c4a
MD
872 }, \
873 }, \
874 }
875
d5a4e361 876#define side_type_byte(_attr...) \
67337c4a 877 { \
3ce69bfa 878 .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), \
67337c4a
MD
879 .u = { \
880 .side_byte = { \
12d787db 881 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 882 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
883 }, \
884 }, \
885 }
886
887#define _side_type_string(_type, _byte_order, _unit_size, _attr) \
888 { \
3ce69bfa 889 .type = SIDE_ENUM_INIT(_type), \
67337c4a
MD
890 .u = { \
891 .side_string = { \
12d787db 892 .attr = SIDE_PTR_INIT(_attr), \
67337c4a
MD
893 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
894 .unit_size = _unit_size, \
3bc9ba43 895 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
896 }, \
897 }, \
898 }
899
900#define side_type_dynamic() \
901 { \
3ce69bfa 902 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC), \
67337c4a
MD
903 }
904
905#define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
906 { \
3ce69bfa 907 .type = SIDE_ENUM_INIT(_type), \
67337c4a
MD
908 .u = { \
909 .side_integer = { \
12d787db 910 .attr = SIDE_PTR_INIT(_attr), \
67337c4a
MD
911 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
912 .integer_size = _integer_size, \
913 .len_bits = _len_bits, \
914 .signedness = _signedness, \
3bc9ba43 915 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
916 }, \
917 }, \
918 }
919
920#define _side_type_float(_type, _byte_order, _float_size, _attr) \
921 { \
3ce69bfa 922 .type = SIDE_ENUM_INIT(_type), \
67337c4a
MD
923 .u = { \
924 .side_float = { \
12d787db 925 .attr = SIDE_PTR_INIT(_attr), \
67337c4a
MD
926 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
927 .float_size = _float_size, \
3bc9ba43 928 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
929 }, \
930 }, \
931 }
932
933#define _side_field(_name, _type) \
934 { \
c5789285 935 .field_name = SIDE_PTR_INIT(_name), \
67337c4a
MD
936 .side_type = _type, \
937 }
938
5530345d
MD
939#define side_option_range(_range_begin, _range_end, _type) \
940 { \
941 .range_begin = _range_begin, \
942 .range_end = _range_end, \
943 .side_type = _type, \
944 }
945
946#define side_option(_value, _type) \
947 side_option_range(_value, _value, SIDE_PARAM(_type))
948
67337c4a 949/* Host endian */
d5a4e361
MD
950#define side_type_u8(_attr...) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
951#define side_type_u16(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
952#define side_type_u32(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
953#define side_type_u64(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
954#define side_type_s8(_attr...) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
955#define side_type_s16(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
956#define side_type_s32(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
957#define side_type_s64(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
958#define side_type_pointer(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
959#define side_type_float_binary16(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
960#define side_type_float_binary32(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
961#define side_type_float_binary64(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
962#define side_type_float_binary128(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
963#define side_type_string(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF8, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
964#define side_type_string16(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
965#define side_type_string32(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
966
967#define side_field_null(_name, _attr...) _side_field(_name, side_type_null(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
968#define side_field_bool(_name, _attr...) _side_field(_name, side_type_bool(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
969#define side_field_u8(_name, _attr...) _side_field(_name, side_type_u8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
970#define side_field_u16(_name, _attr...) _side_field(_name, side_type_u16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
971#define side_field_u32(_name, _attr...) _side_field(_name, side_type_u32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
972#define side_field_u64(_name, _attr...) _side_field(_name, side_type_u64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
973#define side_field_s8(_name, _attr...) _side_field(_name, side_type_s8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
974#define side_field_s16(_name, _attr...) _side_field(_name, side_type_s16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
975#define side_field_s32(_name, _attr...) _side_field(_name, side_type_s32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
976#define side_field_s64(_name, _attr...) _side_field(_name, side_type_s64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
977#define side_field_byte(_name, _attr...) _side_field(_name, side_type_byte(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
978#define side_field_pointer(_name, _attr...) _side_field(_name, side_type_pointer(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
979#define side_field_float_binary16(_name, _attr...) _side_field(_name, side_type_float_binary16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
980#define side_field_float_binary32(_name, _attr...) _side_field(_name, side_type_float_binary32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
981#define side_field_float_binary64(_name, _attr...) _side_field(_name, side_type_float_binary64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
982#define side_field_float_binary128(_name, _attr...) _side_field(_name, side_type_float_binary128(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
983#define side_field_string(_name, _attr...) _side_field(_name, side_type_string(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
984#define side_field_string16(_name, _attr...) _side_field(_name, side_type_string16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
985#define side_field_string32(_name, _attr...) _side_field(_name, side_type_string32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a
MD
986#define side_field_dynamic(_name) _side_field(_name, side_type_dynamic())
987
988/* Little endian */
d5a4e361
MD
989#define side_type_u16_le(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
990#define side_type_u32_le(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
991#define side_type_u64_le(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
992#define side_type_s16_le(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
993#define side_type_s32_le(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
994#define side_type_s64_le(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
995#define side_type_pointer_le(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
996#define side_type_float_binary16_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
997#define side_type_float_binary32_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
998#define side_type_float_binary64_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
999#define side_type_float_binary128_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1000#define side_type_string16_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1001#define side_type_string32_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1002
1003#define side_field_u16_le(_name, _attr...) _side_field(_name, side_type_u16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1004#define side_field_u32_le(_name, _attr...) _side_field(_name, side_type_u32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1005#define side_field_u64_le(_name, _attr...) _side_field(_name, side_type_u64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1006#define side_field_s16_le(_name, _attr...) _side_field(_name, side_type_s16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1007#define side_field_s32_le(_name, _attr...) _side_field(_name, side_type_s32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1008#define side_field_s64_le(_name, _attr...) _side_field(_name, side_type_s64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1009#define side_field_pointer_le(_name, _attr...) _side_field(_name, side_type_pointer_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1010#define side_field_float_binary16_le(_name, _attr...) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1011#define side_field_float_binary32_le(_name, _attr...) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1012#define side_field_float_binary64_le(_name, _attr...) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1013#define side_field_float_binary128_le(_name, _attr...) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1014#define side_field_string16_le(_name, _attr...) _side_field(_name, side_type_string16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1015#define side_field_string32_le(_name, _attr...) _side_field(_name, side_type_string32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a
MD
1016
1017/* Big endian */
d5a4e361
MD
1018#define side_type_u16_be(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1019#define side_type_u32_be(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1020#define side_type_u64_be(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1021#define side_type_s16_be(_attr...) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1022#define side_type_s32_be(_attr...) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1023#define side_type_s64_be(_attr...) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1024#define side_type_pointer_be(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1025#define side_type_float_binary16_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1026#define side_type_float_binary32_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1027#define side_type_float_binary64_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1028#define side_type_float_binary128_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1029#define side_type_string16_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1030#define side_type_string32_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1031
1032#define side_field_u16_be(_name, _attr...) _side_field(_name, side_type_u16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1033#define side_field_u32_be(_name, _attr...) _side_field(_name, side_type_u32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1034#define side_field_u64_be(_name, _attr...) _side_field(_name, side_type_u64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1035#define side_field_s16_be(_name, _attr...) _side_field(_name, side_type_s16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1036#define side_field_s32_be(_name, _attr...) _side_field(_name, side_type_s32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1037#define side_field_s64_be(_name, _attr...) _side_field(_name, side_type_s64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1038#define side_field_pointer_be(_name, _attr...) _side_field(_name, side_type_pointer_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1039#define side_field_float_binary16_be(_name, _attr...) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1040#define side_field_float_binary32_be(_name, _attr...) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1041#define side_field_float_binary64_be(_name, _attr...) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1042#define side_field_float_binary128_be(_name, _attr...) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1043#define side_field_string16_be(_name, _attr...) _side_field(_name, side_type_string16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1044#define side_field_string32_be(_name, _attr...) _side_field(_name, side_type_string32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a
MD
1045
1046#define side_type_enum(_mappings, _elem_type) \
1047 { \
3ce69bfa 1048 .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM), \
67337c4a
MD
1049 .u = { \
1050 .side_enum = { \
64037418 1051 .mappings = SIDE_PTR_INIT(_mappings), \
c5789285 1052 .elem_type = SIDE_PTR_INIT(_elem_type), \
67337c4a
MD
1053 }, \
1054 }, \
1055 }
1056#define side_field_enum(_name, _mappings, _elem_type) \
1057 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1058
1059#define side_type_enum_bitmap(_mappings, _elem_type) \
1060 { \
3ce69bfa 1061 .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM_BITMAP), \
67337c4a
MD
1062 .u = { \
1063 .side_enum_bitmap = { \
64037418 1064 .mappings = SIDE_PTR_INIT(_mappings), \
c5789285 1065 .elem_type = SIDE_PTR_INIT(_elem_type), \
67337c4a
MD
1066 }, \
1067 }, \
1068 }
1069#define side_field_enum_bitmap(_name, _mappings, _elem_type) \
1070 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1071
1072#define side_type_struct(_struct) \
1073 { \
3ce69bfa 1074 .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), \
67337c4a 1075 .u = { \
c5789285 1076 .side_struct = SIDE_PTR_INIT(_struct), \
67337c4a
MD
1077 }, \
1078 }
1079#define side_field_struct(_name, _struct) \
1080 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
1081
1082#define _side_type_struct_define(_fields, _attr) \
1083 { \
c5789285 1084 .fields = SIDE_PTR_INIT(_fields), \
12d787db 1085 .attr = SIDE_PTR_INIT(_attr), \
67337c4a
MD
1086 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1087 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1088 }
1089
d5a4e361
MD
1090#define side_define_struct(_identifier, _fields, _attr...) \
1091 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1092
d5a4e361 1093#define side_struct_literal(_fields, _attr...) \
67337c4a 1094 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
d5a4e361 1095 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1096
5530345d
MD
1097#define side_type_variant(_variant) \
1098 { \
3ce69bfa 1099 .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \
5530345d 1100 .u = { \
c5789285 1101 .side_variant = SIDE_PTR_INIT(_variant), \
5530345d
MD
1102 }, \
1103 }
1104#define side_field_variant(_name, _variant) \
1105 _side_field(_name, side_type_variant(SIDE_PARAM(_variant)))
1106
1107#define _side_type_variant_define(_selector, _options, _attr) \
1108 { \
1109 .selector = _selector, \
c5789285 1110 .options = SIDE_PTR_INIT(_options), \
12d787db 1111 .attr = SIDE_PTR_INIT(_attr), \
5530345d
MD
1112 .nr_options = SIDE_ARRAY_SIZE(SIDE_PARAM(_options)), \
1113 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1114 }
1115
d5a4e361 1116#define side_define_variant(_identifier, _selector, _options, _attr...) \
5530345d 1117 const struct side_type_variant _identifier = \
d5a4e361 1118 _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
5530345d 1119
d5a4e361 1120#define side_variant_literal(_selector, _options, _attr...) \
5530345d 1121 SIDE_COMPOUND_LITERAL(const struct side_type_variant, \
d5a4e361 1122 _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
5530345d 1123
d5a4e361 1124#define side_type_array(_elem_type, _length, _attr...) \
67337c4a 1125 { \
3ce69bfa 1126 .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), \
67337c4a
MD
1127 .u = { \
1128 .side_array = { \
c5789285 1129 .elem_type = SIDE_PTR_INIT(_elem_type), \
12d787db 1130 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1131 .length = _length, \
d5a4e361 1132 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1133 }, \
1134 }, \
1135 }
d5a4e361
MD
1136#define side_field_array(_name, _elem_type, _length, _attr...) \
1137 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1138
d5a4e361 1139#define side_type_vla(_elem_type, _attr...) \
67337c4a 1140 { \
3ce69bfa 1141 .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), \
67337c4a
MD
1142 .u = { \
1143 .side_vla = { \
c5789285 1144 .elem_type = SIDE_PTR_INIT(_elem_type), \
12d787db 1145 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1146 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1147 }, \
1148 }, \
1149 }
d5a4e361
MD
1150#define side_field_vla(_name, _elem_type, _attr...) \
1151 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1152
d5a4e361 1153#define side_type_vla_visitor(_elem_type, _visitor, _attr...) \
67337c4a 1154 { \
3ce69bfa 1155 .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), \
67337c4a
MD
1156 .u = { \
1157 .side_vla_visitor = { \
c5789285 1158 .elem_type = SIDE_PTR_INIT(_elem_type), \
2e197497 1159 .visitor = SIDE_PTR_INIT(_visitor), \
12d787db 1160 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1161 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1162 }, \
1163 }, \
1164 }
d5a4e361
MD
1165#define side_field_vla_visitor(_name, _elem_type, _visitor, _attr...) \
1166 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a
MD
1167
1168/* Gather field and type definitions */
1169
d5a4e361 1170#define side_type_gather_byte(_offset, _access_mode, _attr...) \
67337c4a 1171 { \
3ce69bfa 1172 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), \
67337c4a
MD
1173 .u = { \
1174 .side_gather = { \
1175 .u = { \
1176 .side_byte = { \
1177 .offset = _offset, \
1178 .access_mode = _access_mode, \
1179 .type = { \
12d787db 1180 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1181 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1182 }, \
1183 }, \
1184 }, \
1185 }, \
1186 }, \
1187 }
d5a4e361
MD
1188#define side_field_gather_byte(_name, _offset, _access_mode, _attr...) \
1189 _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1190
d5a4e361 1191#define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
67337c4a 1192 { \
3ce69bfa 1193 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), \
67337c4a
MD
1194 .u = { \
1195 .side_gather = { \
1196 .u = { \
1197 .side_bool = { \
1198 .offset = _offset, \
1199 .access_mode = _access_mode, \
1200 .type = { \
db8df9b5 1201 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1202 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1203 .bool_size = _bool_size, \
1204 .len_bits = _len_bits, \
3bc9ba43 1205 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
1206 }, \
1207 .offset_bits = _offset_bits, \
1208 }, \
1209 }, \
1210 }, \
1211 }, \
1212 }
d5a4e361
MD
1213#define side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1214 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_HOST, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1215#define side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1216 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_LE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1217#define side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1218 _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_BE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1219
1220#define side_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1221 _side_field(_name, side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))))
1222#define side_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1223 _side_field(_name, side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))))
1224#define side_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1225 _side_field(_name, side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))))
67337c4a
MD
1226
1227#define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
d5a4e361 1228 _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
67337c4a 1229 { \
3ce69bfa 1230 .type = SIDE_ENUM_INIT(_type), \
67337c4a
MD
1231 .u = { \
1232 .side_gather = { \
1233 .u = { \
1234 .side_integer = { \
1235 .offset = _offset, \
1236 .access_mode = _access_mode, \
1237 .type = { \
12d787db 1238 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1239 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1240 .integer_size = _integer_size, \
1241 .len_bits = _len_bits, \
1242 .signedness = _signedness, \
3bc9ba43 1243 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
1244 }, \
1245 .offset_bits = _offset_bits, \
1246 }, \
1247 }, \
1248 }, \
1249 }, \
1250 }
1251
d5a4e361 1252#define side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
67337c4a 1253 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
d5a4e361
MD
1254 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1255#define side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
67337c4a 1256 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, \
d5a4e361 1257 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1258
d5a4e361 1259#define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
67337c4a 1260 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_LE, \
d5a4e361
MD
1261 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1262#define side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
67337c4a 1263 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_LE, \
d5a4e361 1264 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1265
d5a4e361 1266#define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
67337c4a 1267 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_BE, \
d5a4e361
MD
1268 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1269#define side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
67337c4a 1270 _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_BE, \
d5a4e361 1271 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1272
d5a4e361
MD
1273#define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1274 _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1275#define side_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1276 _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1277
d5a4e361
MD
1278#define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1279 _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1280#define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1281 _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1282
d5a4e361
MD
1283#define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1284 _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1285#define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
1286 _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1287
d5a4e361 1288#define side_type_gather_pointer(_offset, _access_mode, _attr...) \
67337c4a 1289 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, \
d5a4e361
MD
1290 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1291#define side_field_gather_pointer(_name, _offset, _access_mode, _attr...) \
1292 _side_field(_name, side_type_gather_pointer(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1293
d5a4e361 1294#define side_type_gather_pointer_le(_offset, _access_mode, _attr...) \
67337c4a 1295 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, \
d5a4e361
MD
1296 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1297#define side_field_gather_pointer_le(_name, _offset, _access_mode, _attr...) \
1298 _side_field(_name, side_type_gather_pointer_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1299
d5a4e361 1300#define side_type_gather_pointer_be(_offset, _access_mode, _attr...) \
67337c4a 1301 _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, \
d5a4e361
MD
1302 _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1303#define side_field_gather_pointer_be(_name, _offset, _access_mode, _attr...) \
1304 _side_field(_name, side_type_gather_pointer_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1305
d5a4e361 1306#define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr...) \
67337c4a 1307 { \
3ce69bfa 1308 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), \
67337c4a
MD
1309 .u = { \
1310 .side_gather = { \
1311 .u = { \
1312 .side_float = { \
1313 .offset = _offset, \
1314 .access_mode = _access_mode, \
1315 .type = { \
12d787db 1316 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1317 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1318 .float_size = _float_size, \
3bc9ba43 1319 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
1320 }, \
1321 }, \
1322 }, \
1323 }, \
1324 }, \
1325 }
1326
d5a4e361
MD
1327#define side_type_gather_float(_offset, _float_size, _access_mode, _attr...) \
1328 _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1329#define side_type_gather_float_le(_offset, _float_size, _access_mode, _attr...) \
1330 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1331#define side_type_gather_float_be(_offset, _float_size, _access_mode, _attr...) \
1332 _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1333
1334#define side_field_gather_float(_name, _offset, _float_size, _access_mode, _attr...) \
1335 _side_field(_name, side_type_gather_float(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1336#define side_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr...) \
1337 _side_field(_name, side_type_gather_float_le(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1338#define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr...) \
1339 _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1340
1341#define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr...) \
67337c4a 1342 { \
3ce69bfa 1343 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), \
67337c4a
MD
1344 .u = { \
1345 .side_gather = { \
1346 .u = { \
1347 .side_string = { \
1348 .offset = _offset, \
1349 .access_mode = _access_mode, \
1350 .type = { \
12d787db 1351 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1352 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1353 .unit_size = _unit_size, \
3bc9ba43 1354 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
1355 }, \
1356 }, \
1357 }, \
1358 }, \
1359 }, \
1360 }
d5a4e361
MD
1361#define side_type_gather_string(_offset, _access_mode, _attr...) \
1362 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1363#define side_field_gather_string(_name, _offset, _access_mode, _attr...) \
1364 _side_field(_name, side_type_gather_string(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1365
1366#define side_type_gather_string16(_offset, _access_mode, _attr...) \
1367 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1368#define side_type_gather_string16_le(_offset, _access_mode, _attr...) \
1369 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1370#define side_type_gather_string16_be(_offset, _access_mode, _attr...) \
1371 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1372
1373#define side_field_gather_string16(_name, _offset, _access_mode, _attr...) \
1374 _side_field(_name, side_type_gather_string16(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1375#define side_field_gather_string16_le(_name, _offset, _access_mode, _attr...) \
1376 _side_field(_name, side_type_gather_string16_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1377#define side_field_gather_string16_be(_name, _offset, _access_mode, _attr...) \
1378 _side_field(_name, side_type_gather_string16_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1379
1380#define side_type_gather_string32(_offset, _access_mode, _attr...) \
1381 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1382#define side_type_gather_string32_le(_offset, _access_mode, _attr...) \
1383 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1384#define side_type_gather_string32_be(_offset, _access_mode, _attr...) \
1385 _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1386
1387#define side_field_gather_string32(_name, _offset, _access_mode, _attr...) \
1388 _side_field(_name, side_type_gather_string32(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1389#define side_field_gather_string32_le(_name, _offset, _access_mode, _attr...) \
1390 _side_field(_name, side_type_gather_string32_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
1391#define side_field_gather_string32_be(_name, _offset, _access_mode, _attr...) \
1392 _side_field(_name, side_type_gather_string32_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a
MD
1393
1394#define side_type_gather_enum(_mappings, _elem_type) \
1395 { \
3ce69bfa 1396 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ENUM), \
67337c4a
MD
1397 .u = { \
1398 .side_enum = { \
64037418 1399 .mappings = SIDE_PTR_INIT(_mappings), \
c5789285 1400 .elem_type = SIDE_PTR_INIT(_elem_type), \
67337c4a
MD
1401 }, \
1402 }, \
1403 }
1404#define side_field_gather_enum(_name, _mappings, _elem_type) \
1405 _side_field(_name, side_type_gather_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
1406
1407#define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
1408 { \
3ce69bfa 1409 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), \
67337c4a
MD
1410 .u = { \
1411 .side_gather = { \
1412 .u = { \
1413 .side_struct = { \
1414 .offset = _offset, \
1415 .access_mode = _access_mode, \
c5789285 1416 .type = SIDE_PTR_INIT(_struct_gather), \
67337c4a
MD
1417 .size = _size, \
1418 }, \
1419 }, \
1420 }, \
1421 }, \
1422 }
1423#define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \
1424 _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode))
1425
d5a4e361 1426#define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr...) \
67337c4a 1427 { \
3ce69bfa 1428 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), \
67337c4a
MD
1429 .u = { \
1430 .side_gather = { \
1431 .u = { \
1432 .side_array = { \
1433 .offset = _offset, \
1434 .access_mode = _access_mode, \
1435 .type = { \
c5789285 1436 .elem_type = SIDE_PTR_INIT(_elem_type_gather), \
12d787db 1437 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1438 .length = _length, \
d5a4e361 1439 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1440 }, \
1441 }, \
1442 }, \
1443 }, \
1444 }, \
1445 }
d5a4e361
MD
1446#define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr...) \
1447 _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a 1448
d5a4e361 1449#define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \
67337c4a 1450 { \
3ce69bfa 1451 .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), \
67337c4a
MD
1452 .u = { \
1453 .side_gather = { \
1454 .u = { \
1455 .side_vla = { \
c5789285 1456 .length_type = SIDE_PTR_INIT(_length_type_gather), \
67337c4a
MD
1457 .offset = _offset, \
1458 .access_mode = _access_mode, \
1459 .type = { \
c5789285 1460 .elem_type = SIDE_PTR_INIT(_elem_type_gather), \
12d787db 1461 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1462 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1463 }, \
1464 }, \
1465 }, \
1466 }, \
1467 }, \
1468 }
d5a4e361
MD
1469#define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \
1470 _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
67337c4a
MD
1471
1472#define side_elem(...) \
1473 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1474
1475#define side_length(...) \
1476 SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__)
1477
1478#define side_field_list(...) \
1479 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
1480
5530345d
MD
1481#define side_option_list(...) \
1482 SIDE_COMPOUND_LITERAL(const struct side_variant_option, __VA_ARGS__)
1483
67337c4a
MD
1484/* Stack-copy field arguments */
1485
3ce69bfa
MD
1486#define side_arg_null(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL) }
1487#define side_arg_bool(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } }
1488#define side_arg_byte(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), .u = { .side_static = { .byte_value = (_val) } } }
1489#define side_arg_string(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF8), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
1490#define side_arg_string16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF16), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
1491#define side_arg_string32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF32), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
1492
1493#define side_arg_u8(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U8), .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
1494#define side_arg_u16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U16), .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
1495#define side_arg_u32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U32), .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
1496#define side_arg_u64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_U64), .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
1497#define side_arg_s8(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S8), .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
1498#define side_arg_s16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S16), .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
1499#define side_arg_s32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S32), .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
1500#define side_arg_s64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_S64), .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
1501#define side_arg_pointer(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_POINTER), .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } }
1502#define side_arg_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY16), .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
1503#define side_arg_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY32), .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
1504#define side_arg_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY64), .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
1505#define side_arg_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY128), .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
1506
1507#define side_arg_struct(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), .u = { .side_static = { .side_struct = SIDE_PTR_INIT(_side_type) } } }
5530345d
MD
1508
1509#define side_arg_define_variant(_identifier, _selector_val, _option) \
1510 const struct side_arg_variant _identifier = { \
1511 .selector = _selector_val, \
1512 .option = _option, \
1513 }
1514#define side_arg_variant(_side_variant) \
1515 { \
3ce69bfa 1516 .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \
5530345d
MD
1517 .u = { \
1518 .side_static = { \
bac71609 1519 .side_variant = SIDE_PTR_INIT(_side_variant), \
5530345d
MD
1520 }, \
1521 }, \
1522 }
1523
3ce69bfa
MD
1524#define side_arg_array(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), .u = { .side_static = { .side_array = SIDE_PTR_INIT(_side_type) } } }
1525#define side_arg_vla(_side_type) { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), .u = { .side_static = { .side_vla = SIDE_PTR_INIT(_side_type) } } }
1526#define side_arg_vla_visitor(_ctx) { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
67337c4a
MD
1527
1528/* Gather field arguments */
1529
3ce69bfa
MD
1530#define side_arg_gather_bool(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), .u = { .side_static = { .side_bool_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1531#define side_arg_gather_byte(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), .u = { .side_static = { .side_byte_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1532#define side_arg_gather_pointer(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_POINTER), .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1533#define side_arg_gather_integer(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_INTEGER), .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1534#define side_arg_gather_float(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), .u = { .side_static = { .side_float_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1535#define side_arg_gather_string(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), .u = { .side_static = { .side_string_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1536#define side_arg_gather_struct(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), .u = { .side_static = { .side_struct_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1537#define side_arg_gather_array(_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), .u = { .side_static = { .side_array_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
1538#define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), .u = { .side_static = { .side_vla_gather = { .ptr = SIDE_PTR_INIT(_ptr), .length_ptr = SIDE_PTR_INIT(_length_ptr) } } } }
67337c4a
MD
1539
1540/* Dynamic field arguments */
1541
d5a4e361 1542#define side_arg_dynamic_null(_attr...) \
67337c4a 1543 { \
3ce69bfa 1544 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_NULL), \
67337c4a
MD
1545 .u = { \
1546 .side_dynamic = { \
1547 .side_null = { \
b313067b 1548 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1549 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1550 }, \
1551 }, \
1552 }, \
1553 }
1554
d5a4e361 1555#define side_arg_dynamic_bool(_val, _attr...) \
67337c4a 1556 { \
3ce69bfa 1557 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BOOL), \
67337c4a
MD
1558 .u = { \
1559 .side_dynamic = { \
1560 .side_bool = { \
1561 .type = { \
db8df9b5 1562 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1563 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1564 .bool_size = sizeof(uint8_t), \
1565 .len_bits = 0, \
3bc9ba43 1566 .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
67337c4a
MD
1567 }, \
1568 .value = { \
1569 .side_bool8 = !!(_val), \
1570 }, \
1571 }, \
1572 }, \
1573 }, \
1574 }
1575
d5a4e361 1576#define side_arg_dynamic_byte(_val, _attr...) \
67337c4a 1577 { \
3ce69bfa 1578 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BYTE), \
67337c4a
MD
1579 .u = { \
1580 .side_dynamic = { \
1581 .side_byte = { \
1582 .type = { \
12d787db 1583 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1584 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1585 }, \
1586 .value = (_val), \
1587 }, \
1588 }, \
1589 }, \
1590 }
d5a4e361
MD
1591
1592#define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr...) \
67337c4a 1593 { \
3ce69bfa 1594 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRING), \
67337c4a
MD
1595 .u = { \
1596 .side_dynamic = { \
1597 .side_string = { \
1598 .type = { \
12d787db 1599 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1600 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1601 .unit_size = _unit_size, \
3bc9ba43 1602 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
1603 }, \
1604 .value = (uintptr_t) (_val), \
1605 }, \
1606 }, \
1607 }, \
1608 }
d5a4e361
MD
1609#define side_arg_dynamic_string(_val, _attr...) \
1610 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1611#define side_arg_dynamic_string16(_val, _attr...) \
1612 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1613#define side_arg_dynamic_string16_le(_val, _attr...) \
1614 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1615#define side_arg_dynamic_string16_be(_val, _attr...) \
1616 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1617#define side_arg_dynamic_string32(_val, _attr...) \
1618 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1619#define side_arg_dynamic_string32_le(_val, _attr...) \
1620 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1621#define side_arg_dynamic_string32_be(_val, _attr...) \
1622 _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1623
1624#define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr...) \
67337c4a 1625 { \
3ce69bfa 1626 .type = SIDE_ENUM_INIT(_type), \
67337c4a
MD
1627 .u = { \
1628 .side_dynamic = { \
1629 .side_integer = { \
1630 .type = { \
12d787db 1631 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1632 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1633 .integer_size = _integer_size, \
1634 .len_bits = _len_bits, \
1635 .signedness = _signedness, \
3bc9ba43 1636 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
1637 }, \
1638 .value = { \
1639 _field = (_val), \
1640 }, \
1641 }, \
1642 }, \
1643 }, \
1644 }
1645
d5a4e361
MD
1646#define side_arg_dynamic_u8(_val, _attr...) \
1647 _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1648#define side_arg_dynamic_s8(_val, _attr...) \
1649 _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1650
1651#define _side_arg_dynamic_u16(_val, _byte_order, _attr...) \
1652 _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1653#define _side_arg_dynamic_u32(_val, _byte_order, _attr...) \
1654 _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1655#define _side_arg_dynamic_u64(_val, _byte_order, _attr...) \
1656 _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1657
1658#define _side_arg_dynamic_s16(_val, _byte_order, _attr...) \
1659 _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1660#define _side_arg_dynamic_s32(_val, _byte_order, _attr...) \
1661 _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1662#define _side_arg_dynamic_s64(_val, _byte_order, _attr...) \
1663 _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1664
1665#define _side_arg_dynamic_pointer(_val, _byte_order, _attr...) \
67337c4a 1666 _side_arg_dynamic_integer(.side_uptr, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER, false, _byte_order, \
d5a4e361 1667 sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1668
d5a4e361 1669#define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr...) \
67337c4a 1670 { \
3ce69bfa 1671 .type = SIDE_ENUM_INIT(_type), \
67337c4a
MD
1672 .u = { \
1673 .side_dynamic = { \
1674 .side_float = { \
1675 .type = { \
12d787db 1676 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1677 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1678 .float_size = _float_size, \
3bc9ba43 1679 .byte_order = SIDE_ENUM_INIT(_byte_order), \
67337c4a
MD
1680 }, \
1681 .value = { \
1682 _field = (_val), \
1683 }, \
1684 }, \
1685 }, \
1686 }, \
1687 }
1688
d5a4e361
MD
1689#define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr...) \
1690 _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1691#define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr...) \
1692 _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1693#define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr...) \
1694 _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1695#define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr...) \
1696 _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a
MD
1697
1698/* Host endian */
d5a4e361
MD
1699#define side_arg_dynamic_u16(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1700#define side_arg_dynamic_u32(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1701#define side_arg_dynamic_u64(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1702#define side_arg_dynamic_s16(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1703#define side_arg_dynamic_s32(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1704#define side_arg_dynamic_s64(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1705#define side_arg_dynamic_pointer(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1706#define side_arg_dynamic_float_binary16(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1707#define side_arg_dynamic_float_binary32(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1708#define side_arg_dynamic_float_binary64(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1709#define side_arg_dynamic_float_binary128(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a
MD
1710
1711/* Little endian */
d5a4e361
MD
1712#define side_arg_dynamic_u16_le(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1713#define side_arg_dynamic_u32_le(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1714#define side_arg_dynamic_u64_le(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1715#define side_arg_dynamic_s16_le(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1716#define side_arg_dynamic_s32_le(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1717#define side_arg_dynamic_s64_le(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1718#define side_arg_dynamic_pointer_le(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1719#define side_arg_dynamic_float_binary16_le(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1720#define side_arg_dynamic_float_binary32_le(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1721#define side_arg_dynamic_float_binary64_le(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1722#define side_arg_dynamic_float_binary128_le(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a
MD
1723
1724/* Big endian */
d5a4e361
MD
1725#define side_arg_dynamic_u16_be(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1726#define side_arg_dynamic_u32_be(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1727#define side_arg_dynamic_u64_be(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1728#define side_arg_dynamic_s16_be(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1729#define side_arg_dynamic_s32_be(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1730#define side_arg_dynamic_s64_be(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1731#define side_arg_dynamic_pointer_be(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1732#define side_arg_dynamic_float_binary16_be(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1733#define side_arg_dynamic_float_binary32_be(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1734#define side_arg_dynamic_float_binary64_be(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
1735#define side_arg_dynamic_float_binary128_be(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a
MD
1736
1737#define side_arg_dynamic_vla(_vla) \
1738 { \
3ce69bfa 1739 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA), \
67337c4a
MD
1740 .u = { \
1741 .side_dynamic = { \
f13253cb 1742 .side_dynamic_vla = SIDE_PTR_INIT(_vla), \
67337c4a
MD
1743 }, \
1744 }, \
1745 }
1746
d5a4e361 1747#define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr...) \
67337c4a 1748 { \
3ce69bfa 1749 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA_VISITOR), \
67337c4a
MD
1750 .u = { \
1751 .side_dynamic = { \
1752 .side_dynamic_vla_visitor = { \
2e197497
MD
1753 .app_ctx = SIDE_PTR_INIT(_ctx), \
1754 .visitor = SIDE_PTR_INIT(_dynamic_vla_visitor), \
12d787db 1755 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1756 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1757 }, \
1758 }, \
1759 }, \
1760 }
1761
1762#define side_arg_dynamic_struct(_struct) \
1763 { \
3ce69bfa 1764 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT), \
67337c4a
MD
1765 .u = { \
1766 .side_dynamic = { \
f13253cb 1767 .side_dynamic_struct = SIDE_PTR_INIT(_struct), \
67337c4a
MD
1768 }, \
1769 }, \
1770 }
1771
d5a4e361 1772#define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr...) \
67337c4a 1773 { \
3ce69bfa 1774 .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT_VISITOR), \
67337c4a
MD
1775 .u = { \
1776 .side_dynamic = { \
1777 .side_dynamic_struct_visitor = { \
2e197497
MD
1778 .app_ctx = SIDE_PTR_INIT(_ctx), \
1779 .visitor = SIDE_PTR_INIT(_dynamic_struct_visitor), \
12d787db 1780 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
d5a4e361 1781 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1782 }, \
1783 }, \
1784 }, \
1785 }
1786
d5a4e361 1787#define side_arg_dynamic_define_vec(_identifier, _sav, _attr...) \
67337c4a
MD
1788 const struct side_arg _identifier##_vec[] = { _sav }; \
1789 const struct side_arg_dynamic_vla _identifier = { \
f13253cb 1790 .sav = SIDE_PTR_INIT(_identifier##_vec), \
12d787db 1791 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1792 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
d5a4e361 1793 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1794 }
1795
d5a4e361 1796#define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr...) \
67337c4a
MD
1797 const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \
1798 const struct side_arg_dynamic_struct _identifier = { \
f13253cb 1799 .fields = SIDE_PTR_INIT(_identifier##_fields), \
12d787db 1800 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1801 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
d5a4e361 1802 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1803 }
1804
1805#define side_arg_define_vec(_identifier, _sav) \
1806 const struct side_arg _identifier##_vec[] = { _sav }; \
1807 const struct side_arg_vec _identifier = { \
f13253cb 1808 .sav = SIDE_PTR_INIT(_identifier##_vec), \
67337c4a
MD
1809 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1810 }
1811
1812#define side_arg_dynamic_field(_name, _elem) \
1813 { \
f13253cb 1814 .field_name = SIDE_PTR_INIT(_name), \
67337c4a
MD
1815 .elem = _elem, \
1816 }
1817
1818/*
1819 * Event instrumentation description registration, runtime enabled state
1820 * check, and instrumentation invocation.
1821 */
1822
1823#define side_arg_list(...) __VA_ARGS__
1824
1825#define side_event_cond(_identifier) \
6c12af2c 1826 if (side_unlikely(__atomic_load_n(&side_event_state__##_identifier.enabled, \
67337c4a
MD
1827 __ATOMIC_RELAXED)))
1828
1829#define side_event_call(_identifier, _sav) \
1830 { \
1831 const struct side_arg side_sav[] = { _sav }; \
1832 const struct side_arg_vec side_arg_vec = { \
f13253cb 1833 .sav = SIDE_PTR_INIT(side_sav), \
67337c4a
MD
1834 .len = SIDE_ARRAY_SIZE(side_sav), \
1835 }; \
0d747f98 1836 side_call(&(side_event_state__##_identifier), &side_arg_vec); \
67337c4a
MD
1837 }
1838
1839#define side_event(_identifier, _sav) \
1840 side_event_cond(_identifier) \
1841 side_event_call(_identifier, SIDE_PARAM(_sav))
1842
d5a4e361 1843#define side_event_call_variadic(_identifier, _sav, _var_fields, _attr...) \
67337c4a
MD
1844 { \
1845 const struct side_arg side_sav[] = { _sav }; \
1846 const struct side_arg_vec side_arg_vec = { \
f13253cb 1847 .sav = SIDE_PTR_INIT(side_sav), \
67337c4a
MD
1848 .len = SIDE_ARRAY_SIZE(side_sav), \
1849 }; \
1850 const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \
1851 const struct side_arg_dynamic_struct var_struct = { \
f13253cb 1852 .fields = SIDE_PTR_INIT(side_fields), \
12d787db 1853 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1854 .len = SIDE_ARRAY_SIZE(side_fields), \
d5a4e361 1855 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a 1856 }; \
0d747f98 1857 side_call_variadic(&(side_event_state__##_identifier), &side_arg_vec, &var_struct); \
67337c4a
MD
1858 }
1859
d5a4e361 1860#define side_event_variadic(_identifier, _sav, _var, _attr...) \
67337c4a 1861 side_event_cond(_identifier) \
d5a4e361 1862 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1863
d5a4e361 1864#define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _flags, _attr...) \
0d747f98
MD
1865 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1866 _identifier; \
6c12af2c
MD
1867 _linkage struct side_event_state __attribute__((section("side_event_state"))) \
1868 side_event_state__##_identifier = { \
1869 .enabled = 0, \
1870 .callbacks = &side_empty_callback, \
39fe9c03 1871 .desc = &(_identifier), \
6c12af2c 1872 }; \
67337c4a
MD
1873 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1874 _identifier = { \
0b9e59d6
MD
1875 .state = SIDE_PTR_INIT(&(side_event_state__##_identifier)), \
1876 .provider_name = SIDE_PTR_INIT(_provider), \
1877 .event_name = SIDE_PTR_INIT(_event), \
1878 .fields = SIDE_PTR_INIT(_fields), \
12d787db 1879 .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
67337c4a
MD
1880 .flags = (_flags), \
1881 .version = 0, \
1f7aaefb 1882 .loglevel = SIDE_ENUM_INIT(_loglevel), \
67337c4a 1883 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
d5a4e361 1884 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
f8188f94 1885 .nr_callbacks = 0, \
67337c4a
MD
1886 }; \
1887 static const struct side_event_description *side_event_ptr__##_identifier \
1888 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1889
d5a4e361 1890#define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
67337c4a 1891 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
d5a4e361 1892 0, ##_attr)
67337c4a 1893
d5a4e361 1894#define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
67337c4a 1895 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
d5a4e361 1896 SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1897
d5a4e361 1898#define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
67337c4a 1899 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
d5a4e361 1900 _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1901
d5a4e361 1902#define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
67337c4a 1903 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
d5a4e361 1904 _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1905
d5a4e361 1906#define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
67337c4a 1907 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
d5a4e361 1908 _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a 1909
d5a4e361 1910#define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \
67337c4a 1911 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
d5a4e361 1912 _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
67337c4a
MD
1913
1914#define side_declare_event(_identifier) \
6c12af2c 1915 extern struct side_event_state side_event_state_##_identifier; \
67337c4a
MD
1916 extern struct side_event_description _identifier
1917
1918#ifdef __cplusplus
1919extern "C" {
1920#endif
1921
2e197497
MD
1922struct side_callback {
1923 union {
1924 void (*call)(const struct side_event_description *desc,
1925 const struct side_arg_vec *side_arg_vec,
1926 void *priv);
1927 void (*call_variadic)(const struct side_event_description *desc,
1928 const struct side_arg_vec *side_arg_vec,
1929 const struct side_arg_dynamic_struct *var_struct,
1930 void *priv);
1931 } SIDE_PACKED u;
1932 void *priv;
1933} SIDE_PACKED;
1934
1935/* The visitor pattern is a double-dispatch visitor. */
1936struct side_tracer_visitor_ctx {
1937 side_write_elem_func write_elem;
1938 void *priv; /* Private tracer context. */
1939} SIDE_PACKED;
1940
1941struct side_tracer_dynamic_struct_visitor_ctx {
1942 side_write_field_func write_field;
1943 void *priv; /* Private tracer context. */
1944} SIDE_PACKED;
1945
67337c4a
MD
1946extern const struct side_callback side_empty_callback;
1947
0d747f98 1948void side_call(const struct side_event_state *state,
67337c4a 1949 const struct side_arg_vec *side_arg_vec);
0d747f98 1950void side_call_variadic(const struct side_event_state *state,
67337c4a
MD
1951 const struct side_arg_vec *side_arg_vec,
1952 const struct side_arg_dynamic_struct *var_struct);
1953
1954struct side_events_register_handle *side_events_register(struct side_event_description **events,
1955 uint32_t nr_events);
1956void side_events_unregister(struct side_events_register_handle *handle);
1957
1958/*
1959 * Userspace tracer registration API. This allows userspace tracers to
1960 * register event notification callbacks to be notified of the currently
1961 * registered instrumentation, and to register their callbacks to
1962 * specific events.
1963 */
1964typedef void (*side_tracer_callback_func)(const struct side_event_description *desc,
1965 const struct side_arg_vec *side_arg_vec,
1966 void *priv);
1967typedef void (*side_tracer_callback_variadic_func)(const struct side_event_description *desc,
1968 const struct side_arg_vec *side_arg_vec,
1969 const struct side_arg_dynamic_struct *var_struct,
1970 void *priv);
1971
1972int side_tracer_callback_register(struct side_event_description *desc,
1973 side_tracer_callback_func call,
1974 void *priv);
1975int side_tracer_callback_variadic_register(struct side_event_description *desc,
1976 side_tracer_callback_variadic_func call_variadic,
1977 void *priv);
1978int side_tracer_callback_unregister(struct side_event_description *desc,
1979 side_tracer_callback_func call,
1980 void *priv);
1981int side_tracer_callback_variadic_unregister(struct side_event_description *desc,
1982 side_tracer_callback_variadic_func call_variadic,
1983 void *priv);
1984
1985enum side_tracer_notification {
1986 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS,
1987 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS,
1988};
1989
1990/* Callback is invoked with side library internal lock held. */
1991struct side_tracer_handle *side_tracer_event_notification_register(
1992 void (*cb)(enum side_tracer_notification notif,
1993 struct side_event_description **events, uint32_t nr_events, void *priv),
1994 void *priv);
1995void side_tracer_event_notification_unregister(struct side_tracer_handle *handle);
1996
1997/*
1998 * Explicit hooks to initialize/finalize the side instrumentation
1999 * library. Those are also library constructor/destructor.
2000 */
2001void side_init(void) __attribute__((constructor));
2002void side_exit(void) __attribute__((destructor));
2003
2004/*
2005 * The following constructors/destructors perform automatic registration
2006 * of the declared side events. Those may have to be called explicitly
2007 * in a statically linked library.
2008 */
2009
2010/*
2011 * These weak symbols, the constructor, and destructor take care of
2012 * registering only _one_ instance of the side instrumentation per
2013 * shared-ojbect (or for the whole main program).
2014 */
2015extern struct side_event_description * __start_side_event_description_ptr[]
2016 __attribute__((weak, visibility("hidden")));
2017extern struct side_event_description * __stop_side_event_description_ptr[]
2018 __attribute__((weak, visibility("hidden")));
2019int side_event_description_ptr_registered
2020 __attribute__((weak, visibility("hidden")));
2021struct side_events_register_handle *side_events_handle
2022 __attribute__((weak, visibility("hidden")));
2023
2024static void
2025side_event_description_ptr_init(void)
2026 __attribute__((no_instrument_function))
2027 __attribute__((constructor));
2028static void
2029side_event_description_ptr_init(void)
2030{
2031 if (side_event_description_ptr_registered++)
2032 return;
2033 side_events_handle = side_events_register(__start_side_event_description_ptr,
2034 __stop_side_event_description_ptr - __start_side_event_description_ptr);
2035}
2036
2037static void
2038side_event_description_ptr_exit(void)
2039 __attribute__((no_instrument_function))
2040 __attribute__((destructor));
2041static void
2042side_event_description_ptr_exit(void)
2043{
2044 if (--side_event_description_ptr_registered)
2045 return;
2046 side_events_unregister(side_events_handle);
2047 side_events_handle = NULL;
2048}
2049
2050#ifdef __cplusplus
2051}
2052#endif
2053
2054#endif /* _SIDE_TRACE_H */
This page took 0.122804 seconds and 4 git commands to generate.