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