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