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