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