Revert "Update gitignore"
[libside.git] / include / tgif / trace.h
CommitLineData
d04d4903
MD
1// SPDX-License-Identifier: MIT
2/*
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 */
5
6#ifndef _TGIF_TRACE_H
7#define _TGIF_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 <tgif/macros.h>
15#include <tgif/endian.h>
16
17/*
18 * TGIF stands for "Trace Generation Instrumentation Framework"
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 (tgif_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 TGIF_TYPE_DYNAMIC place holder in the stack-copy type system.
67 */
68
69//TODO: as those structures will be ABI, we need to either contgifr them
70//fixed forever, or think of a scheme that would allow their binary
71//representation to be extended if need be.
72
73struct tgif_arg;
74struct tgif_arg_vec;
75struct tgif_arg_dynamic;
76struct tgif_arg_dynamic_field;
77struct tgif_arg_dynamic_vla;
78struct tgif_type;
79struct tgif_event_field;
80struct tgif_tracer_visitor_ctx;
81struct tgif_tracer_dynamic_struct_visitor_ctx;
82struct tgif_event_description;
83struct tgif_arg_dynamic_struct;
84struct tgif_events_register_handle;
85
86enum tgif_type_label {
87 /* Stack-copy basic types */
88 TGIF_TYPE_NULL,
89 TGIF_TYPE_BOOL,
90 TGIF_TYPE_U8,
91 TGIF_TYPE_U16,
92 TGIF_TYPE_U32,
93 TGIF_TYPE_U64,
94 TGIF_TYPE_S8,
95 TGIF_TYPE_S16,
96 TGIF_TYPE_S32,
97 TGIF_TYPE_S64,
98 TGIF_TYPE_BYTE,
99 TGIF_TYPE_POINTER,
100 TGIF_TYPE_FLOAT_BINARY16,
101 TGIF_TYPE_FLOAT_BINARY32,
102 TGIF_TYPE_FLOAT_BINARY64,
103 TGIF_TYPE_FLOAT_BINARY128,
104 TGIF_TYPE_STRING_UTF8,
105 TGIF_TYPE_STRING_UTF16,
106 TGIF_TYPE_STRING_UTF32,
107
108 /* Stack-copy compound types */
109 TGIF_TYPE_STRUCT,
110 TGIF_TYPE_ARRAY,
111 TGIF_TYPE_VLA,
112 TGIF_TYPE_VLA_VISITOR,
113
114 /* Stack-copy enumeration types */
115 TGIF_TYPE_ENUM,
116 TGIF_TYPE_ENUM_BITMAP,
117
118 /* Stack-copy place holder for dynamic types */
119 TGIF_TYPE_DYNAMIC,
120
121 /* Gather basic types */
122 TGIF_TYPE_GATHER_BOOL,
123 TGIF_TYPE_GATHER_INTEGER,
124 TGIF_TYPE_GATHER_BYTE,
125 TGIF_TYPE_GATHER_POINTER,
126 TGIF_TYPE_GATHER_FLOAT,
127 TGIF_TYPE_GATHER_STRING,
128
129 /* Gather compound types */
130 TGIF_TYPE_GATHER_STRUCT,
131 TGIF_TYPE_GATHER_ARRAY,
132 TGIF_TYPE_GATHER_VLA,
133
134 /* Gather enumeration types */
135 TGIF_TYPE_GATHER_ENUM,
136
137 /* Dynamic basic types */
138 TGIF_TYPE_DYNAMIC_NULL,
139 TGIF_TYPE_DYNAMIC_BOOL,
140 TGIF_TYPE_DYNAMIC_INTEGER,
141 TGIF_TYPE_DYNAMIC_BYTE,
142 TGIF_TYPE_DYNAMIC_POINTER,
143 TGIF_TYPE_DYNAMIC_FLOAT,
144 TGIF_TYPE_DYNAMIC_STRING,
145
146 /* Dynamic compound types */
147 TGIF_TYPE_DYNAMIC_STRUCT,
148 TGIF_TYPE_DYNAMIC_STRUCT_VISITOR,
149 TGIF_TYPE_DYNAMIC_VLA,
150 TGIF_TYPE_DYNAMIC_VLA_VISITOR,
151};
152
153enum tgif_attr_type {
154 TGIF_ATTR_TYPE_NULL,
155 TGIF_ATTR_TYPE_BOOL,
156 TGIF_ATTR_TYPE_U8,
157 TGIF_ATTR_TYPE_U16,
158 TGIF_ATTR_TYPE_U32,
159 TGIF_ATTR_TYPE_U64,
160 TGIF_ATTR_TYPE_S8,
161 TGIF_ATTR_TYPE_S16,
162 TGIF_ATTR_TYPE_S32,
163 TGIF_ATTR_TYPE_S64,
164 TGIF_ATTR_TYPE_FLOAT_BINARY16,
165 TGIF_ATTR_TYPE_FLOAT_BINARY32,
166 TGIF_ATTR_TYPE_FLOAT_BINARY64,
167 TGIF_ATTR_TYPE_FLOAT_BINARY128,
168 TGIF_ATTR_TYPE_STRING,
169};
170
171enum tgif_loglevel {
172 TGIF_LOGLEVEL_EMERG = 0,
173 TGIF_LOGLEVEL_ALERT = 1,
174 TGIF_LOGLEVEL_CRIT = 2,
175 TGIF_LOGLEVEL_ERR = 3,
176 TGIF_LOGLEVEL_WARNING = 4,
177 TGIF_LOGLEVEL_NOTICE = 5,
178 TGIF_LOGLEVEL_INFO = 6,
179 TGIF_LOGLEVEL_DEBUG = 7,
180};
181
182enum tgif_visitor_status {
183 TGIF_VISITOR_STATUS_OK = 0,
184 TGIF_VISITOR_STATUS_ERROR = -1,
185};
186
187enum tgif_error {
188 TGIF_ERROR_OK = 0,
189 TGIF_ERROR_INVAL = 1,
190 TGIF_ERROR_EXIST = 2,
191 TGIF_ERROR_NOMEM = 3,
192 TGIF_ERROR_NOENT = 4,
193 TGIF_ERROR_EXITING = 5,
194};
195
196enum tgif_type_label_byte_order {
197 TGIF_TYPE_BYTE_ORDER_LE = 0,
198 TGIF_TYPE_BYTE_ORDER_BE = 1,
199};
200
201#if (TGIF_BYTE_ORDER == TGIF_LITTLE_ENDIAN)
202# define TGIF_TYPE_BYTE_ORDER_HOST TGIF_TYPE_BYTE_ORDER_LE
203#else
204# define TGIF_TYPE_BYTE_ORDER_HOST TGIF_TYPE_BYTE_ORDER_BE
205#endif
206
207#if (TGIF_FLOAT_WORD_ORDER == TGIF_LITTLE_ENDIAN)
208# define TGIF_TYPE_FLOAT_WORD_ORDER_HOST TGIF_TYPE_BYTE_ORDER_LE
209#else
210# define TGIF_TYPE_FLOAT_WORD_ORDER_HOST TGIF_TYPE_BYTE_ORDER_BE
211#endif
212
213enum tgif_type_gather_access_mode {
214 TGIF_TYPE_GATHER_ACCESS_DIRECT,
215 TGIF_TYPE_GATHER_ACCESS_POINTER, /* Pointer dereference */
216};
217
218typedef enum tgif_visitor_status (*tgif_visitor_func)(
219 const struct tgif_tracer_visitor_ctx *tracer_ctx,
220 void *app_ctx);
221typedef enum tgif_visitor_status (*tgif_dynamic_struct_visitor_func)(
222 const struct tgif_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
223 void *app_ctx);
224
225union tgif_integer_value {
226 uint8_t tgif_u8;
227 uint16_t tgif_u16;
228 uint32_t tgif_u32;
229 uint64_t tgif_u64;
230 int8_t tgif_s8;
231 int16_t tgif_s16;
232 int32_t tgif_s32;
233 int64_t tgif_s64;
234 uintptr_t tgif_uptr;
235} TGIF_PACKED;
236
237union tgif_bool_value {
238 uint8_t tgif_bool8;
239 uint16_t tgif_bool16;
240 uint32_t tgif_bool32;
241 uint64_t tgif_bool64;
242} TGIF_PACKED;
243
244union tgif_float_value {
245#if __HAVE_FLOAT16
246 _Float16 tgif_float_binary16;
247#endif
248#if __HAVE_FLOAT32
249 _Float32 tgif_float_binary32;
250#endif
251#if __HAVE_FLOAT64
252 _Float64 tgif_float_binary64;
253#endif
254#if __HAVE_FLOAT128
255 _Float128 tgif_float_binary128;
256#endif
257} TGIF_PACKED;
258
259struct tgif_type_raw_string {
260 const void *p; /* pointer to string */
261 uint8_t unit_size; /* 1, 2, or 4 bytes */
262 uint8_t byte_order; /* enum tgif_type_label_byte_order */
263} TGIF_PACKED;
264
265struct tgif_attr_value {
266 uint32_t type; /* enum tgif_attr_type */
267 union {
268 uint8_t bool_value;
269 struct tgif_type_raw_string string_value;
270 union tgif_integer_value integer_value;
271 union tgif_float_value float_value;
272 } TGIF_PACKED u;
273};
274
275/* User attributes. */
276struct tgif_attr {
277 const struct tgif_type_raw_string key;
278 const struct tgif_attr_value value;
279} TGIF_PACKED;
280
281/* Type descriptions */
282struct tgif_type_null {
283 const struct tgif_attr *attr;
284 uint32_t nr_attr;
285} TGIF_PACKED;
286
287struct tgif_type_bool {
288 const struct tgif_attr *attr;
289 uint32_t nr_attr;
290 uint16_t bool_size; /* bytes */
291 uint16_t len_bits; /* bits. 0 for (bool_size * CHAR_BITS) */
292 uint8_t byte_order; /* enum tgif_type_label_byte_order */
293} TGIF_PACKED;
294
295struct tgif_type_byte {
296 const struct tgif_attr *attr;
297 uint32_t nr_attr;
298} TGIF_PACKED;
299
300struct tgif_type_string {
301 const struct tgif_attr *attr;
302 uint32_t nr_attr;
303 uint8_t unit_size; /* 1, 2, or 4 bytes */
304 uint8_t byte_order; /* enum tgif_type_label_byte_order */
305} TGIF_PACKED;
306
307struct tgif_type_integer {
308 const struct tgif_attr *attr;
309 uint32_t nr_attr;
310 uint16_t integer_size; /* bytes */
311 uint16_t len_bits; /* bits. 0 for (integer_size * CHAR_BITS) */
312 uint8_t signedness; /* true/false */
313 uint8_t byte_order; /* enum tgif_type_label_byte_order */
314} TGIF_PACKED;
315
316struct tgif_type_float {
317 const struct tgif_attr *attr;
318 uint32_t nr_attr;
319 uint16_t float_size; /* bytes */
320 uint8_t byte_order; /* enum tgif_type_label_byte_order */
321} TGIF_PACKED;
322
323struct tgif_enum_mapping {
324 int64_t range_begin;
325 int64_t range_end;
326 struct tgif_type_raw_string label;
327} TGIF_PACKED;
328
329struct tgif_enum_mappings {
330 const struct tgif_enum_mapping *mappings;
331 const struct tgif_attr *attr;
332 uint32_t nr_mappings;
333 uint32_t nr_attr;
334} TGIF_PACKED;
335
336struct tgif_enum_bitmap_mapping {
337 uint64_t range_begin;
338 uint64_t range_end;
339 struct tgif_type_raw_string label;
340} TGIF_PACKED;
341
342struct tgif_enum_bitmap_mappings {
343 const struct tgif_enum_bitmap_mapping *mappings;
344 const struct tgif_attr *attr;
345 uint32_t nr_mappings;
346 uint32_t nr_attr;
347} TGIF_PACKED;
348
349struct tgif_type_struct {
350 const struct tgif_event_field *fields;
351 const struct tgif_attr *attr;
352 uint32_t nr_fields;
353 uint32_t nr_attr;
354} TGIF_PACKED;
355
356struct tgif_type_array {
357 const struct tgif_type *elem_type;
358 const struct tgif_attr *attr;
359 uint32_t length;
360 uint32_t nr_attr;
361} TGIF_PACKED;
362
363struct tgif_type_vla {
364 const struct tgif_type *elem_type;
365 const struct tgif_attr *attr;
366 uint32_t nr_attr;
367} TGIF_PACKED;
368
369struct tgif_type_vla_visitor {
370 const struct tgif_type *elem_type;
371 tgif_visitor_func visitor;
372 const struct tgif_attr *attr;
373 uint32_t nr_attr;
374} TGIF_PACKED;
375
376struct tgif_type_enum {
377 const struct tgif_enum_mappings *mappings;
378 const struct tgif_type *elem_type;
379} TGIF_PACKED;
380
381struct tgif_type_enum_bitmap {
382 const struct tgif_enum_bitmap_mappings *mappings;
383 const struct tgif_type *elem_type;
384} TGIF_PACKED;
385
386struct tgif_type_gather_bool {
387 uint64_t offset; /* bytes */
388 uint8_t access_mode; /* enum tgif_type_gather_access_mode */
389 struct tgif_type_bool type;
390 uint16_t offset_bits; /* bits */
391} TGIF_PACKED;
392
393struct tgif_type_gather_byte {
394 uint64_t offset; /* bytes */
395 uint8_t access_mode; /* enum tgif_type_gather_access_mode */
396 struct tgif_type_byte type;
397} TGIF_PACKED;
398
399struct tgif_type_gather_integer {
400 uint64_t offset; /* bytes */
401 uint8_t access_mode; /* enum tgif_type_gather_access_mode */
402 struct tgif_type_integer type;
403 uint16_t offset_bits; /* bits */
404} TGIF_PACKED;
405
406struct tgif_type_gather_float {
407 uint64_t offset; /* bytes */
408 uint8_t access_mode; /* enum tgif_type_gather_access_mode */
409 struct tgif_type_float type;
410} TGIF_PACKED;
411
412struct tgif_type_gather_string {
413 uint64_t offset; /* bytes */
414 uint8_t access_mode; /* enum tgif_type_gather_access_mode */
415 struct tgif_type_string type;
416} TGIF_PACKED;
417
418struct tgif_type_gather_enum {
419 const struct tgif_enum_mappings *mappings;
420 const struct tgif_type *elem_type;
421} TGIF_PACKED;
422
423struct tgif_type_gather_struct {
424 uint64_t offset; /* bytes */
425 uint8_t access_mode; /* enum tgif_type_gather_access_mode */
426 const struct tgif_type_struct *type;
427 uint32_t size; /* bytes */
428} TGIF_PACKED;
429
430struct tgif_type_gather_array {
431 uint64_t offset; /* bytes */
432 uint8_t access_mode; /* enum tgif_type_gather_access_mode */
433 struct tgif_type_array type;
434} TGIF_PACKED;
435
436struct tgif_type_gather_vla {
437 const struct tgif_type *length_type; /* tgif_length() */
438
439 uint64_t offset; /* bytes */
440 uint8_t access_mode; /* enum tgif_type_gather_access_mode */
441 struct tgif_type_vla type;
442} TGIF_PACKED;
443
444struct tgif_type_gather {
445 union {
446 struct tgif_type_gather_bool tgif_bool;
447 struct tgif_type_gather_byte tgif_byte;
448 struct tgif_type_gather_integer tgif_integer;
449 struct tgif_type_gather_float tgif_float;
450 struct tgif_type_gather_string tgif_string;
451 struct tgif_type_gather_enum tgif_enum;
452 struct tgif_type_gather_array tgif_array;
453 struct tgif_type_gather_vla tgif_vla;
454 struct tgif_type_gather_struct tgif_struct;
455 } TGIF_PACKED u;
456} TGIF_PACKED;
457
458struct tgif_type {
459 uint32_t type; /* enum tgif_type_label */
460 union {
461 /* Stack-copy basic types */
462 struct tgif_type_null tgif_null;
463 struct tgif_type_bool tgif_bool;
464 struct tgif_type_byte tgif_byte;
465 struct tgif_type_string tgif_string;
466 struct tgif_type_integer tgif_integer;
467 struct tgif_type_float tgif_float;
468
469 /* Stack-copy compound types */
470 struct tgif_type_array tgif_array;
471 struct tgif_type_vla tgif_vla;
472 struct tgif_type_vla_visitor tgif_vla_visitor;
473 const struct tgif_type_struct *tgif_struct;
474
475 /* Stack-copy enumeration types */
476 struct tgif_type_enum tgif_enum;
477 struct tgif_type_enum_bitmap tgif_enum_bitmap;
478
479 /* Gather types */
480 struct tgif_type_gather tgif_gather;
481 } TGIF_PACKED u;
482} TGIF_PACKED;
483
484struct tgif_event_field {
485 const char *field_name;
486 struct tgif_type tgif_type;
487} TGIF_PACKED;
488
489enum tgif_event_flags {
490 TGIF_EVENT_FLAG_VARIADIC = (1 << 0),
491};
492
493struct tgif_callback {
494 union {
495 void (*call)(const struct tgif_event_description *desc,
496 const struct tgif_arg_vec *tgif_arg_vec,
497 void *priv);
498 void (*call_variadic)(const struct tgif_event_description *desc,
499 const struct tgif_arg_vec *tgif_arg_vec,
500 const struct tgif_arg_dynamic_struct *var_struct,
501 void *priv);
502 } TGIF_PACKED u;
503 void *priv;
504} TGIF_PACKED;
505
506struct tgif_arg_static {
507 /* Stack-copy basic types */
508 union tgif_bool_value bool_value;
509 uint8_t byte_value;
510 uint64_t string_value; /* const {uint8_t, uint16_t, uint32_t} * */
511 union tgif_integer_value integer_value;
512 union tgif_float_value float_value;
513
514 /* Stack-copy compound types */
515 const struct tgif_arg_vec *tgif_struct;
516 const struct tgif_arg_vec *tgif_array;
517 const struct tgif_arg_vec *tgif_vla;
518 void *tgif_vla_app_visitor_ctx;
519
520 /* Gather basic types */
521 const void *tgif_bool_gather_ptr;
522 const void *tgif_byte_gather_ptr;
523 const void *tgif_integer_gather_ptr;
524 const void *tgif_float_gather_ptr;
525 const void *tgif_string_gather_ptr;
526
527 /* Gather compound types */
528 const void *tgif_array_gather_ptr;
529 const void *tgif_struct_gather_ptr;
530 struct {
531 const void *ptr;
532 const void *length_ptr;
533 } TGIF_PACKED tgif_vla_gather;
534} TGIF_PACKED;
535
536struct tgif_arg_dynamic_vla {
537 const struct tgif_arg *sav;
538 const struct tgif_attr *attr;
539 uint32_t len;
540 uint32_t nr_attr;
541} TGIF_PACKED;
542
543struct tgif_arg_dynamic_struct {
544 const struct tgif_arg_dynamic_field *fields;
545 const struct tgif_attr *attr;
546 uint32_t len;
547 uint32_t nr_attr;
548} TGIF_PACKED;
549
550struct tgif_dynamic_struct_visitor {
551 void *app_ctx;
552 tgif_dynamic_struct_visitor_func visitor;
553 const struct tgif_attr *attr;
554 uint32_t nr_attr;
555} TGIF_PACKED;
556
557struct tgif_dynamic_vla_visitor {
558 void *app_ctx;
559 tgif_visitor_func visitor;
560 const struct tgif_attr *attr;
561 uint32_t nr_attr;
562} TGIF_PACKED;
563
564struct tgif_arg_dynamic {
565 /* Dynamic basic types */
566 struct tgif_type_null tgif_null;
567 struct {
568 struct tgif_type_bool type;
569 union tgif_bool_value value;
570 } TGIF_PACKED tgif_bool;
571 struct {
572 struct tgif_type_byte type;
573 uint8_t value;
574 } TGIF_PACKED tgif_byte;
575 struct {
576 struct tgif_type_string type;
577 uint64_t value; /* const char * */
578 } TGIF_PACKED tgif_string;
579 struct {
580 struct tgif_type_integer type;
581 union tgif_integer_value value;
582 } TGIF_PACKED tgif_integer;
583 struct {
584 struct tgif_type_float type;
585 union tgif_float_value value;
586 } TGIF_PACKED tgif_float;
587
588 /* Dynamic compound types */
589 const struct tgif_arg_dynamic_struct *tgif_dynamic_struct;
590 const struct tgif_arg_dynamic_vla *tgif_dynamic_vla;
591
592 struct tgif_dynamic_struct_visitor tgif_dynamic_struct_visitor;
593 struct tgif_dynamic_vla_visitor tgif_dynamic_vla_visitor;
594} TGIF_PACKED;
595
596struct tgif_arg {
597 uint32_t type; /* enum tgif_type_label */
598 union {
599 struct tgif_arg_static tgif_static;
600 struct tgif_arg_dynamic tgif_dynamic;
601 } TGIF_PACKED u;
602} TGIF_PACKED;
603
604struct tgif_arg_vec {
605 const struct tgif_arg *sav;
606 uint32_t len;
607} TGIF_PACKED;
608
609struct tgif_arg_dynamic_field {
610 const char *field_name;
611 const struct tgif_arg elem;
612} TGIF_PACKED;
613
614/* The visitor pattern is a double-dispatch visitor. */
615struct tgif_tracer_visitor_ctx {
616 enum tgif_visitor_status (*write_elem)(
617 const struct tgif_tracer_visitor_ctx *tracer_ctx,
618 const struct tgif_arg *elem);
619 void *priv; /* Private tracer context. */
620} TGIF_PACKED;
621
622struct tgif_tracer_dynamic_struct_visitor_ctx {
623 enum tgif_visitor_status (*write_field)(
624 const struct tgif_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
625 const struct tgif_arg_dynamic_field *dynamic_field);
626 void *priv; /* Private tracer context. */
627} TGIF_PACKED;
628
629struct tgif_event_description {
630 uintptr_t *enabled;
631 const char *provider_name;
632 const char *event_name;
633 const struct tgif_event_field *fields;
634 const struct tgif_attr *attr;
635 const struct tgif_callback *callbacks;
636 uint64_t flags;
637 uint32_t version;
638 uint32_t loglevel; /* enum tgif_loglevel */
639 uint32_t nr_fields;
640 uint32_t nr_attr;
641 uint32_t nr_callbacks;
642} TGIF_PACKED;
643
644/* Event and type attributes */
645
646#define tgif_attr(_key, _value) \
647 { \
648 .key = { \
649 .p = (_key), \
650 .unit_size = sizeof(uint8_t), \
651 .byte_order = TGIF_TYPE_BYTE_ORDER_HOST, \
652 }, \
653 .value = TGIF_PARAM(_value), \
654 }
655
656#define tgif_attr_list(...) \
657 TGIF_COMPOUND_LITERAL(const struct tgif_attr, __VA_ARGS__)
658
659#define tgif_attr_null(_val) { .type = TGIF_ATTR_TYPE_NULL }
660#define tgif_attr_bool(_val) { .type = TGIF_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
661#define tgif_attr_u8(_val) { .type = TGIF_ATTR_TYPE_U8, .u = { .integer_value = { .tgif_u8 = (_val) } } }
662#define tgif_attr_u16(_val) { .type = TGIF_ATTR_TYPE_U16, .u = { .integer_value = { .tgif_u16 = (_val) } } }
663#define tgif_attr_u32(_val) { .type = TGIF_ATTR_TYPE_U32, .u = { .integer_value = { .tgif_u32 = (_val) } } }
664#define tgif_attr_u64(_val) { .type = TGIF_ATTR_TYPE_U64, .u = { .integer_value = { .tgif_u64 = (_val) } } }
665#define tgif_attr_s8(_val) { .type = TGIF_ATTR_TYPE_S8, .u = { .integer_value = { .tgif_s8 = (_val) } } }
666#define tgif_attr_s16(_val) { .type = TGIF_ATTR_TYPE_S16, .u = { .integer_value = { .tgif_s16 = (_val) } } }
667#define tgif_attr_s32(_val) { .type = TGIF_ATTR_TYPE_S32, .u = { .integer_value = { .tgif_s32 = (_val) } } }
668#define tgif_attr_s64(_val) { .type = TGIF_ATTR_TYPE_S64, .u = { .integer_value = { .tgif_s64 = (_val) } } }
669#define tgif_attr_float_binary16(_val) { .type = TGIF_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .tgif_float_binary16 = (_val) } } }
670#define tgif_attr_float_binary32(_val) { .type = TGIF_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .tgif_float_binary32 = (_val) } } }
671#define tgif_attr_float_binary64(_val) { .type = TGIF_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .tgif_float_binary64 = (_val) } } }
672#define tgif_attr_float_binary128(_val) { .type = TGIF_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .tgif_float_binary128 = (_val) } } }
673
674#define _tgif_attr_string(_val, _byte_order, _unit_size) \
675 { \
676 .type = TGIF_ATTR_TYPE_STRING, \
677 .u = { \
678 .string_value = { \
679 .p = (const void *) (_val), \
680 .unit_size = _unit_size, \
681 .byte_order = _byte_order, \
682 }, \
683 }, \
684 }
685
686#define tgif_attr_string(_val) _tgif_attr_string(_val, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t))
687#define tgif_attr_string16(_val) _tgif_attr_string(_val, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t))
688#define tgif_attr_string32(_val) _tgif_attr_string(_val, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t))
689
690/* Stack-copy enumeration type definitions */
691
692#define tgif_define_enum(_identifier, _mappings, _attr) \
693 const struct tgif_enum_mappings _identifier = { \
694 .mappings = _mappings, \
695 .attr = _attr, \
696 .nr_mappings = TGIF_ARRAY_SIZE(TGIF_PARAM(_mappings)), \
697 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
698 }
699
700#define tgif_enum_mapping_list(...) \
701 TGIF_COMPOUND_LITERAL(const struct tgif_enum_mapping, __VA_ARGS__)
702
703#define tgif_enum_mapping_range(_label, _begin, _end) \
704 { \
705 .range_begin = _begin, \
706 .range_end = _end, \
707 .label = { \
708 .p = (_label), \
709 .unit_size = sizeof(uint8_t), \
710 .byte_order = TGIF_TYPE_BYTE_ORDER_HOST, \
711 }, \
712 }
713
714#define tgif_enum_mapping_value(_label, _value) \
715 { \
716 .range_begin = _value, \
717 .range_end = _value, \
718 .label = { \
719 .p = (_label), \
720 .unit_size = sizeof(uint8_t), \
721 .byte_order = TGIF_TYPE_BYTE_ORDER_HOST, \
722 }, \
723 }
724
725#define tgif_define_enum_bitmap(_identifier, _mappings, _attr) \
726 const struct tgif_enum_bitmap_mappings _identifier = { \
727 .mappings = _mappings, \
728 .attr = _attr, \
729 .nr_mappings = TGIF_ARRAY_SIZE(TGIF_PARAM(_mappings)), \
730 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
731 }
732
733#define tgif_enum_bitmap_mapping_list(...) \
734 TGIF_COMPOUND_LITERAL(const struct tgif_enum_bitmap_mapping, __VA_ARGS__)
735
736#define tgif_enum_bitmap_mapping_range(_label, _begin, _end) \
737 { \
738 .range_begin = _begin, \
739 .range_end = _end, \
740 .label = { \
741 .p = (_label), \
742 .unit_size = sizeof(uint8_t), \
743 .byte_order = TGIF_TYPE_BYTE_ORDER_HOST, \
744 }, \
745 }
746
747#define tgif_enum_bitmap_mapping_value(_label, _value) \
748 { \
749 .range_begin = _value, \
750 .range_end = _value, \
751 .label = { \
752 .p = (_label), \
753 .unit_size = sizeof(uint8_t), \
754 .byte_order = TGIF_TYPE_BYTE_ORDER_HOST, \
755 }, \
756 }
757
758/* Stack-copy field and type definitions */
759
760#define tgif_type_null(_attr) \
761 { \
762 .type = TGIF_TYPE_NULL, \
763 .u = { \
764 .tgif_null = { \
765 .attr = _attr, \
766 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
767 }, \
768 }, \
769 }
770
771#define tgif_type_bool(_attr) \
772 { \
773 .type = TGIF_TYPE_BOOL, \
774 .u = { \
775 .tgif_bool = { \
776 .attr = _attr, \
777 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
778 .bool_size = sizeof(uint8_t), \
779 .len_bits = 0, \
780 .byte_order = TGIF_TYPE_BYTE_ORDER_HOST, \
781 }, \
782 }, \
783 }
784
785#define tgif_type_byte(_attr) \
786 { \
787 .type = TGIF_TYPE_BYTE, \
788 .u = { \
789 .tgif_byte = { \
790 .attr = _attr, \
791 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
792 }, \
793 }, \
794 }
795
796#define _tgif_type_string(_type, _byte_order, _unit_size, _attr) \
797 { \
798 .type = _type, \
799 .u = { \
800 .tgif_string = { \
801 .attr = _attr, \
802 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
803 .unit_size = _unit_size, \
804 .byte_order = _byte_order, \
805 }, \
806 }, \
807 }
808
809#define tgif_type_dynamic() \
810 { \
811 .type = TGIF_TYPE_DYNAMIC, \
812 }
813
814#define _tgif_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
815 { \
816 .type = _type, \
817 .u = { \
818 .tgif_integer = { \
819 .attr = _attr, \
820 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
821 .integer_size = _integer_size, \
822 .len_bits = _len_bits, \
823 .signedness = _signedness, \
824 .byte_order = _byte_order, \
825 }, \
826 }, \
827 }
828
829#define _tgif_type_float(_type, _byte_order, _float_size, _attr) \
830 { \
831 .type = _type, \
832 .u = { \
833 .tgif_float = { \
834 .attr = _attr, \
835 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
836 .float_size = _float_size, \
837 .byte_order = _byte_order, \
838 }, \
839 }, \
840 }
841
842#define _tgif_field(_name, _type) \
843 { \
844 .field_name = _name, \
845 .tgif_type = _type, \
846 }
847
848/* Host endian */
849#define tgif_type_u8(_attr) _tgif_type_integer(TGIF_TYPE_U8, false, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, TGIF_PARAM(_attr))
850#define tgif_type_u16(_attr) _tgif_type_integer(TGIF_TYPE_U16, false, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, TGIF_PARAM(_attr))
851#define tgif_type_u32(_attr) _tgif_type_integer(TGIF_TYPE_U32, false, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), 0, TGIF_PARAM(_attr))
852#define tgif_type_u64(_attr) _tgif_type_integer(TGIF_TYPE_U64, false, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint64_t), 0, TGIF_PARAM(_attr))
853#define tgif_type_s8(_attr) _tgif_type_integer(TGIF_TYPE_S8, true, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, TGIF_PARAM(_attr))
854#define tgif_type_s16(_attr) _tgif_type_integer(TGIF_TYPE_S16, true, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(int16_t), 0, TGIF_PARAM(_attr))
855#define tgif_type_s32(_attr) _tgif_type_integer(TGIF_TYPE_S32, true, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(int32_t), 0, TGIF_PARAM(_attr))
856#define tgif_type_s64(_attr) _tgif_type_integer(TGIF_TYPE_S64, true, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(int64_t), 0, TGIF_PARAM(_attr))
857#define tgif_type_pointer(_attr) _tgif_type_integer(TGIF_TYPE_POINTER, false, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uintptr_t), 0, TGIF_PARAM(_attr))
858#define tgif_type_float_binary16(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY16, TGIF_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float16), TGIF_PARAM(_attr))
859#define tgif_type_float_binary32(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY32, TGIF_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), TGIF_PARAM(_attr))
860#define tgif_type_float_binary64(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY64, TGIF_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), TGIF_PARAM(_attr))
861#define tgif_type_float_binary128(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY128, TGIF_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), TGIF_PARAM(_attr))
862#define tgif_type_string(_attr) _tgif_type_string(TGIF_TYPE_STRING_UTF8, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), TGIF_PARAM(_attr))
863#define tgif_type_string16(_attr) _tgif_type_string(TGIF_TYPE_STRING_UTF16, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), TGIF_PARAM(_attr))
864#define tgif_type_string32(_attr) _tgif_type_string(TGIF_TYPE_STRING_UTF32, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), TGIF_PARAM(_attr))
865
866#define tgif_field_null(_name, _attr) _tgif_field(_name, tgif_type_null(TGIF_PARAM(_attr)))
867#define tgif_field_bool(_name, _attr) _tgif_field(_name, tgif_type_bool(TGIF_PARAM(_attr)))
868#define tgif_field_u8(_name, _attr) _tgif_field(_name, tgif_type_u8(TGIF_PARAM(_attr)))
869#define tgif_field_u16(_name, _attr) _tgif_field(_name, tgif_type_u16(TGIF_PARAM(_attr)))
870#define tgif_field_u32(_name, _attr) _tgif_field(_name, tgif_type_u32(TGIF_PARAM(_attr)))
871#define tgif_field_u64(_name, _attr) _tgif_field(_name, tgif_type_u64(TGIF_PARAM(_attr)))
872#define tgif_field_s8(_name, _attr) _tgif_field(_name, tgif_type_s8(TGIF_PARAM(_attr)))
873#define tgif_field_s16(_name, _attr) _tgif_field(_name, tgif_type_s16(TGIF_PARAM(_attr)))
874#define tgif_field_s32(_name, _attr) _tgif_field(_name, tgif_type_s32(TGIF_PARAM(_attr)))
875#define tgif_field_s64(_name, _attr) _tgif_field(_name, tgif_type_s64(TGIF_PARAM(_attr)))
876#define tgif_field_byte(_name, _attr) _tgif_field(_name, tgif_type_byte(TGIF_PARAM(_attr)))
877#define tgif_field_pointer(_name, _attr) _tgif_field(_name, tgif_type_pointer(TGIF_PARAM(_attr)))
878#define tgif_field_float_binary16(_name, _attr) _tgif_field(_name, tgif_type_float_binary16(TGIF_PARAM(_attr)))
879#define tgif_field_float_binary32(_name, _attr) _tgif_field(_name, tgif_type_float_binary32(TGIF_PARAM(_attr)))
880#define tgif_field_float_binary64(_name, _attr) _tgif_field(_name, tgif_type_float_binary64(TGIF_PARAM(_attr)))
881#define tgif_field_float_binary128(_name, _attr) _tgif_field(_name, tgif_type_float_binary128(TGIF_PARAM(_attr)))
882#define tgif_field_string(_name, _attr) _tgif_field(_name, tgif_type_string(TGIF_PARAM(_attr)))
883#define tgif_field_string16(_name, _attr) _tgif_field(_name, tgif_type_string16(TGIF_PARAM(_attr)))
884#define tgif_field_string32(_name, _attr) _tgif_field(_name, tgif_type_string32(TGIF_PARAM(_attr)))
885#define tgif_field_dynamic(_name) _tgif_field(_name, tgif_type_dynamic())
886
887/* Little endian */
888#define tgif_type_u16_le(_attr) _tgif_type_integer(TGIF_TYPE_U16, false, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), 0, TGIF_PARAM(_attr))
889#define tgif_type_u32_le(_attr) _tgif_type_integer(TGIF_TYPE_U32, false, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), 0, TGIF_PARAM(_attr))
890#define tgif_type_u64_le(_attr) _tgif_type_integer(TGIF_TYPE_U64, false, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint64_t), 0, TGIF_PARAM(_attr))
891#define tgif_type_s16_le(_attr) _tgif_type_integer(TGIF_TYPE_S16, true, TGIF_TYPE_BYTE_ORDER_LE, sizeof(int16_t), 0, TGIF_PARAM(_attr))
892#define tgif_type_s32_le(_attr) _tgif_type_integer(TGIF_TYPE_S32, true, TGIF_TYPE_BYTE_ORDER_LE, sizeof(int32_t), 0, TGIF_PARAM(_attr))
893#define tgif_type_s64_le(_attr) _tgif_type_integer(TGIF_TYPE_S64, true, TGIF_TYPE_BYTE_ORDER_LE, sizeof(int64_t), 0, TGIF_PARAM(_attr))
894#define tgif_type_pointer_le(_attr) _tgif_type_integer(TGIF_TYPE_POINTER, false, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uintptr_t), 0, TGIF_PARAM(_attr))
895#define tgif_type_float_binary16_le(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY16, TGIF_TYPE_BYTE_ORDER_LE, sizeof(_Float16), TGIF_PARAM(_attr))
896#define tgif_type_float_binary32_le(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY32, TGIF_TYPE_BYTE_ORDER_LE, sizeof(_Float32), TGIF_PARAM(_attr))
897#define tgif_type_float_binary64_le(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY64, TGIF_TYPE_BYTE_ORDER_LE, sizeof(_Float64), TGIF_PARAM(_attr))
898#define tgif_type_float_binary128_le(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY128, TGIF_TYPE_BYTE_ORDER_LE, sizeof(_Float128), TGIF_PARAM(_attr))
899#define tgif_type_string16_le(_attr) _tgif_type_string(TGIF_TYPE_STRING_UTF16, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), TGIF_PARAM(_attr))
900#define tgif_type_string32_le(_attr) _tgif_type_string(TGIF_TYPE_STRING_UTF32, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), TGIF_PARAM(_attr))
901
902#define tgif_field_u16_le(_name, _attr) _tgif_field(_name, tgif_type_u16_le(TGIF_PARAM(_attr)))
903#define tgif_field_u32_le(_name, _attr) _tgif_field(_name, tgif_type_u32_le(TGIF_PARAM(_attr)))
904#define tgif_field_u64_le(_name, _attr) _tgif_field(_name, tgif_type_u64_le(TGIF_PARAM(_attr)))
905#define tgif_field_s16_le(_name, _attr) _tgif_field(_name, tgif_type_s16_le(TGIF_PARAM(_attr)))
906#define tgif_field_s32_le(_name, _attr) _tgif_field(_name, tgif_type_s32_le(TGIF_PARAM(_attr)))
907#define tgif_field_s64_le(_name, _attr) _tgif_field(_name, tgif_type_s64_le(TGIF_PARAM(_attr)))
908#define tgif_field_pointer_le(_name, _attr) _tgif_field(_name, tgif_type_pointer_le(TGIF_PARAM(_attr)))
909#define tgif_field_float_binary16_le(_name, _attr) _tgif_field(_name, tgif_type_float_binary16_le(TGIF_PARAM(_attr)))
910#define tgif_field_float_binary32_le(_name, _attr) _tgif_field(_name, tgif_type_float_binary32_le(TGIF_PARAM(_attr)))
911#define tgif_field_float_binary64_le(_name, _attr) _tgif_field(_name, tgif_type_float_binary64_le(TGIF_PARAM(_attr)))
912#define tgif_field_float_binary128_le(_name, _attr) _tgif_field(_name, tgif_type_float_binary128_le(TGIF_PARAM(_attr)))
913#define tgif_field_string16_le(_name, _attr) _tgif_field(_name, tgif_type_string16_le(TGIF_PARAM(_attr)))
914#define tgif_field_string32_le(_name, _attr) _tgif_field(_name, tgif_type_string32_le(TGIF_PARAM(_attr)))
915
916/* Big endian */
917#define tgif_type_u16_be(_attr) _tgif_type_integer(TGIF_TYPE_U16, false, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, TGIF_PARAM(_attr))
918#define tgif_type_u32_be(_attr) _tgif_type_integer(TGIF_TYPE_U32, false, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), 0, TGIF_PARAM(_attr))
919#define tgif_type_u64_be(_attr) _tgif_type_integer(TGIF_TYPE_U64, false, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint64_t), 0, TGIF_PARAM(_attr))
920#define tgif_type_s16_be(_attr) _tgif_type_integer(TGIF_TYPE_S16, false, TGIF_TYPE_BYTE_ORDER_BE, sizeof(int16_t), 0, TGIF_PARAM(_attr))
921#define tgif_type_s32_be(_attr) _tgif_type_integer(TGIF_TYPE_S32, false, TGIF_TYPE_BYTE_ORDER_BE, sizeof(int32_t), 0, TGIF_PARAM(_attr))
922#define tgif_type_s64_be(_attr) _tgif_type_integer(TGIF_TYPE_S64, false, TGIF_TYPE_BYTE_ORDER_BE, sizeof(int64_t), 0, TGIF_PARAM(_attr))
923#define tgif_type_pointer_be(_attr) _tgif_type_integer(TGIF_TYPE_POINTER, false, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uintptr_t), 0, TGIF_PARAM(_attr))
924#define tgif_type_float_binary16_be(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY16, TGIF_TYPE_BYTE_ORDER_BE, sizeof(_Float16), TGIF_PARAM(_attr))
925#define tgif_type_float_binary32_be(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY32, TGIF_TYPE_BYTE_ORDER_BE, sizeof(_Float32), TGIF_PARAM(_attr))
926#define tgif_type_float_binary64_be(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY64, TGIF_TYPE_BYTE_ORDER_BE, sizeof(_Float64), TGIF_PARAM(_attr))
927#define tgif_type_float_binary128_be(_attr) _tgif_type_float(TGIF_TYPE_FLOAT_BINARY128, TGIF_TYPE_BYTE_ORDER_BE, sizeof(_Float128), TGIF_PARAM(_attr))
928#define tgif_type_string16_be(_attr) _tgif_type_string(TGIF_TYPE_STRING_UTF16, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), TGIF_PARAM(_attr))
929#define tgif_type_string32_be(_attr) _tgif_type_string(TGIF_TYPE_STRING_UTF32, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), TGIF_PARAM(_attr))
930
931#define tgif_field_u16_be(_name, _attr) _tgif_field(_name, tgif_type_u16_be(TGIF_PARAM(_attr)))
932#define tgif_field_u32_be(_name, _attr) _tgif_field(_name, tgif_type_u32_be(TGIF_PARAM(_attr)))
933#define tgif_field_u64_be(_name, _attr) _tgif_field(_name, tgif_type_u64_be(TGIF_PARAM(_attr)))
934#define tgif_field_s16_be(_name, _attr) _tgif_field(_name, tgif_type_s16_be(TGIF_PARAM(_attr)))
935#define tgif_field_s32_be(_name, _attr) _tgif_field(_name, tgif_type_s32_be(TGIF_PARAM(_attr)))
936#define tgif_field_s64_be(_name, _attr) _tgif_field(_name, tgif_type_s64_be(TGIF_PARAM(_attr)))
937#define tgif_field_pointer_be(_name, _attr) _tgif_field(_name, tgif_type_pointer_be(TGIF_PARAM(_attr)))
938#define tgif_field_float_binary16_be(_name, _attr) _tgif_field(_name, tgif_type_float_binary16_be(TGIF_PARAM(_attr)))
939#define tgif_field_float_binary32_be(_name, _attr) _tgif_field(_name, tgif_type_float_binary32_be(TGIF_PARAM(_attr)))
940#define tgif_field_float_binary64_be(_name, _attr) _tgif_field(_name, tgif_type_float_binary64_be(TGIF_PARAM(_attr)))
941#define tgif_field_float_binary128_be(_name, _attr) _tgif_field(_name, tgif_type_float_binary128_be(TGIF_PARAM(_attr)))
942#define tgif_field_string16_be(_name, _attr) _tgif_field(_name, tgif_type_string16_be(TGIF_PARAM(_attr)))
943#define tgif_field_string32_be(_name, _attr) _tgif_field(_name, tgif_type_string32_be(TGIF_PARAM(_attr)))
944
945#define tgif_type_enum(_mappings, _elem_type) \
946 { \
947 .type = TGIF_TYPE_ENUM, \
948 .u = { \
949 .tgif_enum = { \
950 .mappings = _mappings, \
951 .elem_type = _elem_type, \
952 }, \
953 }, \
954 }
955#define tgif_field_enum(_name, _mappings, _elem_type) \
956 _tgif_field(_name, tgif_type_enum(TGIF_PARAM(_mappings), TGIF_PARAM(_elem_type)))
957
958#define tgif_type_enum_bitmap(_mappings, _elem_type) \
959 { \
960 .type = TGIF_TYPE_ENUM_BITMAP, \
961 .u = { \
962 .tgif_enum_bitmap = { \
963 .mappings = _mappings, \
964 .elem_type = _elem_type, \
965 }, \
966 }, \
967 }
968#define tgif_field_enum_bitmap(_name, _mappings, _elem_type) \
969 _tgif_field(_name, tgif_type_enum_bitmap(TGIF_PARAM(_mappings), TGIF_PARAM(_elem_type)))
970
971#define tgif_type_struct(_struct) \
972 { \
973 .type = TGIF_TYPE_STRUCT, \
974 .u = { \
975 .tgif_struct = _struct, \
976 }, \
977 }
978#define tgif_field_struct(_name, _struct) \
979 _tgif_field(_name, tgif_type_struct(TGIF_PARAM(_struct)))
980
981#define _tgif_type_struct_define(_fields, _attr) \
982 { \
983 .fields = _fields, \
984 .attr = _attr, \
985 .nr_fields = TGIF_ARRAY_SIZE(TGIF_PARAM(_fields)), \
986 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
987 }
988
989#define tgif_define_struct(_identifier, _fields, _attr) \
990 const struct tgif_type_struct _identifier = _tgif_type_struct_define(TGIF_PARAM(_fields), TGIF_PARAM(_attr))
991
992#define tgif_struct_literal(_fields, _attr) \
993 TGIF_COMPOUND_LITERAL(const struct tgif_type_struct, \
994 _tgif_type_struct_define(TGIF_PARAM(_fields), TGIF_PARAM(_attr)))
995
996#define tgif_type_array(_elem_type, _length, _attr) \
997 { \
998 .type = TGIF_TYPE_ARRAY, \
999 .u = { \
1000 .tgif_array = { \
1001 .elem_type = _elem_type, \
1002 .attr = _attr, \
1003 .length = _length, \
1004 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1005 }, \
1006 }, \
1007 }
1008#define tgif_field_array(_name, _elem_type, _length, _attr) \
1009 _tgif_field(_name, tgif_type_array(TGIF_PARAM(_elem_type), _length, TGIF_PARAM(_attr)))
1010
1011#define tgif_type_vla(_elem_type, _attr) \
1012 { \
1013 .type = TGIF_TYPE_VLA, \
1014 .u = { \
1015 .tgif_vla = { \
1016 .elem_type = _elem_type, \
1017 .attr = _attr, \
1018 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1019 }, \
1020 }, \
1021 }
1022#define tgif_field_vla(_name, _elem_type, _attr) \
1023 _tgif_field(_name, tgif_type_vla(TGIF_PARAM(_elem_type), TGIF_PARAM(_attr)))
1024
1025#define tgif_type_vla_visitor(_elem_type, _visitor, _attr) \
1026 { \
1027 .type = TGIF_TYPE_VLA_VISITOR, \
1028 .u = { \
1029 .tgif_vla_visitor = { \
1030 .elem_type = TGIF_PARAM(_elem_type), \
1031 .visitor = _visitor, \
1032 .attr = _attr, \
1033 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1034 }, \
1035 }, \
1036 }
1037#define tgif_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
1038 _tgif_field(_name, tgif_type_vla_visitor(TGIF_PARAM(_elem_type), _visitor, TGIF_PARAM(_attr)))
1039
1040/* Gather field and type definitions */
1041
1042#define tgif_type_gather_byte(_offset, _access_mode, _attr) \
1043 { \
1044 .type = TGIF_TYPE_GATHER_BYTE, \
1045 .u = { \
1046 .tgif_gather = { \
1047 .u = { \
1048 .tgif_byte = { \
1049 .offset = _offset, \
1050 .access_mode = _access_mode, \
1051 .type = { \
1052 .attr = _attr, \
1053 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1054 }, \
1055 }, \
1056 }, \
1057 }, \
1058 }, \
1059 }
1060#define tgif_field_gather_byte(_name, _offset, _access_mode, _attr) \
1061 _tgif_field(_name, tgif_type_gather_byte(_offset, _access_mode, TGIF_PARAM(_attr)))
1062
1063#define _tgif_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1064 { \
1065 .type = TGIF_TYPE_GATHER_BOOL, \
1066 .u = { \
1067 .tgif_gather = { \
1068 .u = { \
1069 .tgif_bool = { \
1070 .offset = _offset, \
1071 .access_mode = _access_mode, \
1072 .type = { \
1073 .attr = _attr, \
1074 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1075 .bool_size = _bool_size, \
1076 .len_bits = _len_bits, \
1077 .byte_order = _byte_order, \
1078 }, \
1079 .offset_bits = _offset_bits, \
1080 }, \
1081 }, \
1082 }, \
1083 }, \
1084 }
1085#define tgif_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1086 _tgif_type_gather_bool(TGIF_TYPE_BYTE_ORDER_HOST, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1087#define tgif_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1088 _tgif_type_gather_bool(TGIF_TYPE_BYTE_ORDER_LE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1089#define tgif_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1090 _tgif_type_gather_bool(TGIF_TYPE_BYTE_ORDER_BE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr)
1091
1092#define tgif_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1093 _tgif_field(_name, tgif_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1094#define tgif_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1095 _tgif_field(_name, tgif_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1096#define tgif_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr) \
1097 _tgif_field(_name, tgif_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1098
1099#define _tgif_type_gather_integer(_type, _signedness, _byte_order, _offset, \
1100 _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1101 { \
1102 .type = _type, \
1103 .u = { \
1104 .tgif_gather = { \
1105 .u = { \
1106 .tgif_integer = { \
1107 .offset = _offset, \
1108 .access_mode = _access_mode, \
1109 .type = { \
1110 .attr = _attr, \
1111 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1112 .integer_size = _integer_size, \
1113 .len_bits = _len_bits, \
1114 .signedness = _signedness, \
1115 .byte_order = _byte_order, \
1116 }, \
1117 .offset_bits = _offset_bits, \
1118 }, \
1119 }, \
1120 }, \
1121 }, \
1122 }
1123
1124#define tgif_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1125 _tgif_type_gather_integer(TGIF_TYPE_GATHER_INTEGER, false, TGIF_TYPE_BYTE_ORDER_HOST, \
1126 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr))
1127#define tgif_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1128 _tgif_type_gather_integer(TGIF_TYPE_GATHER_INTEGER, true, TGIF_TYPE_BYTE_ORDER_HOST, \
1129 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr))
1130
1131#define tgif_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1132 _tgif_type_gather_integer(TGIF_TYPE_GATHER_INTEGER, false, TGIF_TYPE_BYTE_ORDER_LE, \
1133 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr))
1134#define tgif_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1135 _tgif_type_gather_integer(TGIF_TYPE_GATHER_INTEGER, true, TGIF_TYPE_BYTE_ORDER_LE, \
1136 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr))
1137
1138#define tgif_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1139 _tgif_type_gather_integer(TGIF_TYPE_GATHER_INTEGER, false, TGIF_TYPE_BYTE_ORDER_BE, \
1140 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr))
1141#define tgif_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1142 _tgif_type_gather_integer(TGIF_TYPE_GATHER_INTEGER, true, TGIF_TYPE_BYTE_ORDER_BE, \
1143 _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr))
1144
1145#define tgif_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1146 _tgif_field(_name, tgif_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1147#define tgif_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1148 _tgif_field(_name, tgif_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1149
1150#define tgif_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1151 _tgif_field(_name, tgif_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1152#define tgif_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1153 _tgif_field(_name, tgif_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1154
1155#define tgif_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1156 _tgif_field(_name, tgif_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1157#define tgif_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr) \
1158 _tgif_field(_name, tgif_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, TGIF_PARAM(_attr)))
1159
1160#define tgif_type_gather_pointer(_offset, _access_mode, _attr) \
1161 _tgif_type_gather_integer(TGIF_TYPE_GATHER_POINTER, false, TGIF_TYPE_BYTE_ORDER_HOST, \
1162 _offset, sizeof(uintptr_t), 0, 0, _access_mode, TGIF_PARAM(_attr))
1163#define tgif_field_gather_pointer(_name, _offset, _access_mode, _attr) \
1164 _tgif_field(_name, tgif_type_gather_pointer(_offset, _access_mode, TGIF_PARAM(_attr)))
1165
1166#define tgif_type_gather_pointer_le(_offset, _access_mode, _attr) \
1167 _tgif_type_gather_integer(TGIF_TYPE_GATHER_POINTER, false, TGIF_TYPE_BYTE_ORDER_LE, \
1168 _offset, sizeof(uintptr_t), 0, 0, _access_mode, TGIF_PARAM(_attr))
1169#define tgif_field_gather_pointer_le(_name, _offset, _access_mode, _attr) \
1170 _tgif_field(_name, tgif_type_gather_pointer_le(_offset, _access_mode, TGIF_PARAM(_attr)))
1171
1172#define tgif_type_gather_pointer_be(_offset, _access_mode, _attr) \
1173 _tgif_type_gather_integer(TGIF_TYPE_GATHER_POINTER, false, TGIF_TYPE_BYTE_ORDER_BE, \
1174 _offset, sizeof(uintptr_t), 0, 0, _access_mode, TGIF_PARAM(_attr))
1175#define tgif_field_gather_pointer_be(_name, _offset, _access_mode, _attr) \
1176 _tgif_field(_name, tgif_type_gather_pointer_be(_offset, _access_mode, TGIF_PARAM(_attr)))
1177
1178#define _tgif_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr) \
1179 { \
1180 .type = TGIF_TYPE_GATHER_FLOAT, \
1181 .u = { \
1182 .tgif_gather = { \
1183 .u = { \
1184 .tgif_float = { \
1185 .offset = _offset, \
1186 .access_mode = _access_mode, \
1187 .type = { \
1188 .attr = _attr, \
1189 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1190 .float_size = _float_size, \
1191 .byte_order = _byte_order, \
1192 }, \
1193 }, \
1194 }, \
1195 }, \
1196 }, \
1197 }
1198
1199#define tgif_type_gather_float(_offset, _float_size, _access_mode, _attr) \
1200 _tgif_type_gather_float(TGIF_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, _attr)
1201#define tgif_type_gather_float_le(_offset, _float_size, _access_mode, _attr) \
1202 _tgif_type_gather_float(TGIF_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, _attr)
1203#define tgif_type_gather_float_be(_offset, _float_size, _access_mode, _attr) \
1204 _tgif_type_gather_float(TGIF_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, _attr)
1205
1206#define tgif_field_gather_float(_name, _offset, _float_size, _access_mode, _attr) \
1207 _tgif_field(_name, tgif_type_gather_float(_offset, _float_size, _access_mode, _attr))
1208#define tgif_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr) \
1209 _tgif_field(_name, tgif_type_gather_float_le(_offset, _float_size, _access_mode, _attr))
1210#define tgif_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr) \
1211 _tgif_field(_name, tgif_type_gather_float_be(_offset, _float_size, _access_mode, _attr))
1212
1213#define _tgif_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr) \
1214 { \
1215 .type = TGIF_TYPE_GATHER_STRING, \
1216 .u = { \
1217 .tgif_gather = { \
1218 .u = { \
1219 .tgif_string = { \
1220 .offset = _offset, \
1221 .access_mode = _access_mode, \
1222 .type = { \
1223 .attr = _attr, \
1224 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1225 .unit_size = _unit_size, \
1226 .byte_order = _byte_order, \
1227 }, \
1228 }, \
1229 }, \
1230 }, \
1231 }, \
1232 }
1233#define tgif_type_gather_string(_offset, _access_mode, _attr) \
1234 _tgif_type_gather_string(_offset, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, TGIF_PARAM(_attr))
1235#define tgif_field_gather_string(_name, _offset, _access_mode, _attr) \
1236 _tgif_field(_name, tgif_type_gather_string(_offset, _access_mode, TGIF_PARAM(_attr)))
1237
1238#define tgif_type_gather_string16(_offset, _access_mode, _attr) \
1239 _tgif_type_gather_string(_offset, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, TGIF_PARAM(_attr))
1240#define tgif_type_gather_string16_le(_offset, _access_mode, _attr) \
1241 _tgif_type_gather_string(_offset, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, TGIF_PARAM(_attr))
1242#define tgif_type_gather_string16_be(_offset, _access_mode, _attr) \
1243 _tgif_type_gather_string(_offset, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, TGIF_PARAM(_attr))
1244
1245#define tgif_field_gather_string16(_name, _offset, _access_mode, _attr) \
1246 _tgif_field(_name, tgif_type_gather_string16(_offset, _access_mode, TGIF_PARAM(_attr)))
1247#define tgif_field_gather_string16_le(_name, _offset, _access_mode, _attr) \
1248 _tgif_field(_name, tgif_type_gather_string16_le(_offset, _access_mode, TGIF_PARAM(_attr)))
1249#define tgif_field_gather_string16_be(_name, _offset, _access_mode, _attr) \
1250 _tgif_field(_name, tgif_type_gather_string16_be(_offset, _access_mode, TGIF_PARAM(_attr)))
1251
1252#define tgif_type_gather_string32(_offset, _access_mode, _attr) \
1253 _tgif_type_gather_string(_offset, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, TGIF_PARAM(_attr))
1254#define tgif_type_gather_string32_le(_offset, _access_mode, _attr) \
1255 _tgif_type_gather_string(_offset, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, TGIF_PARAM(_attr))
1256#define tgif_type_gather_string32_be(_offset, _access_mode, _attr) \
1257 _tgif_type_gather_string(_offset, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, TGIF_PARAM(_attr))
1258
1259#define tgif_field_gather_string32(_name, _offset, _access_mode, _attr) \
1260 _tgif_field(_name, tgif_type_gather_string32(_offset, _access_mode, TGIF_PARAM(_attr)))
1261#define tgif_field_gather_string32_le(_name, _offset, _access_mode, _attr) \
1262 _tgif_field(_name, tgif_type_gather_string32_le(_offset, _access_mode, TGIF_PARAM(_attr)))
1263#define tgif_field_gather_string32_be(_name, _offset, _access_mode, _attr) \
1264 _tgif_field(_name, tgif_type_gather_string32_be(_offset, _access_mode, TGIF_PARAM(_attr)))
1265
1266#define tgif_type_gather_enum(_mappings, _elem_type) \
1267 { \
1268 .type = TGIF_TYPE_GATHER_ENUM, \
1269 .u = { \
1270 .tgif_enum = { \
1271 .mappings = _mappings, \
1272 .elem_type = _elem_type, \
1273 }, \
1274 }, \
1275 }
1276#define tgif_field_gather_enum(_name, _mappings, _elem_type) \
1277 _tgif_field(_name, tgif_type_gather_enum(TGIF_PARAM(_mappings), TGIF_PARAM(_elem_type)))
1278
1279#define tgif_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
1280 { \
1281 .type = TGIF_TYPE_GATHER_STRUCT, \
1282 .u = { \
1283 .tgif_gather = { \
1284 .u = { \
1285 .tgif_struct = { \
1286 .offset = _offset, \
1287 .access_mode = _access_mode, \
1288 .type = _struct_gather, \
1289 .size = _size, \
1290 }, \
1291 }, \
1292 }, \
1293 }, \
1294 }
1295#define tgif_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \
1296 _tgif_field(_name, tgif_type_gather_struct(TGIF_PARAM(_struct_gather), _offset, _size, _access_mode))
1297
1298#define tgif_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr) \
1299 { \
1300 .type = TGIF_TYPE_GATHER_ARRAY, \
1301 .u = { \
1302 .tgif_gather = { \
1303 .u = { \
1304 .tgif_array = { \
1305 .offset = _offset, \
1306 .access_mode = _access_mode, \
1307 .type = { \
1308 .elem_type = _elem_type_gather, \
1309 .attr = _attr, \
1310 .length = _length, \
1311 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1312 }, \
1313 }, \
1314 }, \
1315 }, \
1316 }, \
1317 }
1318#define tgif_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr) \
1319 _tgif_field(_name, tgif_type_gather_array(TGIF_PARAM(_elem_type), _length, _offset, _access_mode, TGIF_PARAM(_attr)))
1320
1321#define tgif_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1322 { \
1323 .type = TGIF_TYPE_GATHER_VLA, \
1324 .u = { \
1325 .tgif_gather = { \
1326 .u = { \
1327 .tgif_vla = { \
1328 .length_type = _length_type_gather, \
1329 .offset = _offset, \
1330 .access_mode = _access_mode, \
1331 .type = { \
1332 .elem_type = _elem_type_gather, \
1333 .attr = _attr, \
1334 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1335 }, \
1336 }, \
1337 }, \
1338 }, \
1339 }, \
1340 }
1341#define tgif_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \
1342 _tgif_field(_name, tgif_type_gather_vla(TGIF_PARAM(_elem_type_gather), _offset, _access_mode, TGIF_PARAM(_length_type_gather), TGIF_PARAM(_attr)))
1343
1344#define tgif_elem(...) \
1345 TGIF_COMPOUND_LITERAL(const struct tgif_type, __VA_ARGS__)
1346
1347#define tgif_length(...) \
1348 TGIF_COMPOUND_LITERAL(const struct tgif_type, __VA_ARGS__)
1349
1350#define tgif_field_list(...) \
1351 TGIF_COMPOUND_LITERAL(const struct tgif_event_field, __VA_ARGS__)
1352
1353/* Stack-copy field arguments */
1354
1355#define tgif_arg_null(_val) { .type = TGIF_TYPE_NULL }
1356#define tgif_arg_bool(_val) { .type = TGIF_TYPE_BOOL, .u = { .tgif_static = { .bool_value = { .tgif_bool8 = !!(_val) } } } }
1357#define tgif_arg_byte(_val) { .type = TGIF_TYPE_BYTE, .u = { .tgif_static = { .byte_value = (_val) } } }
1358#define tgif_arg_string(_val) { .type = TGIF_TYPE_STRING_UTF8, .u = { .tgif_static = { .string_value = (uintptr_t) (_val) } } }
1359#define tgif_arg_string16(_val) { .type = TGIF_TYPE_STRING_UTF16, .u = { .tgif_static = { .string_value = (uintptr_t) (_val) } } }
1360#define tgif_arg_string32(_val) { .type = TGIF_TYPE_STRING_UTF32, .u = { .tgif_static = { .string_value = (uintptr_t) (_val) } } }
1361
1362#define tgif_arg_u8(_val) { .type = TGIF_TYPE_U8, .u = { .tgif_static = { .integer_value = { .tgif_u8 = (_val) } } } }
1363#define tgif_arg_u16(_val) { .type = TGIF_TYPE_U16, .u = { .tgif_static = { .integer_value = { .tgif_u16 = (_val) } } } }
1364#define tgif_arg_u32(_val) { .type = TGIF_TYPE_U32, .u = { .tgif_static = { .integer_value = { .tgif_u32 = (_val) } } } }
1365#define tgif_arg_u64(_val) { .type = TGIF_TYPE_U64, .u = { .tgif_static = { .integer_value = { .tgif_u64 = (_val) } } } }
1366#define tgif_arg_s8(_val) { .type = TGIF_TYPE_S8, .u = { .tgif_static = { .integer_value = { .tgif_s8 = (_val) } } } }
1367#define tgif_arg_s16(_val) { .type = TGIF_TYPE_S16, .u = { .tgif_static = { .integer_value = { .tgif_s16 = (_val) } } } }
1368#define tgif_arg_s32(_val) { .type = TGIF_TYPE_S32, .u = { .tgif_static = { .integer_value = { .tgif_s32 = (_val) } } } }
1369#define tgif_arg_s64(_val) { .type = TGIF_TYPE_S64, .u = { .tgif_static = { .integer_value = { .tgif_s64 = (_val) } } } }
1370#define tgif_arg_pointer(_val) { .type = TGIF_TYPE_POINTER, .u = { .tgif_static = { .integer_value = { .tgif_uptr = (uintptr_t) (_val) } } } }
1371#define tgif_arg_float_binary16(_val) { .type = TGIF_TYPE_FLOAT_BINARY16, .u = { .tgif_static = { .float_value = { .tgif_float_binary16 = (_val) } } } }
1372#define tgif_arg_float_binary32(_val) { .type = TGIF_TYPE_FLOAT_BINARY32, .u = { .tgif_static = { .float_value = { .tgif_float_binary32 = (_val) } } } }
1373#define tgif_arg_float_binary64(_val) { .type = TGIF_TYPE_FLOAT_BINARY64, .u = { .tgif_static = { .float_value = { .tgif_float_binary64 = (_val) } } } }
1374#define tgif_arg_float_binary128(_val) { .type = TGIF_TYPE_FLOAT_BINARY128, .u = { .tgif_static = { .float_value = { .tgif_float_binary128 = (_val) } } } }
1375
1376#define tgif_arg_struct(_tgif_type) { .type = TGIF_TYPE_STRUCT, .u = { .tgif_static = { .tgif_struct = (_tgif_type) } } }
1377#define tgif_arg_array(_tgif_type) { .type = TGIF_TYPE_ARRAY, .u = { .tgif_static = { .tgif_array = (_tgif_type) } } }
1378#define tgif_arg_vla(_tgif_type) { .type = TGIF_TYPE_VLA, .u = { .tgif_static = { .tgif_vla = (_tgif_type) } } }
1379#define tgif_arg_vla_visitor(_ctx) { .type = TGIF_TYPE_VLA_VISITOR, .u = { .tgif_static = { .tgif_vla_app_visitor_ctx = (_ctx) } } }
1380
1381/* Gather field arguments */
1382
1383#define tgif_arg_gather_bool(_ptr) { .type = TGIF_TYPE_GATHER_BOOL, .u = { .tgif_static = { .tgif_bool_gather_ptr = (_ptr) } } }
1384#define tgif_arg_gather_byte(_ptr) { .type = TGIF_TYPE_GATHER_BYTE, .u = { .tgif_static = { .tgif_byte_gather_ptr = (_ptr) } } }
1385#define tgif_arg_gather_pointer(_ptr) { .type = TGIF_TYPE_GATHER_POINTER, .u = { .tgif_static = { .tgif_integer_gather_ptr = (_ptr) } } }
1386#define tgif_arg_gather_integer(_ptr) { .type = TGIF_TYPE_GATHER_INTEGER, .u = { .tgif_static = { .tgif_integer_gather_ptr = (_ptr) } } }
1387#define tgif_arg_gather_float(_ptr) { .type = TGIF_TYPE_GATHER_FLOAT, .u = { .tgif_static = { .tgif_float_gather_ptr = (_ptr) } } }
1388#define tgif_arg_gather_string(_ptr) { .type = TGIF_TYPE_GATHER_STRING, .u = { .tgif_static = { .tgif_string_gather_ptr = (_ptr) } } }
1389#define tgif_arg_gather_struct(_ptr) { .type = TGIF_TYPE_GATHER_STRUCT, .u = { .tgif_static = { .tgif_struct_gather_ptr = (_ptr) } } }
1390#define tgif_arg_gather_array(_ptr) { .type = TGIF_TYPE_GATHER_ARRAY, .u = { .tgif_static = { .tgif_array_gather_ptr = (_ptr) } } }
1391#define tgif_arg_gather_vla(_ptr, _length_ptr) { .type = TGIF_TYPE_GATHER_VLA, .u = { .tgif_static = { .tgif_vla_gather = { .ptr = (_ptr), .length_ptr = (_length_ptr) } } } }
1392
1393/* Dynamic field arguments */
1394
1395#define tgif_arg_dynamic_null(_attr) \
1396 { \
1397 .type = TGIF_TYPE_DYNAMIC_NULL, \
1398 .u = { \
1399 .tgif_dynamic = { \
1400 .tgif_null = { \
1401 .attr = _attr, \
1402 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1403 }, \
1404 }, \
1405 }, \
1406 }
1407
1408#define tgif_arg_dynamic_bool(_val, _attr) \
1409 { \
1410 .type = TGIF_TYPE_DYNAMIC_BOOL, \
1411 .u = { \
1412 .tgif_dynamic = { \
1413 .tgif_bool = { \
1414 .type = { \
1415 .attr = _attr, \
1416 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1417 .bool_size = sizeof(uint8_t), \
1418 .len_bits = 0, \
1419 .byte_order = TGIF_TYPE_BYTE_ORDER_HOST, \
1420 }, \
1421 .value = { \
1422 .tgif_bool8 = !!(_val), \
1423 }, \
1424 }, \
1425 }, \
1426 }, \
1427 }
1428
1429#define tgif_arg_dynamic_byte(_val, _attr) \
1430 { \
1431 .type = TGIF_TYPE_DYNAMIC_BYTE, \
1432 .u = { \
1433 .tgif_dynamic = { \
1434 .tgif_byte = { \
1435 .type = { \
1436 .attr = _attr, \
1437 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1438 }, \
1439 .value = (_val), \
1440 }, \
1441 }, \
1442 }, \
1443 }
1444#define _tgif_arg_dynamic_string(_val, _byte_order, _unit_size, _attr) \
1445 { \
1446 .type = TGIF_TYPE_DYNAMIC_STRING, \
1447 .u = { \
1448 .tgif_dynamic = { \
1449 .tgif_string = { \
1450 .type = { \
1451 .attr = _attr, \
1452 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1453 .unit_size = _unit_size, \
1454 .byte_order = _byte_order, \
1455 }, \
1456 .value = (uintptr_t) (_val), \
1457 }, \
1458 }, \
1459 }, \
1460 }
1461#define tgif_arg_dynamic_string(_val, _attr) \
1462 _tgif_arg_dynamic_string(_val, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), TGIF_PARAM(_attr))
1463#define tgif_arg_dynamic_string16(_val, _attr) \
1464 _tgif_arg_dynamic_string(_val, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), TGIF_PARAM(_attr))
1465#define tgif_arg_dynamic_string16_le(_val, _attr) \
1466 _tgif_arg_dynamic_string(_val, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), TGIF_PARAM(_attr))
1467#define tgif_arg_dynamic_string16_be(_val, _attr) \
1468 _tgif_arg_dynamic_string(_val, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), TGIF_PARAM(_attr))
1469#define tgif_arg_dynamic_string32(_val, _attr) \
1470 _tgif_arg_dynamic_string(_val, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), TGIF_PARAM(_attr))
1471#define tgif_arg_dynamic_string32_le(_val, _attr) \
1472 _tgif_arg_dynamic_string(_val, TGIF_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), TGIF_PARAM(_attr))
1473#define tgif_arg_dynamic_string32_be(_val, _attr) \
1474 _tgif_arg_dynamic_string(_val, TGIF_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), TGIF_PARAM(_attr))
1475
1476#define _tgif_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
1477 { \
1478 .type = _type, \
1479 .u = { \
1480 .tgif_dynamic = { \
1481 .tgif_integer = { \
1482 .type = { \
1483 .attr = _attr, \
1484 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1485 .integer_size = _integer_size, \
1486 .len_bits = _len_bits, \
1487 .signedness = _signedness, \
1488 .byte_order = _byte_order, \
1489 }, \
1490 .value = { \
1491 _field = (_val), \
1492 }, \
1493 }, \
1494 }, \
1495 }, \
1496 }
1497
1498#define tgif_arg_dynamic_u8(_val, _attr) \
1499 _tgif_arg_dynamic_integer(.tgif_u8, _val, TGIF_TYPE_DYNAMIC_INTEGER, false, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, TGIF_PARAM(_attr))
1500#define tgif_arg_dynamic_s8(_val, _attr) \
1501 _tgif_arg_dynamic_integer(.tgif_s8, _val, TGIF_TYPE_DYNAMIC_INTEGER, true, TGIF_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, TGIF_PARAM(_attr))
1502
1503#define _tgif_arg_dynamic_u16(_val, _byte_order, _attr) \
1504 _tgif_arg_dynamic_integer(.tgif_u16, _val, TGIF_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint16_t), 0, TGIF_PARAM(_attr))
1505#define _tgif_arg_dynamic_u32(_val, _byte_order, _attr) \
1506 _tgif_arg_dynamic_integer(.tgif_u32, _val, TGIF_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint32_t), 0, TGIF_PARAM(_attr))
1507#define _tgif_arg_dynamic_u64(_val, _byte_order, _attr) \
1508 _tgif_arg_dynamic_integer(.tgif_u64, _val, TGIF_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint64_t), 0, TGIF_PARAM(_attr))
1509
1510#define _tgif_arg_dynamic_s16(_val, _byte_order, _attr) \
1511 _tgif_arg_dynamic_integer(.tgif_s16, _val, TGIF_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int16_t), 0, TGIF_PARAM(_attr))
1512#define _tgif_arg_dynamic_s32(_val, _byte_order, _attr) \
1513 _tgif_arg_dynamic_integer(.tgif_s32, _val, TGIF_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int32_t), 0, TGIF_PARAM(_attr))
1514#define _tgif_arg_dynamic_s64(_val, _byte_order, _attr) \
1515 _tgif_arg_dynamic_integer(.tgif_s64, _val, TGIF_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int64_t), 0, TGIF_PARAM(_attr))
1516
1517#define _tgif_arg_dynamic_pointer(_val, _byte_order, _attr) \
1518 _tgif_arg_dynamic_integer(.tgif_uptr, (uintptr_t) (_val), TGIF_TYPE_DYNAMIC_POINTER, false, _byte_order, \
1519 sizeof(uintptr_t), 0, TGIF_PARAM(_attr))
1520
1521#define _tgif_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr) \
1522 { \
1523 .type = _type, \
1524 .u = { \
1525 .tgif_dynamic = { \
1526 .tgif_float = { \
1527 .type = { \
1528 .attr = _attr, \
1529 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1530 .float_size = _float_size, \
1531 .byte_order = _byte_order, \
1532 }, \
1533 .value = { \
1534 _field = (_val), \
1535 }, \
1536 }, \
1537 }, \
1538 }, \
1539 }
1540
1541#define _tgif_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
1542 _tgif_arg_dynamic_float(.tgif_float_binary16, _val, TGIF_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), TGIF_PARAM(_attr))
1543#define _tgif_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
1544 _tgif_arg_dynamic_float(.tgif_float_binary32, _val, TGIF_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), TGIF_PARAM(_attr))
1545#define _tgif_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
1546 _tgif_arg_dynamic_float(.tgif_float_binary64, _val, TGIF_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), TGIF_PARAM(_attr))
1547#define _tgif_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
1548 _tgif_arg_dynamic_float(.tgif_float_binary128, _val, TGIF_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), TGIF_PARAM(_attr))
1549
1550/* Host endian */
1551#define tgif_arg_dynamic_u16(_val, _attr) _tgif_arg_dynamic_u16(_val, TGIF_TYPE_BYTE_ORDER_HOST, TGIF_PARAM(_attr))
1552#define tgif_arg_dynamic_u32(_val, _attr) _tgif_arg_dynamic_u32(_val, TGIF_TYPE_BYTE_ORDER_HOST, TGIF_PARAM(_attr))
1553#define tgif_arg_dynamic_u64(_val, _attr) _tgif_arg_dynamic_u64(_val, TGIF_TYPE_BYTE_ORDER_HOST, TGIF_PARAM(_attr))
1554#define tgif_arg_dynamic_s16(_val, _attr) _tgif_arg_dynamic_s16(_val, TGIF_TYPE_BYTE_ORDER_HOST, TGIF_PARAM(_attr))
1555#define tgif_arg_dynamic_s32(_val, _attr) _tgif_arg_dynamic_s32(_val, TGIF_TYPE_BYTE_ORDER_HOST, TGIF_PARAM(_attr))
1556#define tgif_arg_dynamic_s64(_val, _attr) _tgif_arg_dynamic_s64(_val, TGIF_TYPE_BYTE_ORDER_HOST, TGIF_PARAM(_attr))
1557#define tgif_arg_dynamic_pointer(_val, _attr) _tgif_arg_dynamic_pointer(_val, TGIF_TYPE_BYTE_ORDER_HOST, TGIF_PARAM(_attr))
1558#define tgif_arg_dynamic_float_binary16(_val, _attr) _tgif_arg_dynamic_float_binary16(_val, TGIF_TYPE_FLOAT_WORD_ORDER_HOST, TGIF_PARAM(_attr))
1559#define tgif_arg_dynamic_float_binary32(_val, _attr) _tgif_arg_dynamic_float_binary32(_val, TGIF_TYPE_FLOAT_WORD_ORDER_HOST, TGIF_PARAM(_attr))
1560#define tgif_arg_dynamic_float_binary64(_val, _attr) _tgif_arg_dynamic_float_binary64(_val, TGIF_TYPE_FLOAT_WORD_ORDER_HOST, TGIF_PARAM(_attr))
1561#define tgif_arg_dynamic_float_binary128(_val, _attr) _tgif_arg_dynamic_float_binary128(_val, TGIF_TYPE_FLOAT_WORD_ORDER_HOST, TGIF_PARAM(_attr))
1562
1563/* Little endian */
1564#define tgif_arg_dynamic_u16_le(_val, _attr) _tgif_arg_dynamic_u16(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1565#define tgif_arg_dynamic_u32_le(_val, _attr) _tgif_arg_dynamic_u32(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1566#define tgif_arg_dynamic_u64_le(_val, _attr) _tgif_arg_dynamic_u64(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1567#define tgif_arg_dynamic_s16_le(_val, _attr) _tgif_arg_dynamic_s16(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1568#define tgif_arg_dynamic_s32_le(_val, _attr) _tgif_arg_dynamic_s32(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1569#define tgif_arg_dynamic_s64_le(_val, _attr) _tgif_arg_dynamic_s64(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1570#define tgif_arg_dynamic_pointer_le(_val, _attr) _tgif_arg_dynamic_pointer(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1571#define tgif_arg_dynamic_float_binary16_le(_val, _attr) _tgif_arg_dynamic_float_binary16(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1572#define tgif_arg_dynamic_float_binary32_le(_val, _attr) _tgif_arg_dynamic_float_binary32(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1573#define tgif_arg_dynamic_float_binary64_le(_val, _attr) _tgif_arg_dynamic_float_binary64(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1574#define tgif_arg_dynamic_float_binary128_le(_val, _attr) _tgif_arg_dynamic_float_binary128(_val, TGIF_TYPE_BYTE_ORDER_LE, TGIF_PARAM(_attr))
1575
1576/* Big endian */
1577#define tgif_arg_dynamic_u16_be(_val, _attr) _tgif_arg_dynamic_u16(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1578#define tgif_arg_dynamic_u32_be(_val, _attr) _tgif_arg_dynamic_u32(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1579#define tgif_arg_dynamic_u64_be(_val, _attr) _tgif_arg_dynamic_u64(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1580#define tgif_arg_dynamic_s16_be(_val, _attr) _tgif_arg_dynamic_s16(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1581#define tgif_arg_dynamic_s32_be(_val, _attr) _tgif_arg_dynamic_s32(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1582#define tgif_arg_dynamic_s64_be(_val, _attr) _tgif_arg_dynamic_s64(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1583#define tgif_arg_dynamic_pointer_be(_val, _attr) _tgif_arg_dynamic_pointer(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1584#define tgif_arg_dynamic_float_binary16_be(_val, _attr) _tgif_arg_dynamic_float_binary16(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1585#define tgif_arg_dynamic_float_binary32_be(_val, _attr) _tgif_arg_dynamic_float_binary32(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1586#define tgif_arg_dynamic_float_binary64_be(_val, _attr) _tgif_arg_dynamic_float_binary64(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1587#define tgif_arg_dynamic_float_binary128_be(_val, _attr) _tgif_arg_dynamic_float_binary128(_val, TGIF_TYPE_BYTE_ORDER_BE, TGIF_PARAM(_attr))
1588
1589#define tgif_arg_dynamic_vla(_vla) \
1590 { \
1591 .type = TGIF_TYPE_DYNAMIC_VLA, \
1592 .u = { \
1593 .tgif_dynamic = { \
1594 .tgif_dynamic_vla = (_vla), \
1595 }, \
1596 }, \
1597 }
1598
1599#define tgif_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1600 { \
1601 .type = TGIF_TYPE_DYNAMIC_VLA_VISITOR, \
1602 .u = { \
1603 .tgif_dynamic = { \
1604 .tgif_dynamic_vla_visitor = { \
1605 .app_ctx = _ctx, \
1606 .visitor = _dynamic_vla_visitor, \
1607 .attr = _attr, \
1608 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1609 }, \
1610 }, \
1611 }, \
1612 }
1613
1614#define tgif_arg_dynamic_struct(_struct) \
1615 { \
1616 .type = TGIF_TYPE_DYNAMIC_STRUCT, \
1617 .u = { \
1618 .tgif_dynamic = { \
1619 .tgif_dynamic_struct = (_struct), \
1620 }, \
1621 }, \
1622 }
1623
1624#define tgif_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1625 { \
1626 .type = TGIF_TYPE_DYNAMIC_STRUCT_VISITOR, \
1627 .u = { \
1628 .tgif_dynamic = { \
1629 .tgif_dynamic_struct_visitor = { \
1630 .app_ctx = _ctx, \
1631 .visitor = _dynamic_struct_visitor, \
1632 .attr = _attr, \
1633 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1634 }, \
1635 }, \
1636 }, \
1637 }
1638
1639#define tgif_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1640 const struct tgif_arg _identifier##_vec[] = { _sav }; \
1641 const struct tgif_arg_dynamic_vla _identifier = { \
1642 .sav = _identifier##_vec, \
1643 .attr = _attr, \
1644 .len = TGIF_ARRAY_SIZE(_identifier##_vec), \
1645 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1646 }
1647
1648#define tgif_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1649 const struct tgif_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \
1650 const struct tgif_arg_dynamic_struct _identifier = { \
1651 .fields = _identifier##_fields, \
1652 .attr = _attr, \
1653 .len = TGIF_ARRAY_SIZE(_identifier##_fields), \
1654 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1655 }
1656
1657#define tgif_arg_define_vec(_identifier, _sav) \
1658 const struct tgif_arg _identifier##_vec[] = { _sav }; \
1659 const struct tgif_arg_vec _identifier = { \
1660 .sav = _identifier##_vec, \
1661 .len = TGIF_ARRAY_SIZE(_identifier##_vec), \
1662 }
1663
1664#define tgif_arg_dynamic_field(_name, _elem) \
1665 { \
1666 .field_name = _name, \
1667 .elem = _elem, \
1668 }
1669
1670/*
1671 * Event instrumentation description registration, runtime enabled state
1672 * check, and instrumentation invocation.
1673 */
1674
1675#define tgif_arg_list(...) __VA_ARGS__
1676
1677#define tgif_event_cond(_identifier) \
1678 if (tgif_unlikely(__atomic_load_n(&tgif_event_enable__##_identifier, \
1679 __ATOMIC_RELAXED)))
1680
1681#define tgif_event_call(_identifier, _sav) \
1682 { \
1683 const struct tgif_arg tgif_sav[] = { _sav }; \
1684 const struct tgif_arg_vec tgif_arg_vec = { \
1685 .sav = tgif_sav, \
1686 .len = TGIF_ARRAY_SIZE(tgif_sav), \
1687 }; \
1688 tgif_call(&(_identifier), &tgif_arg_vec); \
1689 }
1690
1691#define tgif_event(_identifier, _sav) \
1692 tgif_event_cond(_identifier) \
1693 tgif_event_call(_identifier, TGIF_PARAM(_sav))
1694
1695#define tgif_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1696 { \
1697 const struct tgif_arg tgif_sav[] = { _sav }; \
1698 const struct tgif_arg_vec tgif_arg_vec = { \
1699 .sav = tgif_sav, \
1700 .len = TGIF_ARRAY_SIZE(tgif_sav), \
1701 }; \
1702 const struct tgif_arg_dynamic_field tgif_fields[] = { _var_fields }; \
1703 const struct tgif_arg_dynamic_struct var_struct = { \
1704 .fields = tgif_fields, \
1705 .attr = _attr, \
1706 .len = TGIF_ARRAY_SIZE(tgif_fields), \
1707 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1708 }; \
1709 tgif_call_variadic(&(_identifier), &tgif_arg_vec, &var_struct); \
1710 }
1711
1712#define tgif_event_variadic(_identifier, _sav, _var, _attr) \
1713 tgif_event_cond(_identifier) \
1714 tgif_event_call_variadic(_identifier, TGIF_PARAM(_sav), TGIF_PARAM(_var), TGIF_PARAM(_attr))
1715
1716#define _tgif_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1717 _linkage uintptr_t tgif_event_enable__##_identifier __attribute__((section("tgif_event_enable"))); \
1718 _linkage struct tgif_event_description __attribute__((section("tgif_event_description"))) \
1719 _identifier = { \
1720 .enabled = &(tgif_event_enable__##_identifier), \
1721 .provider_name = _provider, \
1722 .event_name = _event, \
1723 .fields = _fields, \
1724 .attr = _attr, \
1725 .callbacks = &tgif_empty_callback, \
1726 .flags = (_flags), \
1727 .version = 0, \
1728 .loglevel = _loglevel, \
1729 .nr_fields = TGIF_ARRAY_SIZE(TGIF_PARAM(_fields)), \
1730 .nr_attr = TGIF_ARRAY_SIZE(TGIF_PARAM(_attr)), \
1731 .nr_callbacks = 0, \
1732 }; \
1733 static const struct tgif_event_description *tgif_event_ptr__##_identifier \
1734 __attribute__((section("tgif_event_description_ptr"), used)) = &(_identifier);
1735
1736#define tgif_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1737 _tgif_define_event(static, _identifier, _provider, _event, _loglevel, TGIF_PARAM(_fields), \
1738 TGIF_PARAM(_attr), 0)
1739
1740#define tgif_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1741 _tgif_define_event(static, _identifier, _provider, _event, _loglevel, TGIF_PARAM(_fields), \
1742 TGIF_PARAM(_attr), TGIF_EVENT_FLAG_VARIADIC)
1743
1744#define tgif_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1745 _tgif_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1746 _loglevel, TGIF_PARAM(_fields), TGIF_PARAM(_attr), 0)
1747
1748#define tgif_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1749 _tgif_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \
1750 _loglevel, TGIF_PARAM(_fields), TGIF_PARAM(_attr), TGIF_EVENT_FLAG_VARIADIC)
1751
1752#define tgif_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1753 _tgif_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1754 _loglevel, TGIF_PARAM(_fields), TGIF_PARAM(_attr), 0)
1755
1756#define tgif_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1757 _tgif_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \
1758 _loglevel, TGIF_PARAM(_fields), TGIF_PARAM(_attr), TGIF_EVENT_FLAG_VARIADIC)
1759
1760#define tgif_declare_event(_identifier) \
1761 extern uintptr_t tgif_event_enable_##_identifier; \
1762 extern struct tgif_event_description _identifier
1763
1764#ifdef __cplusplus
1765extern "C" {
1766#endif
1767
1768extern const struct tgif_callback tgif_empty_callback;
1769
1770void tgif_call(const struct tgif_event_description *desc,
1771 const struct tgif_arg_vec *tgif_arg_vec);
1772void tgif_call_variadic(const struct tgif_event_description *desc,
1773 const struct tgif_arg_vec *tgif_arg_vec,
1774 const struct tgif_arg_dynamic_struct *var_struct);
1775
1776struct tgif_events_register_handle *tgif_events_register(struct tgif_event_description **events,
1777 uint32_t nr_events);
1778void tgif_events_unregister(struct tgif_events_register_handle *handle);
1779
1780/*
1781 * Userspace tracer registration API. This allows userspace tracers to
1782 * register event notification callbacks to be notified of the currently
1783 * registered instrumentation, and to register their callbacks to
1784 * specific events.
1785 */
1786typedef void (*tgif_tracer_callback_func)(const struct tgif_event_description *desc,
1787 const struct tgif_arg_vec *tgif_arg_vec,
1788 void *priv);
1789typedef void (*tgif_tracer_callback_variadic_func)(const struct tgif_event_description *desc,
1790 const struct tgif_arg_vec *tgif_arg_vec,
1791 const struct tgif_arg_dynamic_struct *var_struct,
1792 void *priv);
1793
1794int tgif_tracer_callback_register(struct tgif_event_description *desc,
1795 tgif_tracer_callback_func call,
1796 void *priv);
1797int tgif_tracer_callback_variadic_register(struct tgif_event_description *desc,
1798 tgif_tracer_callback_variadic_func call_variadic,
1799 void *priv);
1800int tgif_tracer_callback_unregister(struct tgif_event_description *desc,
1801 tgif_tracer_callback_func call,
1802 void *priv);
1803int tgif_tracer_callback_variadic_unregister(struct tgif_event_description *desc,
1804 tgif_tracer_callback_variadic_func call_variadic,
1805 void *priv);
1806
1807enum tgif_tracer_notification {
1808 TGIF_TRACER_NOTIFICATION_INSERT_EVENTS,
1809 TGIF_TRACER_NOTIFICATION_REMOVE_EVENTS,
1810};
1811
1812/* Callback is invoked with tgif library internal lock held. */
1813struct tgif_tracer_handle *tgif_tracer_event_notification_register(
1814 void (*cb)(enum tgif_tracer_notification notif,
1815 struct tgif_event_description **events, uint32_t nr_events, void *priv),
1816 void *priv);
1817void tgif_tracer_event_notification_unregister(struct tgif_tracer_handle *handle);
1818
1819/*
1820 * Explicit hooks to initialize/finalize the tgif instrumentation
1821 * library. Those are also library constructor/destructor.
1822 */
1823void tgif_init(void) __attribute__((constructor));
1824void tgif_exit(void) __attribute__((destructor));
1825
1826/*
1827 * The following constructors/destructors perform automatic registration
1828 * of the declared tgif events. Those may have to be called explicitly
1829 * in a statically linked library.
1830 */
1831
1832/*
1833 * These weak symbols, the constructor, and destructor take care of
1834 * registering only _one_ instance of the tgif instrumentation per
1835 * shared-ojbect (or for the whole main program).
1836 */
1837extern struct tgif_event_description * __start_tgif_event_description_ptr[]
1838 __attribute__((weak, visibility("hidden")));
1839extern struct tgif_event_description * __stop_tgif_event_description_ptr[]
1840 __attribute__((weak, visibility("hidden")));
1841int tgif_event_description_ptr_registered
1842 __attribute__((weak, visibility("hidden")));
1843struct tgif_events_register_handle *tgif_events_handle
1844 __attribute__((weak, visibility("hidden")));
1845
1846static void
1847tgif_event_description_ptr_init(void)
1848 __attribute__((no_instrument_function))
1849 __attribute__((constructor));
1850static void
1851tgif_event_description_ptr_init(void)
1852{
1853 if (tgif_event_description_ptr_registered++)
1854 return;
1855 tgif_events_handle = tgif_events_register(__start_tgif_event_description_ptr,
1856 __stop_tgif_event_description_ptr - __start_tgif_event_description_ptr);
1857}
1858
1859static void
1860tgif_event_description_ptr_exit(void)
1861 __attribute__((no_instrument_function))
1862 __attribute__((destructor));
1863static void
1864tgif_event_description_ptr_exit(void)
1865{
1866 if (--tgif_event_description_ptr_registered)
1867 return;
1868 tgif_events_unregister(tgif_events_handle);
1869 tgif_events_handle = NULL;
1870}
1871
1872#ifdef __cplusplus
1873}
1874#endif
1875
1876#endif /* _TGIF_TRACE_H */
This page took 0.090132 seconds and 4 git commands to generate.