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