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