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