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