Implement support for host/le/be integer and float endianness
[libside.git] / include / side / trace.h
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 */
5
6 #ifndef _SIDE_TRACE_H
7 #define _SIDE_TRACE_H
8
9 #include <stdint.h>
10 #include <inttypes.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <math.h>
14 #include <side/macros.h>
15 #include <side/endian.h>
16
17 /* SIDE stands for "Static Instrumentation Dynamically Enabled" */
18
19 //TODO: as those structures will be ABI, we need to either consider them
20 //fixed forever, or think of a scheme that would allow their binary
21 //representation to be extended if need be.
22
23 struct side_arg_vec;
24 struct side_arg_vec_description;
25 struct side_arg_dynamic_vec;
26 struct side_arg_dynamic_vec_vla;
27 struct side_type_description;
28 struct side_event_field;
29 struct side_tracer_visitor_ctx;
30 struct side_tracer_dynamic_struct_visitor_ctx;
31 struct side_tracer_dynamic_vla_visitor_ctx;
32 struct side_event_description;
33 struct side_arg_dynamic_event_struct;
34 struct side_events_register_handle;
35
36 enum side_type {
37 /* Basic types */
38 SIDE_TYPE_BOOL,
39 SIDE_TYPE_U8,
40 SIDE_TYPE_U16,
41 SIDE_TYPE_U32,
42 SIDE_TYPE_U64,
43 SIDE_TYPE_S8,
44 SIDE_TYPE_S16,
45 SIDE_TYPE_S32,
46 SIDE_TYPE_S64,
47 SIDE_TYPE_BYTE,
48 SIDE_TYPE_FLOAT_BINARY16,
49 SIDE_TYPE_FLOAT_BINARY32,
50 SIDE_TYPE_FLOAT_BINARY64,
51 SIDE_TYPE_FLOAT_BINARY128,
52 SIDE_TYPE_STRING,
53
54 /* Compound types */
55 SIDE_TYPE_STRUCT,
56 SIDE_TYPE_ARRAY,
57 SIDE_TYPE_VLA,
58 SIDE_TYPE_VLA_VISITOR,
59
60 SIDE_TYPE_ARRAY_U8,
61 SIDE_TYPE_ARRAY_U16,
62 SIDE_TYPE_ARRAY_U32,
63 SIDE_TYPE_ARRAY_U64,
64 SIDE_TYPE_ARRAY_S8,
65 SIDE_TYPE_ARRAY_S16,
66 SIDE_TYPE_ARRAY_S32,
67 SIDE_TYPE_ARRAY_S64,
68 SIDE_TYPE_ARRAY_BYTE,
69
70 SIDE_TYPE_VLA_U8,
71 SIDE_TYPE_VLA_U16,
72 SIDE_TYPE_VLA_U32,
73 SIDE_TYPE_VLA_U64,
74 SIDE_TYPE_VLA_S8,
75 SIDE_TYPE_VLA_S16,
76 SIDE_TYPE_VLA_S32,
77 SIDE_TYPE_VLA_S64,
78 SIDE_TYPE_VLA_BYTE,
79
80 /* Enumeration types */
81 SIDE_TYPE_ENUM,
82 SIDE_TYPE_ENUM_BITMAP,
83
84 /* Dynamic type */
85 SIDE_TYPE_DYNAMIC,
86 };
87
88 enum side_dynamic_type {
89 /* Basic types */
90 SIDE_DYNAMIC_TYPE_NULL,
91 SIDE_DYNAMIC_TYPE_BOOL,
92 SIDE_DYNAMIC_TYPE_U8,
93 SIDE_DYNAMIC_TYPE_U16,
94 SIDE_DYNAMIC_TYPE_U32,
95 SIDE_DYNAMIC_TYPE_U64,
96 SIDE_DYNAMIC_TYPE_S8,
97 SIDE_DYNAMIC_TYPE_S16,
98 SIDE_DYNAMIC_TYPE_S32,
99 SIDE_DYNAMIC_TYPE_S64,
100 SIDE_DYNAMIC_TYPE_BYTE,
101 SIDE_DYNAMIC_TYPE_FLOAT_BINARY16,
102 SIDE_DYNAMIC_TYPE_FLOAT_BINARY32,
103 SIDE_DYNAMIC_TYPE_FLOAT_BINARY64,
104 SIDE_DYNAMIC_TYPE_FLOAT_BINARY128,
105 SIDE_DYNAMIC_TYPE_STRING,
106
107 /* Compound types */
108 SIDE_DYNAMIC_TYPE_STRUCT,
109 SIDE_DYNAMIC_TYPE_STRUCT_VISITOR,
110 SIDE_DYNAMIC_TYPE_VLA,
111 SIDE_DYNAMIC_TYPE_VLA_VISITOR,
112 };
113
114 enum side_attr_type {
115 SIDE_ATTR_TYPE_NULL,
116 SIDE_ATTR_TYPE_BOOL,
117 SIDE_ATTR_TYPE_U8,
118 SIDE_ATTR_TYPE_U16,
119 SIDE_ATTR_TYPE_U32,
120 SIDE_ATTR_TYPE_U64,
121 SIDE_ATTR_TYPE_S8,
122 SIDE_ATTR_TYPE_S16,
123 SIDE_ATTR_TYPE_S32,
124 SIDE_ATTR_TYPE_S64,
125 SIDE_ATTR_TYPE_FLOAT_BINARY16,
126 SIDE_ATTR_TYPE_FLOAT_BINARY32,
127 SIDE_ATTR_TYPE_FLOAT_BINARY64,
128 SIDE_ATTR_TYPE_FLOAT_BINARY128,
129 SIDE_ATTR_TYPE_STRING,
130 };
131
132 enum side_loglevel {
133 SIDE_LOGLEVEL_EMERG = 0,
134 SIDE_LOGLEVEL_ALERT = 1,
135 SIDE_LOGLEVEL_CRIT = 2,
136 SIDE_LOGLEVEL_ERR = 3,
137 SIDE_LOGLEVEL_WARNING = 4,
138 SIDE_LOGLEVEL_NOTICE = 5,
139 SIDE_LOGLEVEL_INFO = 6,
140 SIDE_LOGLEVEL_DEBUG = 7,
141 };
142
143 enum side_visitor_status {
144 SIDE_VISITOR_STATUS_OK = 0,
145 SIDE_VISITOR_STATUS_ERROR = -1,
146 };
147
148 enum side_error {
149 SIDE_ERROR_OK = 0,
150 SIDE_ERROR_INVAL = 1,
151 SIDE_ERROR_EXIST = 2,
152 SIDE_ERROR_NOMEM = 3,
153 SIDE_ERROR_NOENT = 4,
154 SIDE_ERROR_EXITING = 5,
155 };
156
157 enum side_type_byte_order {
158 SIDE_TYPE_BYTE_ORDER_LE = 0,
159 SIDE_TYPE_BYTE_ORDER_BE = 1,
160 };
161
162 #if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN)
163 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
164 #else
165 # define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
166 #endif
167
168 #if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN)
169 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE
170 #else
171 # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE
172 #endif
173
174 typedef enum side_visitor_status (*side_visitor)(
175 const struct side_tracer_visitor_ctx *tracer_ctx,
176 void *app_ctx);
177 typedef enum side_visitor_status (*side_dynamic_struct_visitor)(
178 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
179 void *app_ctx);
180 typedef enum side_visitor_status (*side_dynamic_vla_visitor)(
181 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
182 void *app_ctx);
183
184 struct side_attr_value {
185 uint32_t type; /* enum side_attr_type */
186 union {
187 uint8_t side_bool;
188 uint8_t side_u8;
189 uint16_t side_u16;
190 uint32_t side_u32;
191 uint64_t side_u64;
192 int8_t side_s8;
193 int16_t side_s16;
194 int32_t side_s32;
195 int64_t side_s64;
196 #if __HAVE_FLOAT16
197 _Float16 side_float_binary16;
198 #endif
199 #if __HAVE_FLOAT32
200 _Float32 side_float_binary32;
201 #endif
202 #if __HAVE_FLOAT64
203 _Float64 side_float_binary64;
204 #endif
205 #if __HAVE_FLOAT128
206 _Float128 side_float_binary128;
207 #endif
208 const char *string;
209 } u;
210 };
211
212 /* User attributes. */
213 struct side_attr {
214 const char *key;
215 const struct side_attr_value value;
216 };
217
218 struct side_enum_mapping {
219 int64_t range_begin;
220 int64_t range_end;
221 const char *label;
222 };
223
224 struct side_enum_mappings {
225 const struct side_enum_mapping *mappings;
226 const struct side_attr *attr;
227 uint32_t nr_mappings;
228 uint32_t nr_attr;
229 };
230
231 struct side_enum_bitmap_mapping {
232 uint64_t range_begin;
233 uint64_t range_end;
234 const char *label;
235 };
236
237 struct side_enum_bitmap_mappings {
238 const struct side_enum_bitmap_mapping *mappings;
239 const struct side_attr *attr;
240 uint32_t nr_mappings;
241 uint32_t nr_attr;
242 };
243
244 struct side_type_struct {
245 uint32_t nr_fields;
246 uint32_t nr_attr;
247 const struct side_event_field *fields;
248 const struct side_attr *attr;
249 };
250
251 struct side_type_description {
252 uint32_t type; /* enum side_type */
253 union {
254 /* Basic types */
255 struct {
256 const struct side_attr *attr;
257 uint32_t nr_attr;
258 uint32_t byte_order; /* enum side_type_byte_order */
259 } side_basic;
260
261 /* Compound types */
262 struct {
263 const struct side_type_description *elem_type;
264 const struct side_attr *attr;
265 uint32_t length;
266 uint32_t nr_attr;
267 } side_array;
268 struct {
269 const struct side_type_description *elem_type;
270 const struct side_attr *attr;
271 uint32_t nr_attr;
272 } side_vla;
273 struct {
274 const struct side_type_description *elem_type;
275 side_visitor visitor;
276 const struct side_attr *attr;
277 uint32_t nr_attr;
278 } side_vla_visitor;
279 const struct side_type_struct *side_struct;
280
281 /* Enumeration types */
282 struct {
283 const struct side_enum_mappings *mappings;
284 const struct side_type_description *elem_type;
285 } side_enum;
286 struct {
287 const struct side_enum_bitmap_mappings *mappings;
288 const struct side_type_description *elem_type;
289 } side_enum_bitmap;
290 } u;
291 };
292
293 struct side_event_field {
294 const char *field_name;
295 struct side_type_description side_type;
296 };
297
298 enum side_event_flags {
299 SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
300 };
301
302 struct side_callback {
303 union {
304 void (*call)(const struct side_event_description *desc,
305 const struct side_arg_vec_description *sav_desc,
306 void *priv);
307 void (*call_variadic)(const struct side_event_description *desc,
308 const struct side_arg_vec_description *sav_desc,
309 const struct side_arg_dynamic_event_struct *var_struct,
310 void *priv);
311 } u;
312 void *priv;
313 };
314
315 struct side_event_description {
316 uintptr_t *enabled;
317 const char *provider_name;
318 const char *event_name;
319 const struct side_event_field *fields;
320 const struct side_attr *attr;
321 const struct side_callback *callbacks;
322 uint64_t flags;
323 uint32_t version;
324 uint32_t loglevel; /* enum side_loglevel */
325 uint32_t nr_fields;
326 uint32_t nr_attr;
327 uint32_t nr_callbacks;
328 };
329
330 struct side_arg_dynamic_vec {
331 uint32_t dynamic_type; /* enum side_dynamic_type */
332 union {
333 /* Basic types */
334 struct {
335 const struct side_attr *attr;
336 uint32_t nr_attr;
337 uint32_t byte_order; /* enum side_type_byte_order */
338 union {
339 uint8_t side_bool;
340 uint8_t side_u8;
341 uint16_t side_u16;
342 uint32_t side_u32;
343 uint64_t side_u64;
344 int8_t side_s8;
345 int16_t side_s16;
346 int32_t side_s32;
347 int64_t side_s64;
348 uint8_t side_byte;
349 #if __HAVE_FLOAT16
350 _Float16 side_float_binary16;
351 #endif
352 #if __HAVE_FLOAT32
353 _Float32 side_float_binary32;
354 #endif
355 #if __HAVE_FLOAT64
356 _Float64 side_float_binary64;
357 #endif
358 #if __HAVE_FLOAT128
359 _Float128 side_float_binary128;
360 #endif
361 const char *string;
362 } u;
363 } side_basic;
364
365 /* Compound types */
366 const struct side_arg_dynamic_event_struct *side_dynamic_struct;
367 struct {
368 void *app_ctx;
369 side_dynamic_struct_visitor visitor;
370 const struct side_attr *attr;
371 uint32_t nr_attr;
372 } side_dynamic_struct_visitor;
373 const struct side_arg_dynamic_vec_vla *side_dynamic_vla;
374 struct {
375 void *app_ctx;
376 side_dynamic_vla_visitor visitor;
377 const struct side_attr *attr;
378 uint32_t nr_attr;
379 } side_dynamic_vla_visitor;
380 } u;
381 };
382
383 struct side_arg_dynamic_vec_vla {
384 const struct side_arg_dynamic_vec *sav;
385 const struct side_attr *attr;
386 uint32_t len;
387 uint32_t nr_attr;
388 };
389
390 struct side_arg_dynamic_event_field {
391 const char *field_name;
392 const struct side_arg_dynamic_vec elem;
393 };
394
395 struct side_arg_dynamic_event_struct {
396 const struct side_arg_dynamic_event_field *fields;
397 const struct side_attr *attr;
398 uint32_t len;
399 uint32_t nr_attr;
400 };
401
402 struct side_arg_vec {
403 enum side_type type;
404 union {
405 /* Basic types */
406 uint8_t side_bool;
407 uint8_t side_u8;
408 uint16_t side_u16;
409 uint32_t side_u32;
410 uint64_t side_u64;
411 int8_t side_s8;
412 int16_t side_s16;
413 int32_t side_s32;
414 int64_t side_s64;
415 uint8_t side_byte;
416 #if __HAVE_FLOAT16
417 _Float16 side_float_binary16;
418 #endif
419 #if __HAVE_FLOAT32
420 _Float32 side_float_binary32;
421 #endif
422 #if __HAVE_FLOAT64
423 _Float64 side_float_binary64;
424 #endif
425 #if __HAVE_FLOAT128
426 _Float128 side_float_binary128;
427 #endif
428 const char *string;
429
430 /* Compound types */
431 const struct side_arg_vec_description *side_struct;
432 const struct side_arg_vec_description *side_array;
433 const struct side_arg_vec_description *side_vla;
434 void *side_vla_app_visitor_ctx;
435 void *side_array_fixint;
436 struct {
437 void *p;
438 uint32_t length;
439 } side_vla_fixint;
440
441 /* Dynamic type */
442 struct side_arg_dynamic_vec dynamic;
443 } u;
444 };
445
446 struct side_arg_vec_description {
447 const struct side_arg_vec *sav;
448 uint32_t len;
449 };
450
451 /* The visitor pattern is a double-dispatch visitor. */
452 struct side_tracer_visitor_ctx {
453 enum side_visitor_status (*write_elem)(
454 const struct side_tracer_visitor_ctx *tracer_ctx,
455 const struct side_arg_vec *elem);
456 void *priv; /* Private tracer context. */
457 };
458
459 struct side_tracer_dynamic_struct_visitor_ctx {
460 enum side_visitor_status (*write_field)(
461 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
462 const struct side_arg_dynamic_event_field *dynamic_field);
463 void *priv; /* Private tracer context. */
464 };
465
466 struct side_tracer_dynamic_vla_visitor_ctx {
467 enum side_visitor_status (*write_elem)(
468 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
469 const struct side_arg_dynamic_vec *elem);
470 void *priv; /* Private tracer context. */
471 };
472
473 /* Event and type attributes */
474
475 #define side_attr(_key, _value) \
476 { \
477 .key = _key, \
478 .value = SIDE_PARAM(_value), \
479 }
480
481 #define side_attr_list(...) \
482 SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
483
484 #define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL }
485 #define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
486 #define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } }
487 #define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } }
488 #define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } }
489 #define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } }
490 #define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } }
491 #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } }
492 #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } }
493 #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } }
494 #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
495 #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
496 #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
497 #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
498 #define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } }
499
500 /* Static field definition */
501
502 #define _side_type_basic(_type, _byte_order, _attr) \
503 { \
504 .type = _type, \
505 .u = { \
506 .side_basic = { \
507 .attr = _attr, \
508 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
509 .byte_order = _byte_order, \
510 }, \
511 }, \
512 }
513
514 #define _side_field(_name, _type) \
515 { \
516 .field_name = _name, \
517 .side_type = _type, \
518 }
519
520 /* Host endian */
521 #define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
522 #define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
523 #define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
524 #define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
525 #define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
526 #define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
527 #define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
528 #define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
529 #define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
530 #define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
531 #define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
532 #define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
533 #define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
534 #define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
535 #define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
536 #define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
537
538 #define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
539 #define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr)))
540 #define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr)))
541 #define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr)))
542 #define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr)))
543 #define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr)))
544 #define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
545 #define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
546 #define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
547 #define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr)))
548 #define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
549 #define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
550 #define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
551 #define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
552 #define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
553 #define side_field_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr)))
554
555 /* Little endian */
556 #define side_type_u16_le(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
557 #define side_type_u32_le(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
558 #define side_type_u64_le(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
559 #define side_type_s16_le(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
560 #define side_type_s32_le(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
561 #define side_type_s64_le(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
562 #define side_type_float_binary16_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
563 #define side_type_float_binary32_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
564 #define side_type_float_binary64_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
565 #define side_type_float_binary128_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
566
567 #define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
568 #define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
569 #define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr)))
570 #define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr)))
571 #define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr)))
572 #define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr)))
573 #define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr)))
574 #define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
575 #define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
576 #define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
577
578 /* Big endian */
579 #define side_type_u16_be(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
580 #define side_type_u32_be(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
581 #define side_type_u64_be(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
582 #define side_type_s16_be(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
583 #define side_type_s32_be(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
584 #define side_type_s64_be(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
585 #define side_type_float_binary16_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
586 #define side_type_float_binary32_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
587 #define side_type_float_binary64_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
588 #define side_type_float_binary128_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
589
590 #define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
591 #define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
592 #define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr)))
593 #define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr)))
594 #define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr)))
595 #define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr)))
596 #define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr)))
597 #define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
598 #define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
599 #define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
600
601 #define side_type_enum(_mappings, _elem_type) \
602 { \
603 .type = SIDE_TYPE_ENUM, \
604 .u = { \
605 .side_enum = { \
606 .mappings = _mappings, \
607 .elem_type = _elem_type, \
608 }, \
609 }, \
610 }
611 #define side_field_enum(_name, _mappings, _elem_type) \
612 _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
613
614 #define side_type_enum_bitmap(_mappings, _elem_type) \
615 { \
616 .type = SIDE_TYPE_ENUM_BITMAP, \
617 .u = { \
618 .side_enum_bitmap = { \
619 .mappings = _mappings, \
620 .elem_type = _elem_type, \
621 }, \
622 }, \
623 }
624 #define side_field_enum_bitmap(_name, _mappings, _elem_type) \
625 _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
626
627 #define side_type_struct(_struct) \
628 { \
629 .type = SIDE_TYPE_STRUCT, \
630 .u = { \
631 .side_struct = _struct, \
632 }, \
633 }
634 #define side_field_struct(_name, _struct) \
635 _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
636
637 #define _side_type_struct_define(_fields, _attr) \
638 { \
639 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
640 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
641 .fields = _fields, \
642 .attr = _attr, \
643 }
644
645 #define side_define_struct(_identifier, _fields, _attr) \
646 const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))
647
648 #define side_struct_literal(_fields, _attr) \
649 SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
650 _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
651
652 #define side_type_array(_elem_type, _length, _attr) \
653 { \
654 .type = SIDE_TYPE_ARRAY, \
655 .u = { \
656 .side_array = { \
657 .elem_type = _elem_type, \
658 .attr = _attr, \
659 .length = _length, \
660 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
661 }, \
662 }, \
663 }
664 #define side_field_array(_name, _elem_type, _length, _attr) \
665 _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr)))
666
667 #define side_type_vla(_elem_type, _attr) \
668 { \
669 .type = SIDE_TYPE_VLA, \
670 .u = { \
671 .side_vla = { \
672 .elem_type = _elem_type, \
673 .attr = _attr, \
674 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
675 }, \
676 }, \
677 }
678 #define side_field_vla(_name, _elem_type, _attr) \
679 _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr)))
680
681 #define side_type_vla_visitor(_elem_type, _visitor, _attr) \
682 { \
683 .type = SIDE_TYPE_VLA_VISITOR, \
684 .u = { \
685 .side_vla_visitor = { \
686 .elem_type = SIDE_PARAM(_elem_type), \
687 .visitor = _visitor, \
688 .attr = _attr, \
689 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
690 }, \
691 }, \
692 }
693 #define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \
694 _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr)))
695
696 #define side_elem(...) \
697 SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__)
698
699 #define side_field_list(...) \
700 SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
701
702 /* Static field arguments */
703
704 #define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } }
705 #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } }
706 #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } }
707 #define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } }
708 #define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } }
709 #define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } }
710 #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } }
711 #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } }
712 #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } }
713 #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } }
714 #define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } }
715 #define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } }
716 #define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } }
717 #define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } }
718 #define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } }
719 #define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } }
720 #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } }
721 #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } }
722 #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } }
723 #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } }
724
725 #define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } }
726 #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } }
727 #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } }
728 #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } }
729 #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_vla_app_visitor_ctx = (_ctx) } }
730
731 #define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_array_fixint = (_ptr) } }
732 #define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_array_fixint = (_ptr) } }
733 #define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_array_fixint = (_ptr) } }
734 #define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_array_fixint = (_ptr) } }
735 #define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_array_fixint = (_ptr) } }
736 #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } }
737 #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
738 #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
739 #define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } }
740
741 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
742 #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
743 #define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
744 #define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
745 #define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
746 #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
747 #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
748 #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
749 #define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
750
751 #define side_arg_dynamic(_dynamic_arg_type) \
752 { \
753 .type = SIDE_TYPE_DYNAMIC, \
754 .u = { \
755 .dynamic = _dynamic_arg_type, \
756 }, \
757 }
758
759 /* Dynamic field arguments */
760
761 #define side_arg_dynamic_null(_attr) \
762 { \
763 .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \
764 .u = { \
765 .side_basic = { \
766 .attr = _attr, \
767 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
768 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
769 }, \
770 }, \
771 }
772
773 #define side_arg_dynamic_bool(_val, _attr) \
774 { \
775 .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \
776 .u = { \
777 .side_basic = { \
778 .attr = _attr, \
779 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
780 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
781 .u = { \
782 .side_bool = !!(_val), \
783 }, \
784 }, \
785 }, \
786 }
787
788 #define side_arg_dynamic_u8(_val, _attr) \
789 { \
790 .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \
791 .u = { \
792 .side_basic = { \
793 .attr = _attr, \
794 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
795 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
796 .u = { \
797 .side_u8 = (_val), \
798 }, \
799 }, \
800 }, \
801 }
802 #define side_arg_dynamic_s8(_val, _attr) \
803 { \
804 .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \
805 .u = { \
806 .side_basic = { \
807 .attr = _attr, \
808 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
809 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
810 .u = { \
811 .side_s8 = (_val), \
812 }, \
813 }, \
814 }, \
815 }
816 #define side_arg_dynamic_byte(_val, _attr) \
817 { \
818 .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \
819 .u = { \
820 .side_basic = { \
821 .attr = _attr, \
822 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
823 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
824 .u = { \
825 .side_byte = (_val), \
826 }, \
827 }, \
828 }, \
829 }
830 #define side_arg_dynamic_string(_val, _attr) \
831 { \
832 .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \
833 .u = { \
834 .side_basic = { \
835 .attr = _attr, \
836 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
837 .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
838 .u = { \
839 .string = (_val), \
840 }, \
841 }, \
842 }, \
843 }
844
845 #define _side_arg_dynamic_u16(_val, _byte_order, _attr) \
846 { \
847 .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \
848 .u = { \
849 .side_basic = { \
850 .attr = _attr, \
851 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
852 .byte_order = _byte_order, \
853 .u = { \
854 .side_u16 = (_val), \
855 }, \
856 }, \
857 }, \
858 }
859 #define _side_arg_dynamic_u32(_val, _byte_order, _attr) \
860 { \
861 .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \
862 .u = { \
863 .side_basic = { \
864 .attr = _attr, \
865 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
866 .byte_order = _byte_order, \
867 .u = { \
868 .side_u32 = (_val), \
869 }, \
870 }, \
871 }, \
872 }
873 #define _side_arg_dynamic_u64(_val, _byte_order, _attr) \
874 { \
875 .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \
876 .u = { \
877 .side_basic = { \
878 .attr = _attr, \
879 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
880 .byte_order = _byte_order, \
881 .u = { \
882 .side_u64 = (_val), \
883 }, \
884 }, \
885 }, \
886 }
887
888 #define _side_arg_dynamic_s16(_val, _byte_order, _attr) \
889 { \
890 .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \
891 .u = { \
892 .side_basic = { \
893 .attr = _attr, \
894 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
895 .byte_order = _byte_order, \
896 .u = { \
897 .side_s16 = (_val), \
898 }, \
899 }, \
900 }, \
901 }
902 #define _side_arg_dynamic_s32(_val, _byte_order, _attr) \
903 { \
904 .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \
905 .u = { \
906 .side_basic = { \
907 .attr = _attr, \
908 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
909 .byte_order = _byte_order, \
910 .u = { \
911 .side_s32 = (_val), \
912 }, \
913 }, \
914 }, \
915 }
916 #define _side_arg_dynamic_s64(_val, _byte_order, _attr) \
917 { \
918 .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \
919 .u = { \
920 .side_basic = { \
921 .attr = _attr, \
922 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
923 .byte_order = _byte_order, \
924 .u = { \
925 .side_s64 = (_val), \
926 }, \
927 }, \
928 }, \
929 }
930 #define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \
931 { \
932 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \
933 .u = { \
934 .side_basic = { \
935 .attr = _attr, \
936 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
937 .byte_order = _byte_order, \
938 .u = { \
939 .side_float_binary16 = (_val), \
940 }, \
941 }, \
942 }, \
943 }
944 #define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \
945 { \
946 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \
947 .u = { \
948 .side_basic = { \
949 .attr = _attr, \
950 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
951 .byte_order = _byte_order, \
952 .u = { \
953 .side_float_binary32 = (_val), \
954 }, \
955 }, \
956 }, \
957 }
958 #define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \
959 { \
960 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \
961 .u = { \
962 .side_basic = { \
963 .attr = _attr, \
964 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
965 .byte_order = _byte_order, \
966 .u = { \
967 .side_float_binary64 = (_val), \
968 }, \
969 }, \
970 }, \
971 }
972 #define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \
973 { \
974 .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \
975 .u = { \
976 .side_basic = { \
977 .attr = _attr, \
978 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
979 .byte_order = _byte_order, \
980 .u = { \
981 .side_float_binary128 = (_val), \
982 }, \
983 }, \
984 }, \
985 }
986
987 /* Host endian */
988 #define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
989 #define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
990 #define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
991 #define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
992 #define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
993 #define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr))
994 #define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
995 #define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
996 #define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
997 #define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr))
998
999 /* Little endian */
1000 #define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1001 #define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1002 #define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1003 #define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1004 #define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1005 #define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1006 #define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1007 #define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1008 #define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1009 #define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr))
1010
1011 /* Big endian */
1012 #define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1013 #define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1014 #define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1015 #define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1016 #define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1017 #define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1018 #define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1019 #define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1020 #define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1021 #define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr))
1022
1023 #define side_arg_dynamic_vla(_vla) \
1024 { \
1025 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \
1026 .u = { \
1027 .side_dynamic_vla = (_vla), \
1028 }, \
1029 }
1030
1031 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \
1032 { \
1033 .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \
1034 .u = { \
1035 .side_dynamic_vla_visitor = { \
1036 .app_ctx = _ctx, \
1037 .visitor = _dynamic_vla_visitor, \
1038 .attr = _attr, \
1039 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1040 }, \
1041 }, \
1042 }
1043
1044 #define side_arg_dynamic_struct(_struct) \
1045 { \
1046 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \
1047 .u = { \
1048 .side_dynamic_struct = (_struct), \
1049 }, \
1050 }
1051
1052 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \
1053 { \
1054 .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \
1055 .u = { \
1056 .side_dynamic_struct_visitor = { \
1057 .app_ctx = _ctx, \
1058 .visitor = _dynamic_struct_visitor, \
1059 .attr = _attr, \
1060 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1061 }, \
1062 }, \
1063 }
1064
1065 #define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \
1066 const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \
1067 const struct side_arg_dynamic_vec_vla _identifier = { \
1068 .sav = _identifier##_vec, \
1069 .attr = _attr, \
1070 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1071 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1072 }
1073
1074 #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \
1075 const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \
1076 const struct side_arg_dynamic_event_struct _identifier = { \
1077 .fields = _identifier##_fields, \
1078 .attr = _attr, \
1079 .len = SIDE_ARRAY_SIZE(_identifier##_fields), \
1080 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1081 }
1082
1083 #define side_arg_define_vec(_identifier, _sav) \
1084 const struct side_arg_vec _identifier##_vec[] = { _sav }; \
1085 const struct side_arg_vec_description _identifier = { \
1086 .sav = _identifier##_vec, \
1087 .len = SIDE_ARRAY_SIZE(_identifier##_vec), \
1088 }
1089
1090 #define side_arg_dynamic_field(_name, _elem) \
1091 { \
1092 .field_name = _name, \
1093 .elem = _elem, \
1094 }
1095
1096 #define side_arg_list(...) __VA_ARGS__
1097
1098 #define side_define_enum(_identifier, _mappings, _attr) \
1099 const struct side_enum_mappings _identifier = { \
1100 .mappings = _mappings, \
1101 .attr = _attr, \
1102 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1103 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1104 }
1105
1106 #define side_enum_mapping_list(...) \
1107 SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__)
1108
1109 #define side_enum_mapping_range(_label, _begin, _end) \
1110 { \
1111 .range_begin = _begin, \
1112 .range_end = _end, \
1113 .label = _label, \
1114 }
1115
1116 #define side_enum_mapping_value(_label, _value) \
1117 { \
1118 .range_begin = _value, \
1119 .range_end = _value, \
1120 .label = _label, \
1121 }
1122
1123 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
1124 const struct side_enum_bitmap_mappings _identifier = { \
1125 .mappings = _mappings, \
1126 .attr = _attr, \
1127 .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \
1128 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1129 }
1130
1131 #define side_enum_bitmap_mapping_list(...) \
1132 SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__)
1133
1134 #define side_enum_bitmap_mapping_range(_label, _begin, _end) \
1135 { \
1136 .range_begin = _begin, \
1137 .range_end = _end, \
1138 .label = _label, \
1139 }
1140
1141 #define side_enum_bitmap_mapping_value(_label, _value) \
1142 { \
1143 .range_begin = _value, \
1144 .range_end = _value, \
1145 .label = _label, \
1146 }
1147
1148 #define side_event_cond(_identifier) \
1149 if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \
1150 __ATOMIC_RELAXED)))
1151
1152 #define side_event_call(_identifier, _sav) \
1153 { \
1154 const struct side_arg_vec side_sav[] = { _sav }; \
1155 const struct side_arg_vec_description sav_desc = { \
1156 .sav = side_sav, \
1157 .len = SIDE_ARRAY_SIZE(side_sav), \
1158 }; \
1159 side_call(&(_identifier), &sav_desc); \
1160 }
1161
1162 #define side_event(_identifier, _sav) \
1163 side_event_cond(_identifier) \
1164 side_event_call(_identifier, SIDE_PARAM(_sav))
1165
1166 #define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \
1167 { \
1168 const struct side_arg_vec side_sav[] = { _sav }; \
1169 const struct side_arg_vec_description sav_desc = { \
1170 .sav = side_sav, \
1171 .len = SIDE_ARRAY_SIZE(side_sav), \
1172 }; \
1173 const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \
1174 const struct side_arg_dynamic_event_struct var_struct = { \
1175 .fields = side_fields, \
1176 .attr = _attr, \
1177 .len = SIDE_ARRAY_SIZE(side_fields), \
1178 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1179 }; \
1180 side_call_variadic(&(_identifier), &sav_desc, &var_struct); \
1181 }
1182
1183 #define side_event_variadic(_identifier, _sav, _var, _attr) \
1184 side_event_cond(_identifier) \
1185 side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr))
1186
1187 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \
1188 _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \
1189 _linkage struct side_event_description __attribute__((section("side_event_description"))) \
1190 _identifier = { \
1191 .version = 0, \
1192 .enabled = &(side_event_enable__##_identifier), \
1193 .loglevel = _loglevel, \
1194 .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
1195 .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
1196 .nr_callbacks = 0, \
1197 .flags = (_flags), \
1198 .provider_name = _provider, \
1199 .event_name = _event, \
1200 .fields = _fields, \
1201 .attr = _attr, \
1202 .callbacks = &side_empty_callback, \
1203 }; \
1204 static const struct side_event_description *side_event_ptr__##_identifier \
1205 __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
1206
1207 #define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1208 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1209 SIDE_PARAM(_attr), 0)
1210
1211 #define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1212 _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1213 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1214
1215 #define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1216 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1217 SIDE_PARAM(_attr), 0)
1218
1219 #define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1220 _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1221 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1222
1223 #define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1224 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1225 SIDE_PARAM(_attr), 0)
1226
1227 #define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \
1228 _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \
1229 SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC)
1230
1231 #define side_declare_event(_identifier) \
1232 extern uintptr_t side_event_enable_##_identifier; \
1233 extern struct side_event_description _identifier
1234
1235 extern const struct side_callback side_empty_callback;
1236
1237 void side_call(const struct side_event_description *desc,
1238 const struct side_arg_vec_description *sav_desc);
1239 void side_call_variadic(const struct side_event_description *desc,
1240 const struct side_arg_vec_description *sav_desc,
1241 const struct side_arg_dynamic_event_struct *var_struct);
1242
1243 int side_tracer_callback_register(struct side_event_description *desc,
1244 void (*call)(const struct side_event_description *desc,
1245 const struct side_arg_vec_description *sav_desc,
1246 void *priv),
1247 void *priv);
1248 int side_tracer_callback_variadic_register(struct side_event_description *desc,
1249 void (*call_variadic)(const struct side_event_description *desc,
1250 const struct side_arg_vec_description *sav_desc,
1251 const struct side_arg_dynamic_event_struct *var_struct,
1252 void *priv),
1253 void *priv);
1254 int side_tracer_callback_unregister(struct side_event_description *desc,
1255 void (*call)(const struct side_event_description *desc,
1256 const struct side_arg_vec_description *sav_desc,
1257 void *priv),
1258 void *priv);
1259 int side_tracer_callback_variadic_unregister(struct side_event_description *desc,
1260 void (*call_variadic)(const struct side_event_description *desc,
1261 const struct side_arg_vec_description *sav_desc,
1262 const struct side_arg_dynamic_event_struct *var_struct,
1263 void *priv),
1264 void *priv);
1265
1266 struct side_events_register_handle *side_events_register(struct side_event_description **events, uint32_t nr_events);
1267 void side_events_unregister(struct side_events_register_handle *handle);
1268
1269 enum side_tracer_notification {
1270 SIDE_TRACER_NOTIFICATION_INSERT_EVENTS,
1271 SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS,
1272 };
1273
1274 /* Callback is invoked with side library internal lock held. */
1275 struct side_tracer_handle *side_tracer_event_notification_register(
1276 void (*cb)(enum side_tracer_notification notif,
1277 struct side_event_description **events, uint32_t nr_events, void *priv),
1278 void *priv);
1279 void side_tracer_event_notification_unregister(struct side_tracer_handle *handle);
1280
1281 void side_init(void);
1282 void side_exit(void);
1283
1284 /*
1285 * These weak symbols, the constructor, and destructor take care of
1286 * registering only _one_ instance of the side instrumentation per
1287 * shared-ojbect (or for the whole main program).
1288 */
1289 extern struct side_event_description * __start_side_event_description_ptr[]
1290 __attribute__((weak, visibility("hidden")));
1291 extern struct side_event_description * __stop_side_event_description_ptr[]
1292 __attribute__((weak, visibility("hidden")));
1293 int side_event_description_ptr_registered
1294 __attribute__((weak, visibility("hidden")));
1295 struct side_events_register_handle *side_events_handle
1296 __attribute__((weak, visibility("hidden")));
1297
1298 static void
1299 side_event_description_ptr_init(void)
1300 __attribute__((no_instrument_function))
1301 __attribute__((constructor));
1302 static void
1303 side_event_description_ptr_init(void)
1304 {
1305 if (side_event_description_ptr_registered++)
1306 return;
1307 side_events_handle = side_events_register(__start_side_event_description_ptr,
1308 __stop_side_event_description_ptr - __start_side_event_description_ptr);
1309 }
1310
1311 static void
1312 side_event_description_ptr_exit(void)
1313 __attribute__((no_instrument_function))
1314 __attribute__((destructor));
1315 static void
1316 side_event_description_ptr_exit(void)
1317 {
1318 if (--side_event_description_ptr_registered)
1319 return;
1320 side_events_unregister(side_events_handle);
1321 side_events_handle = NULL;
1322 }
1323
1324 #endif /* _SIDE_TRACE_H */
This page took 0.073139 seconds and 5 git commands to generate.