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