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