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