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