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