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