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