X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fside%2Ftrace.h;h=d63a95e32717d9f1f71fc94476f0955cd889c31e;hb=3db2d8a1ed6d924d3a16d67330530c15eaa3073b;hp=b47bb96cd307a1df492f91ab6b1b8d45906903aa;hpb=d41cb7ee3441d81a044f40201d26c179e817d8da;p=libside.git diff --git a/include/side/trace.h b/include/side/trace.h index b47bb96..d63a95e 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -11,10 +11,61 @@ #include #include #include +#include #include #include -/* SIDE stands for "Static Instrumentation Dynamically Enabled" */ +/* + * SIDE stands for "Software Instrumentation Dynamically Enabled" + * + * This is an instrumentation API for Linux user-space, which exposes an + * instrumentation type system and facilities allowing a kernel or + * user-space tracer to consume user-space instrumentation. + * + * This instrumentation API exposes 3 type systems: + * + * * Stack-copy type system: This is the core type system which can + * represent all supported types and into which all other type systems + * can be nested. This type system requires that every type is + * statically or dynamically declared and then registered, thus giving + * tracers a complete description of the events and their associated + * fields before the associated instrumentation is invoked. The + * application needs to copy each argument (side_arg_...()) onto the + * stack when calling the instrumentation. + * + * This is the most expressive of the 3 type systems, althrough not the + * fastest due to the extra copy of the arguments. + * + * * Data-gathering type system: This type system requires every type to + * be statically or dynamically declared and registered, but does not + * require the application to copy its arguments onto the stack. + * Instead, the type description contains all the required information + * to fetch the data from the application memory. The only argument + * required from the instrumentation is the base pointer from which + * the data should be fetched. + * + * This type system can be used as an event field, or nested within + * the stack-copy type system. Nesting of gather-vla within + * gather-array and gather-vla types is not allowed. + * + * This type system is has the least overhead of the 3 type systems. + * + * * Dynamic type system: This type system receives both type + * description and actual data onto the stack at runtime. It has more + * overhead that the 2 other type systems, but does not require a + * prior registration of event field description. This makes it useful + * for seldom used types which are not performance critical, but for + * which registering each individual events would needlessly grow the + * number of events to declare and register. + * + * Another use-case for this type system is for use by dynamically + * typed language runtimes, where the field type is only known when + * the instrumentation is called. + * + * Those dynamic types can be either used as arguments to a variadic + * field list, or as on-stack instrumentation argument for a static + * type SIDE_TYPE_DYNAMIC place holder in the stack-copy type system. + */ //TODO: as those structures will be ABI, we need to either consider them //fixed forever, or think of a scheme that would allow their binary @@ -22,7 +73,7 @@ struct side_arg; struct side_arg_vec; -struct side_arg_dynamic; +union side_arg_dynamic; struct side_arg_dynamic_field; struct side_arg_dynamic_vla; struct side_type; @@ -32,9 +83,10 @@ struct side_tracer_dynamic_struct_visitor_ctx; struct side_event_description; struct side_arg_dynamic_struct; struct side_events_register_handle; +struct side_arg_variant; enum side_type_label { - /* Statically declared types */ + /* Stack-copy basic types */ SIDE_TYPE_NULL, SIDE_TYPE_BOOL, SIDE_TYPE_U8, @@ -46,76 +98,52 @@ enum side_type_label { SIDE_TYPE_S32, SIDE_TYPE_S64, SIDE_TYPE_BYTE, - SIDE_TYPE_POINTER32, - SIDE_TYPE_POINTER64, + SIDE_TYPE_POINTER, SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_BINARY128, - SIDE_TYPE_STRING, + SIDE_TYPE_STRING_UTF8, + SIDE_TYPE_STRING_UTF16, + SIDE_TYPE_STRING_UTF32, - /* Statically declared compound types */ + /* Stack-copy compound types */ SIDE_TYPE_STRUCT, + SIDE_TYPE_VARIANT, SIDE_TYPE_ARRAY, SIDE_TYPE_VLA, SIDE_TYPE_VLA_VISITOR, - SIDE_TYPE_ARRAY_U8, - SIDE_TYPE_ARRAY_U16, - SIDE_TYPE_ARRAY_U32, - SIDE_TYPE_ARRAY_U64, - SIDE_TYPE_ARRAY_S8, - SIDE_TYPE_ARRAY_S16, - SIDE_TYPE_ARRAY_S32, - SIDE_TYPE_ARRAY_S64, - SIDE_TYPE_ARRAY_BYTE, - SIDE_TYPE_ARRAY_POINTER32, - SIDE_TYPE_ARRAY_POINTER64, - - SIDE_TYPE_VLA_U8, - SIDE_TYPE_VLA_U16, - SIDE_TYPE_VLA_U32, - SIDE_TYPE_VLA_U64, - SIDE_TYPE_VLA_S8, - SIDE_TYPE_VLA_S16, - SIDE_TYPE_VLA_S32, - SIDE_TYPE_VLA_S64, - SIDE_TYPE_VLA_BYTE, - SIDE_TYPE_VLA_POINTER32, - SIDE_TYPE_VLA_POINTER64, - - /* Statically declared enumeration types */ + /* Stack-copy enumeration types */ SIDE_TYPE_ENUM, SIDE_TYPE_ENUM_BITMAP, + /* Stack-copy place holder for dynamic types */ SIDE_TYPE_DYNAMIC, - /* Gather types */ - SIDE_TYPE_GATHER_UNSIGNED_INT, - SIDE_TYPE_GATHER_SIGNED_INT, + /* Gather basic types */ + SIDE_TYPE_GATHER_BOOL, + SIDE_TYPE_GATHER_INTEGER, + SIDE_TYPE_GATHER_BYTE, + SIDE_TYPE_GATHER_POINTER, SIDE_TYPE_GATHER_FLOAT, + SIDE_TYPE_GATHER_STRING, + + /* Gather compound types */ SIDE_TYPE_GATHER_STRUCT, SIDE_TYPE_GATHER_ARRAY, SIDE_TYPE_GATHER_VLA, - /* Dynamic types */ + /* Gather enumeration types */ + SIDE_TYPE_GATHER_ENUM, + + /* Dynamic basic types */ SIDE_TYPE_DYNAMIC_NULL, SIDE_TYPE_DYNAMIC_BOOL, - SIDE_TYPE_DYNAMIC_U8, - SIDE_TYPE_DYNAMIC_U16, - SIDE_TYPE_DYNAMIC_U32, - SIDE_TYPE_DYNAMIC_U64, - SIDE_TYPE_DYNAMIC_S8, - SIDE_TYPE_DYNAMIC_S16, - SIDE_TYPE_DYNAMIC_S32, - SIDE_TYPE_DYNAMIC_S64, + SIDE_TYPE_DYNAMIC_INTEGER, SIDE_TYPE_DYNAMIC_BYTE, - SIDE_TYPE_DYNAMIC_POINTER32, - SIDE_TYPE_DYNAMIC_POINTER64, - SIDE_TYPE_DYNAMIC_FLOAT_BINARY16, - SIDE_TYPE_DYNAMIC_FLOAT_BINARY32, - SIDE_TYPE_DYNAMIC_FLOAT_BINARY64, - SIDE_TYPE_DYNAMIC_FLOAT_BINARY128, + SIDE_TYPE_DYNAMIC_POINTER, + SIDE_TYPE_DYNAMIC_FLOAT, SIDE_TYPE_DYNAMIC_STRING, /* Dynamic compound types */ @@ -136,8 +164,6 @@ enum side_attr_type { SIDE_ATTR_TYPE_S16, SIDE_ATTR_TYPE_S32, SIDE_ATTR_TYPE_S64, - SIDE_ATTR_TYPE_POINTER32, - SIDE_ATTR_TYPE_POINTER64, SIDE_ATTR_TYPE_FLOAT_BINARY16, SIDE_ATTR_TYPE_FLOAT_BINARY32, SIDE_ATTR_TYPE_FLOAT_BINARY64, @@ -187,6 +213,11 @@ enum side_type_label_byte_order { # define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE #endif +enum side_type_gather_access_mode { + SIDE_TYPE_GATHER_ACCESS_DIRECT, + SIDE_TYPE_GATHER_ACCESS_POINTER, /* Pointer dereference */ +}; + typedef enum side_visitor_status (*side_visitor_func)( const struct side_tracer_visitor_ctx *tracer_ctx, void *app_ctx); @@ -203,6 +234,14 @@ union side_integer_value { int16_t side_s16; int32_t side_s32; int64_t side_s64; + uintptr_t side_uptr; +} SIDE_PACKED; + +union side_bool_value { + uint8_t side_bool8; + uint16_t side_bool16; + uint32_t side_bool32; + uint64_t side_bool64; } SIDE_PACKED; union side_float_value { @@ -220,11 +259,17 @@ union side_float_value { #endif } SIDE_PACKED; +struct side_type_raw_string { + side_ptr_t(const void) p; /* pointer to string */ + uint8_t unit_size; /* 1, 2, or 4 bytes */ + uint8_t byte_order; /* enum side_type_label_byte_order */ +} SIDE_PACKED; + struct side_attr_value { uint32_t type; /* enum side_attr_type */ union { uint8_t bool_value; - uint64_t string_value; /* const char * */ + struct side_type_raw_string string_value; union side_integer_value integer_value; union side_float_value float_value; } SIDE_PACKED u; @@ -232,7 +277,7 @@ struct side_attr_value { /* User attributes. */ struct side_attr { - const char *key; + const struct side_type_raw_string key; const struct side_attr_value value; } SIDE_PACKED; @@ -245,6 +290,9 @@ struct side_type_null { struct side_type_bool { const struct side_attr *attr; uint32_t nr_attr; + uint16_t bool_size; /* bytes */ + uint16_t len_bits; /* bits. 0 for (bool_size * CHAR_BITS) */ + uint8_t byte_order; /* enum side_type_label_byte_order */ } SIDE_PACKED; struct side_type_byte { @@ -255,13 +303,15 @@ struct side_type_byte { struct side_type_string { const struct side_attr *attr; uint32_t nr_attr; + uint8_t unit_size; /* 1, 2, or 4 bytes */ + uint8_t byte_order; /* enum side_type_label_byte_order */ } SIDE_PACKED; struct side_type_integer { const struct side_attr *attr; uint32_t nr_attr; - uint16_t integer_size_bits; /* bits */ - uint16_t len_bits; /* bits */ + uint16_t integer_size; /* bytes */ + uint16_t len_bits; /* bits. 0 for (integer_size * CHAR_BITS) */ uint8_t signedness; /* true/false */ uint8_t byte_order; /* enum side_type_label_byte_order */ } SIDE_PACKED; @@ -269,14 +319,14 @@ struct side_type_integer { struct side_type_float { const struct side_attr *attr; uint32_t nr_attr; - uint16_t float_size_bits; /* bits */ + uint16_t float_size; /* bytes */ uint8_t byte_order; /* enum side_type_label_byte_order */ } SIDE_PACKED; struct side_enum_mapping { int64_t range_begin; int64_t range_end; - const char *label; + struct side_type_raw_string label; } SIDE_PACKED; struct side_enum_mappings { @@ -289,7 +339,7 @@ struct side_enum_mappings { struct side_enum_bitmap_mapping { uint64_t range_begin; uint64_t range_end; - const char *label; + struct side_type_raw_string label; } SIDE_PACKED; struct side_enum_bitmap_mappings { @@ -336,6 +386,19 @@ struct side_type_enum_bitmap { const struct side_type *elem_type; } SIDE_PACKED; +struct side_type_gather_bool { + uint64_t offset; /* bytes */ + uint8_t access_mode; /* enum side_type_gather_access_mode */ + struct side_type_bool type; + uint16_t offset_bits; /* bits */ +} SIDE_PACKED; + +struct side_type_gather_byte { + uint64_t offset; /* bytes */ + uint8_t access_mode; /* enum side_type_gather_access_mode */ + struct side_type_byte type; +} SIDE_PACKED; + struct side_type_gather_integer { uint64_t offset; /* bytes */ uint8_t access_mode; /* enum side_type_gather_access_mode */ @@ -349,6 +412,17 @@ struct side_type_gather_float { struct side_type_float type; } SIDE_PACKED; +struct side_type_gather_string { + uint64_t offset; /* bytes */ + uint8_t access_mode; /* enum side_type_gather_access_mode */ + struct side_type_string type; +} SIDE_PACKED; + +struct side_type_gather_enum { + const struct side_enum_mappings *mappings; + const struct side_type *elem_type; +} SIDE_PACKED; + struct side_type_gather_struct { uint64_t offset; /* bytes */ uint8_t access_mode; /* enum side_type_gather_access_mode */ @@ -370,26 +444,24 @@ struct side_type_gather_vla { struct side_type_vla type; } SIDE_PACKED; -enum side_type_gather_access_mode { - SIDE_TYPE_GATHER_ACCESS_ADDRESS, - SIDE_TYPE_GATHER_ACCESS_POINTER, -}; - struct side_type_gather { union { + struct side_type_gather_bool side_bool; + struct side_type_gather_byte side_byte; struct side_type_gather_integer side_integer; struct side_type_gather_float side_float; + struct side_type_gather_string side_string; + struct side_type_gather_enum side_enum; struct side_type_gather_array side_array; struct side_type_gather_vla side_vla; struct side_type_gather_struct side_struct; } SIDE_PACKED u; } SIDE_PACKED; -/* Statically defined types. */ struct side_type { uint32_t type; /* enum side_type_label */ union { - /* Basic types */ + /* Stack-copy basic types */ struct side_type_null side_null; struct side_type_bool side_bool; struct side_type_byte side_byte; @@ -397,13 +469,14 @@ struct side_type { struct side_type_integer side_integer; struct side_type_float side_float; - /* Compound types */ + /* Stack-copy compound types */ struct side_type_array side_array; struct side_type_vla side_vla; struct side_type_vla_visitor side_vla_visitor; const struct side_type_struct *side_struct; + const struct side_type_variant *side_variant; - /* Enumeration types */ + /* Stack-copy enumeration types */ struct side_type_enum side_enum; struct side_type_enum_bitmap side_enum_bitmap; @@ -412,6 +485,20 @@ struct side_type { } SIDE_PACKED u; } SIDE_PACKED; +struct side_variant_option { + int64_t range_begin; + int64_t range_end; + const struct side_type side_type; +} SIDE_PACKED; + +struct side_type_variant { + const struct side_type selector; + const struct side_variant_option *options; + const struct side_attr *attr; + uint32_t nr_options; + uint32_t nr_attr; +} SIDE_PACKED; + struct side_event_field { const char *field_name; struct side_type side_type; @@ -434,33 +521,34 @@ struct side_callback { void *priv; } SIDE_PACKED; -struct side_arg_static { - /* Basic types */ - uint8_t bool_value; +union side_arg_static { + /* Stack-copy basic types */ + union side_bool_value bool_value; uint8_t byte_value; - uint64_t string_value; /* const char * */ + uint64_t string_value; /* const {uint8_t, uint16_t, uint32_t} * */ union side_integer_value integer_value; union side_float_value float_value; - /* Compound types */ + /* Stack-copy compound types */ const struct side_arg_vec *side_struct; + const struct side_arg_variant *side_variant; const struct side_arg_vec *side_array; const struct side_arg_vec *side_vla; void *side_vla_app_visitor_ctx; - void *side_array_fixint; - struct { - void *p; - uint32_t length; - } SIDE_PACKED side_vla_fixint; - - /* Gather types */ - void *side_integer_gather_ptr; - void *side_float_gather_ptr; - void *side_array_gather_ptr; - void *side_struct_gather_ptr; + + /* Gather basic types */ + const void *side_bool_gather_ptr; + const void *side_byte_gather_ptr; + const void *side_integer_gather_ptr; + const void *side_float_gather_ptr; + const void *side_string_gather_ptr; + + /* Gather compound types */ + const void *side_array_gather_ptr; + const void *side_struct_gather_ptr; struct { - void *ptr; - void *length_ptr; + const void *ptr; + const void *length_ptr; } SIDE_PACKED side_vla_gather; } SIDE_PACKED; @@ -492,36 +580,31 @@ struct side_dynamic_vla_visitor { uint32_t nr_attr; } SIDE_PACKED; -struct side_arg_dynamic { - /* Basic types */ +union side_arg_dynamic { + /* Dynamic basic types */ struct side_type_null side_null; struct { struct side_type_bool type; - uint8_t value; + union side_bool_value value; } SIDE_PACKED side_bool; - struct { struct side_type_byte type; uint8_t value; } SIDE_PACKED side_byte; - struct { struct side_type_string type; uint64_t value; /* const char * */ } SIDE_PACKED side_string; - - /* Integer type */ struct { struct side_type_integer type; union side_integer_value value; } SIDE_PACKED side_integer; - struct { struct side_type_float type; union side_float_value value; } SIDE_PACKED side_float; - /* Compound types */ + /* Dynamic compound types */ const struct side_arg_dynamic_struct *side_dynamic_struct; const struct side_arg_dynamic_vla *side_dynamic_vla; @@ -530,13 +613,18 @@ struct side_arg_dynamic { } SIDE_PACKED; struct side_arg { - enum side_type_label type; + uint32_t type; /* enum side_type_label */ union { - struct side_arg_static side_static; - struct side_arg_dynamic side_dynamic; + union side_arg_static side_static; + union side_arg_dynamic side_dynamic; } SIDE_PACKED u; } SIDE_PACKED; +struct side_arg_variant { + struct side_arg selector; + struct side_arg option; +} SIDE_PACKED; + struct side_arg_vec { const struct side_arg *sav; uint32_t len; @@ -562,42 +650,40 @@ struct side_tracer_dynamic_struct_visitor_ctx { void *priv; /* Private tracer context. */ } SIDE_PACKED; +/* + * This structure is _not_ packed to allow atomic operations on its + * fields. + */ +struct side_event_state { + uintptr_t enabled; + const struct side_callback *callbacks; + uint32_t nr_callbacks; +}; + struct side_event_description { - uintptr_t *enabled; + struct side_event_state *state; const char *provider_name; const char *event_name; const struct side_event_field *fields; const struct side_attr *attr; - const struct side_callback *callbacks; uint64_t flags; uint32_t version; uint32_t loglevel; /* enum side_loglevel */ uint32_t nr_fields; uint32_t nr_attr; - uint32_t nr_callbacks; } SIDE_PACKED; /* Event and type attributes */ -#if SIDE_BITS_PER_LONG == 64 -# define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER64 -# define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER64 -# define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER64 -# define SIDE_TYPE_DYNAMIC_POINTER_HOST SIDE_TYPE_DYNAMIC_POINTER64 -# define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER64 -# define SIDE_PTR_HOST .side_u64 -#else -# define SIDE_TYPE_POINTER_HOST SIDE_TYPE_POINTER32 -# define SIDE_TYPE_ARRAY_POINTER_HOST SIDE_TYPE_ARRAY_POINTER32 -# define SIDE_TYPE_VLA_POINTER_HOST SIDE_TYPE_VLA_POINTER32 -# define SIDE_TYPE_DYNAMIC_POINTER_HOST SIDE_TYPE_DYNAMIC_POINTER32 -# define SIDE_ATTR_TYPE_POINTER_HOST SIDE_ATTR_TYPE_POINTER32 -# define SIDE_PTR_HOST .side_u32 -#endif - #define side_attr(_key, _value) \ { \ - .key = _key, \ + .key = { \ + .p = { \ + .v = (uintptr_t) (_key), \ + }, \ + .unit_size = sizeof(uint8_t), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + }, \ .value = SIDE_PARAM(_value), \ } @@ -614,55 +700,152 @@ struct side_event_description { #define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } } #define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } } #define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } } -#define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER_HOST, .u = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } } #define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } } #define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } } #define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } } #define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } } -#define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string_value = (uintptr_t) (_val) } } -/* Static field definition */ +#define _side_attr_string(_val, _byte_order, _unit_size) \ + { \ + .type = SIDE_ATTR_TYPE_STRING, \ + .u = { \ + .string_value = { \ + .p = { \ + .v = (uintptr_t) (_val), \ + }, \ + .unit_size = _unit_size, \ + .byte_order = _byte_order, \ + }, \ + }, \ + } + +#define side_attr_string(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t)) +#define side_attr_string16(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t)) +#define side_attr_string32(_val) _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t)) + +/* Stack-copy enumeration type definitions */ -#define side_type_null(_attr) \ +#define side_define_enum(_identifier, _mappings, _attr...) \ + const struct side_enum_mappings _identifier = { \ + .mappings = _mappings, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + } + +#define side_enum_mapping_list(...) \ + SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__) + +#define side_enum_mapping_range(_label, _begin, _end) \ + { \ + .range_begin = _begin, \ + .range_end = _end, \ + .label = { \ + .p = { \ + .v = (uintptr_t) (_label), \ + }, \ + .unit_size = sizeof(uint8_t), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + }, \ + } + +#define side_enum_mapping_value(_label, _value) \ + { \ + .range_begin = _value, \ + .range_end = _value, \ + .label = { \ + .p = { \ + .v = (uintptr_t) (_label), \ + }, \ + .unit_size = sizeof(uint8_t), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + }, \ + } + +#define side_define_enum_bitmap(_identifier, _mappings, _attr...) \ + const struct side_enum_bitmap_mappings _identifier = { \ + .mappings = _mappings, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + } + +#define side_enum_bitmap_mapping_list(...) \ + SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__) + +#define side_enum_bitmap_mapping_range(_label, _begin, _end) \ + { \ + .range_begin = _begin, \ + .range_end = _end, \ + .label = { \ + .p = { \ + .v = (uintptr_t) (_label), \ + }, \ + .unit_size = sizeof(uint8_t), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + }, \ + } + +#define side_enum_bitmap_mapping_value(_label, _value) \ + { \ + .range_begin = _value, \ + .range_end = _value, \ + .label = { \ + .p = { \ + .v = (uintptr_t) (_label), \ + }, \ + .unit_size = sizeof(uint8_t), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + }, \ + } + +/* Stack-copy field and type definitions */ + +#define side_type_null(_attr...) \ { \ .type = SIDE_TYPE_NULL, \ .u = { \ .side_null = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ }, \ } -#define side_type_bool(_attr) \ +#define side_type_bool(_attr...) \ { \ .type = SIDE_TYPE_BOOL, \ .u = { \ .side_bool = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .bool_size = sizeof(uint8_t), \ + .len_bits = 0, \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ }, \ }, \ } -#define side_type_byte(_attr) \ +#define side_type_byte(_attr...) \ { \ .type = SIDE_TYPE_BYTE, \ .u = { \ .side_byte = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ }, \ } -#define side_type_string(_attr) \ +#define _side_type_string(_type, _byte_order, _unit_size, _attr) \ { \ - .type = SIDE_TYPE_STRING, \ + .type = _type, \ .u = { \ .side_string = { \ .attr = _attr, \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .unit_size = _unit_size, \ + .byte_order = _byte_order, \ }, \ }, \ } @@ -672,14 +855,14 @@ struct side_event_description { .type = SIDE_TYPE_DYNAMIC, \ } -#define _side_type_integer(_type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \ +#define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \ { \ .type = _type, \ .u = { \ .side_integer = { \ .attr = _attr, \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - .integer_size_bits = _integer_size_bits, \ + .integer_size = _integer_size, \ .len_bits = _len_bits, \ .signedness = _signedness, \ .byte_order = _byte_order, \ @@ -687,14 +870,14 @@ struct side_event_description { }, \ } -#define _side_type_float(_type, _byte_order, _float_size_bits, _attr) \ +#define _side_type_float(_type, _byte_order, _float_size, _attr) \ { \ .type = _type, \ .u = { \ .side_float = { \ .attr = _attr, \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - .float_size_bits = _float_size_bits, \ + .float_size = _float_size, \ .byte_order = _byte_order, \ }, \ }, \ @@ -706,92 +889,112 @@ struct side_event_description { .side_type = _type, \ } +#define side_option_range(_range_begin, _range_end, _type) \ + { \ + .range_begin = _range_begin, \ + .range_end = _range_end, \ + .side_type = _type, \ + } + +#define side_option(_value, _type) \ + side_option_range(_value, _value, SIDE_PARAM(_type)) + /* Host endian */ -#define side_type_u8(_attr) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr)) -#define side_type_u16(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr)) -#define side_type_u32(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr)) -#define side_type_u64(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr)) -#define side_type_s8(_attr) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr)) -#define side_type_s16(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, 16, 16, SIDE_PARAM(_attr)) -#define side_type_s32(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, 32, 32, SIDE_PARAM(_attr)) -#define side_type_s64(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, 64, 64, SIDE_PARAM(_attr)) -#define side_type_pointer(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_BITS_PER_LONG, \ - SIDE_BITS_PER_LONG, SIDE_PARAM(_attr)) -#define side_type_float_binary16(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 16, SIDE_PARAM(_attr)) -#define side_type_float_binary32(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 32, SIDE_PARAM(_attr)) -#define side_type_float_binary64(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 64, SIDE_PARAM(_attr)) -#define side_type_float_binary128(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, 128, SIDE_PARAM(_attr)) - -#define side_field_null(_name, _attr) _side_field(_name, side_type_null(SIDE_PARAM(_attr))) -#define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr))) -#define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr))) -#define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr))) -#define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr))) -#define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr))) -#define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr))) -#define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr))) -#define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr))) -#define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr))) -#define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr))) -#define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr))) -#define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr))) -#define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr))) -#define side_field_float_binary64(_name, _attr) _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr))) -#define side_field_float_binary128(_name, _attr) _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr))) -#define side_field_string(_name, _attr) _side_field(_name, side_type_string(SIDE_PARAM(_attr))) +#define side_type_u8(_attr...) _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_u16(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_u32(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_u64(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s8(_attr...) _side_type_integer(SIDE_TYPE_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s16(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s32(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s64(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_pointer(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary16(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary32(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary64(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary128(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_string(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF8, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_string16(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_string32(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_field_null(_name, _attr...) _side_field(_name, side_type_null(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_bool(_name, _attr...) _side_field(_name, side_type_bool(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_u8(_name, _attr...) _side_field(_name, side_type_u8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_u16(_name, _attr...) _side_field(_name, side_type_u16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_u32(_name, _attr...) _side_field(_name, side_type_u32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_u64(_name, _attr...) _side_field(_name, side_type_u64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s8(_name, _attr...) _side_field(_name, side_type_s8(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s16(_name, _attr...) _side_field(_name, side_type_s16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s32(_name, _attr...) _side_field(_name, side_type_s32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s64(_name, _attr...) _side_field(_name, side_type_s64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_byte(_name, _attr...) _side_field(_name, side_type_byte(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_pointer(_name, _attr...) _side_field(_name, side_type_pointer(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary16(_name, _attr...) _side_field(_name, side_type_float_binary16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary32(_name, _attr...) _side_field(_name, side_type_float_binary32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary64(_name, _attr...) _side_field(_name, side_type_float_binary64(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary128(_name, _attr...) _side_field(_name, side_type_float_binary128(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_string(_name, _attr...) _side_field(_name, side_type_string(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_string16(_name, _attr...) _side_field(_name, side_type_string16(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_string32(_name, _attr...) _side_field(_name, side_type_string32(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) #define side_field_dynamic(_name) _side_field(_name, side_type_dynamic()) /* Little endian */ -#define side_type_u16_le(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr)) -#define side_type_u32_le(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr)) -#define side_type_u64_le(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr)) -#define side_type_s16_le(_attr) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, 16, 16, SIDE_PARAM(_attr)) -#define side_type_s32_le(_attr) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, 32, 32, SIDE_PARAM(_attr)) -#define side_type_s64_le(_attr) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, 64, 64, SIDE_PARAM(_attr)) -#define side_type_pointer_le(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_LE, SIDE_BITS_PER_LONG, \ - SIDE_BITS_PER_LONG, SIDE_PARAM(_attr)) -#define side_type_float_binary16_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, 16, SIDE_PARAM(_attr)) -#define side_type_float_binary32_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, 32, SIDE_PARAM(_attr)) -#define side_type_float_binary64_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, 64, SIDE_PARAM(_attr)) -#define side_type_float_binary128_le(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 128, SIDE_PARAM(_attr)) - -#define side_field_u16_le(_name, _attr) _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr))) -#define side_field_u32_le(_name, _attr) _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr))) -#define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr))) -#define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr))) -#define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr))) -#define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr))) -#define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr))) -#define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr))) -#define side_field_float_binary32_le(_name, _attr) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr))) -#define side_field_float_binary64_le(_name, _attr) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr))) -#define side_field_float_binary128_le(_name, _attr) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr))) +#define side_type_u16_le(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_u32_le(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_u64_le(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s16_le(_attr...) _side_type_integer(SIDE_TYPE_S16, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s32_le(_attr...) _side_type_integer(SIDE_TYPE_S32, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s64_le(_attr...) _side_type_integer(SIDE_TYPE_S64, true, SIDE_TYPE_BYTE_ORDER_LE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_pointer_le(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary16_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary32_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary64_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary128_le(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_string16_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_string32_le(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_field_u16_le(_name, _attr...) _side_field(_name, side_type_u16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_u32_le(_name, _attr...) _side_field(_name, side_type_u32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_u64_le(_name, _attr...) _side_field(_name, side_type_u64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s16_le(_name, _attr...) _side_field(_name, side_type_s16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s32_le(_name, _attr...) _side_field(_name, side_type_s32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s64_le(_name, _attr...) _side_field(_name, side_type_s64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_pointer_le(_name, _attr...) _side_field(_name, side_type_pointer_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary16_le(_name, _attr...) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary32_le(_name, _attr...) _side_field(_name, side_type_float_binary32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary64_le(_name, _attr...) _side_field(_name, side_type_float_binary64_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary128_le(_name, _attr...) _side_field(_name, side_type_float_binary128_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_string16_le(_name, _attr...) _side_field(_name, side_type_string16_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_string32_le(_name, _attr...) _side_field(_name, side_type_string32_le(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) /* Big endian */ -#define side_type_u16_be(_attr) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr)) -#define side_type_u32_be(_attr) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr)) -#define side_type_u64_be(_attr) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr)) -#define side_type_s16_be(_attr) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, 16, 16, SIDE_PARAM(_attr)) -#define side_type_s32_be(_attr) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, 32, 32, SIDE_PARAM(_attr)) -#define side_type_s64_be(_attr) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, 64, 64, SIDE_PARAM(_attr)) -#define side_type_pointer_be(_attr) _side_type_integer(SIDE_TYPE_POINTER_HOST, false, SIDE_TYPE_BYTE_ORDER_BE, SIDE_BITS_PER_LONG, \ - SIDE_BITS_PER_LONG, SIDE_PARAM(_attr)) -#define side_type_float_binary16_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, 16, SIDE_PARAM(_attr)) -#define side_type_float_binary32_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, 32, SIDE_PARAM(_attr)) -#define side_type_float_binary64_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, 64, SIDE_PARAM(_attr)) -#define side_type_float_binary128_be(_attr) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, 128, SIDE_PARAM(_attr)) - -#define side_field_u16_be(_name, _attr) _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr))) -#define side_field_u32_be(_name, _attr) _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr))) -#define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr))) -#define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr))) -#define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr))) -#define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr))) -#define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr))) -#define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr))) -#define side_field_float_binary32_be(_name, _attr) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr))) -#define side_field_float_binary64_be(_name, _attr) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr))) -#define side_field_float_binary128_be(_name, _attr) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr))) +#define side_type_u16_be(_attr...) _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_u32_be(_attr...) _side_type_integer(SIDE_TYPE_U32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_u64_be(_attr...) _side_type_integer(SIDE_TYPE_U64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s16_be(_attr...) _side_type_integer(SIDE_TYPE_S16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s32_be(_attr...) _side_type_integer(SIDE_TYPE_S32, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_s64_be(_attr...) _side_type_integer(SIDE_TYPE_S64, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_pointer_be(_attr...) _side_type_integer(SIDE_TYPE_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary16_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary32_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary64_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_float_binary128_be(_attr...) _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_string16_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_string32_be(_attr...) _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_field_u16_be(_name, _attr...) _side_field(_name, side_type_u16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_u32_be(_name, _attr...) _side_field(_name, side_type_u32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_u64_be(_name, _attr...) _side_field(_name, side_type_u64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s16_be(_name, _attr...) _side_field(_name, side_type_s16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s32_be(_name, _attr...) _side_field(_name, side_type_s32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_s64_be(_name, _attr...) _side_field(_name, side_type_s64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_pointer_be(_name, _attr...) _side_field(_name, side_type_pointer_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary16_be(_name, _attr...) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary32_be(_name, _attr...) _side_field(_name, side_type_float_binary32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary64_be(_name, _attr...) _side_field(_name, side_type_float_binary64_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_float_binary128_be(_name, _attr...) _side_field(_name, side_type_float_binary128_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_string16_be(_name, _attr...) _side_field(_name, side_type_string16_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_string32_be(_name, _attr...) _side_field(_name, side_type_string32_be(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) #define side_type_enum(_mappings, _elem_type) \ { \ @@ -837,61 +1040,145 @@ struct side_event_description { .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ } -#define side_define_struct(_identifier, _fields, _attr) \ - const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)) +#define side_define_struct(_identifier, _fields, _attr...) \ + const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) -#define side_struct_literal(_fields, _attr) \ +#define side_struct_literal(_fields, _attr...) \ SIDE_COMPOUND_LITERAL(const struct side_type_struct, \ - _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))) + _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_type_variant(_variant) \ + { \ + .type = SIDE_TYPE_VARIANT, \ + .u = { \ + .side_variant = _variant, \ + }, \ + } +#define side_field_variant(_name, _variant) \ + _side_field(_name, side_type_variant(SIDE_PARAM(_variant))) -#define side_type_array(_elem_type, _length, _attr) \ +#define _side_type_variant_define(_selector, _options, _attr) \ + { \ + .selector = _selector, \ + .options = _options, \ + .attr = _attr, \ + .nr_options = SIDE_ARRAY_SIZE(SIDE_PARAM(_options)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + } + +#define side_define_variant(_identifier, _selector, _options, _attr...) \ + const struct side_type_variant _identifier = \ + _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_variant_literal(_selector, _options, _attr...) \ + SIDE_COMPOUND_LITERAL(const struct side_type_variant, \ + _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_type_array(_elem_type, _length, _attr...) \ { \ .type = SIDE_TYPE_ARRAY, \ .u = { \ .side_array = { \ .elem_type = _elem_type, \ - .attr = _attr, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ .length = _length, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ }, \ } -#define side_field_array(_name, _elem_type, _length, _attr) \ - _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr))) +#define side_field_array(_name, _elem_type, _length, _attr...) \ + _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) -#define side_type_vla(_elem_type, _attr) \ +#define side_type_vla(_elem_type, _attr...) \ { \ .type = SIDE_TYPE_VLA, \ .u = { \ .side_vla = { \ .elem_type = _elem_type, \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ }, \ } -#define side_field_vla(_name, _elem_type, _attr) \ - _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr))) +#define side_field_vla(_name, _elem_type, _attr...) \ + _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) -#define side_type_vla_visitor(_elem_type, _visitor, _attr) \ +#define side_type_vla_visitor(_elem_type, _visitor, _attr...) \ { \ .type = SIDE_TYPE_VLA_VISITOR, \ .u = { \ .side_vla_visitor = { \ .elem_type = SIDE_PARAM(_elem_type), \ .visitor = _visitor, \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + }, \ + }, \ + } +#define side_field_vla_visitor(_name, _elem_type, _visitor, _attr...) \ + _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +/* Gather field and type definitions */ + +#define side_type_gather_byte(_offset, _access_mode, _attr...) \ + { \ + .type = SIDE_TYPE_GATHER_BYTE, \ + .u = { \ + .side_gather = { \ + .u = { \ + .side_byte = { \ + .offset = _offset, \ + .access_mode = _access_mode, \ + .type = { \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + }, \ + }, \ + }, \ }, \ }, \ } -#define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \ - _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr))) +#define side_field_gather_byte(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_byte(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) -/* Gather fields */ +#define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + { \ + .type = SIDE_TYPE_GATHER_BOOL, \ + .u = { \ + .side_gather = { \ + .u = { \ + .side_bool = { \ + .offset = _offset, \ + .access_mode = _access_mode, \ + .type = { \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .bool_size = _bool_size, \ + .len_bits = _len_bits, \ + .byte_order = _byte_order, \ + }, \ + .offset_bits = _offset_bits, \ + }, \ + }, \ + }, \ + }, \ + } +#define side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_HOST, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_LE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_bool(SIDE_TYPE_BYTE_ORDER_BE, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_field_gather_bool(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_bool(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) +#define side_field_gather_bool_le(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_bool_le(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) +#define side_field_gather_bool_be(_name, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_bool_be(_offset, _bool_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))) #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \ - _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ + _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ { \ .type = _type, \ .u = { \ @@ -901,9 +1188,9 @@ struct side_event_description { .offset = _offset, \ .access_mode = _access_mode, \ .type = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - .integer_size_bits = _integer_size_bits, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .integer_size = _integer_size, \ .len_bits = _len_bits, \ .signedness = _signedness, \ .byte_order = _byte_order, \ @@ -915,43 +1202,61 @@ struct side_event_description { }, \ } -#define side_type_gather_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_HOST, \ - _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)) -#define side_type_gather_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_HOST, \ - _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)) - -#define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_LE, \ - _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)) -#define side_type_gather_signed_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_LE, \ - _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)) - -#define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_type_gather_integer(SIDE_TYPE_GATHER_UNSIGNED_INT, false, SIDE_TYPE_BYTE_ORDER_BE, \ - _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)) -#define side_type_gather_signed_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_type_gather_integer(SIDE_TYPE_GATHER_SIGNED_INT, true, SIDE_TYPE_BYTE_ORDER_BE, \ - _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr)) - -#define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))) -#define side_field_gather_signed_integer(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))) - -#define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))) -#define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))) - -#define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))) -#define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size_bits, _offset_bits, _len_bits, _access_mode, SIDE_PARAM(_attr))) - -#define _side_type_gather_float(_byte_order, _offset, _float_size_bits, _access_mode, _attr) \ +#define side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, \ + _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, \ + _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_LE, \ + _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_LE, \ + _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, false, SIDE_TYPE_BYTE_ORDER_BE, \ + _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_INTEGER, true, SIDE_TYPE_BYTE_ORDER_BE, \ + _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_field_gather_unsigned_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_unsigned_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_signed_integer(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_signed_integer(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_field_gather_unsigned_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_unsigned_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_signed_integer_le(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_signed_integer_le(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_field_gather_unsigned_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_unsigned_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_signed_integer_be(_name, _integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_signed_integer_be(_integer_offset, _integer_size, _offset_bits, _len_bits, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_type_gather_pointer(_offset, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_HOST, \ + _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_field_gather_pointer(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_pointer(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_type_gather_pointer_le(_offset, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_LE, \ + _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_field_gather_pointer_le(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_pointer_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_type_gather_pointer_be(_offset, _access_mode, _attr...) \ + _side_type_gather_integer(SIDE_TYPE_GATHER_POINTER, false, SIDE_TYPE_BYTE_ORDER_BE, \ + _offset, sizeof(uintptr_t), 0, 0, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_field_gather_pointer_be(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_pointer_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr...) \ { \ .type = SIDE_TYPE_GATHER_FLOAT, \ .u = { \ @@ -961,9 +1266,9 @@ struct side_event_description { .offset = _offset, \ .access_mode = _access_mode, \ .type = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - .float_size_bits = _float_size_bits, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .float_size = _float_size, \ .byte_order = _byte_order, \ }, \ }, \ @@ -972,19 +1277,85 @@ struct side_event_description { }, \ } -#define side_type_gather_float(_offset, _float_size_bits, _access_mode, _attr) \ - _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size_bits, _access_mode, _attr) -#define side_type_gather_float_le(_offset, _float_size_bits, _access_mode, _attr) \ - _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size_bits, _access_mode, _attr) -#define side_type_gather_float_be(_offset, _float_size_bits, _access_mode, _attr) \ - _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size_bits, _access_mode, _attr) - -#define side_field_gather_float(_name, _offset, _float_size_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_float(_offset, _float_size_bits, _access_mode, _attr)) -#define side_field_gather_float_le(_name, _offset, _float_size_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_float_le(_offset, _float_size_bits, _access_mode, _attr)) -#define side_field_gather_float_be(_name, _offset, _float_size_bits, _access_mode, _attr) \ - _side_field(_name, side_type_gather_float_be(_offset, _float_size_bits, _access_mode, _attr)) +#define side_type_gather_float(_offset, _float_size, _access_mode, _attr...) \ + _side_type_gather_float(SIDE_TYPE_FLOAT_WORD_ORDER_HOST, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_float_le(_offset, _float_size, _access_mode, _attr...) \ + _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_LE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_float_be(_offset, _float_size, _access_mode, _attr...) \ + _side_type_gather_float(SIDE_TYPE_BYTE_ORDER_BE, _offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_field_gather_float(_name, _offset, _float_size, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_float(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_float_le(_name, _offset, _float_size, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_float_le(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr...) \ + { \ + .type = SIDE_TYPE_GATHER_STRING, \ + .u = { \ + .side_gather = { \ + .u = { \ + .side_string = { \ + .offset = _offset, \ + .access_mode = _access_mode, \ + .type = { \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .unit_size = _unit_size, \ + .byte_order = _byte_order, \ + }, \ + }, \ + }, \ + }, \ + }, \ + } +#define side_type_gather_string(_offset, _access_mode, _attr...) \ + _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_field_gather_string(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_string(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_type_gather_string16(_offset, _access_mode, _attr...) \ + _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_string16_le(_offset, _access_mode, _attr...) \ + _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_string16_be(_offset, _access_mode, _attr...) \ + _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_field_gather_string16(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_string16(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_string16_le(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_string16_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_string16_be(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_string16_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_type_gather_string32(_offset, _access_mode, _attr...) \ + _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_string32_le(_offset, _access_mode, _attr...) \ + _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_type_gather_string32_be(_offset, _access_mode, _attr...) \ + _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define side_field_gather_string32(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_string32(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_string32_le(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_string32_le(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) +#define side_field_gather_string32_be(_name, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_string32_be(_offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) + +#define side_type_gather_enum(_mappings, _elem_type) \ + { \ + .type = SIDE_TYPE_GATHER_ENUM, \ + .u = { \ + .side_enum = { \ + .mappings = _mappings, \ + .elem_type = _elem_type, \ + }, \ + }, \ + } +#define side_field_gather_enum(_name, _mappings, _elem_type) \ + _side_field(_name, side_type_gather_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \ { \ @@ -1005,7 +1376,7 @@ struct side_event_description { #define side_field_gather_struct(_name, _struct_gather, _offset, _size, _access_mode) \ _side_field(_name, side_type_gather_struct(SIDE_PARAM(_struct_gather), _offset, _size, _access_mode)) -#define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr) \ +#define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr...) \ { \ .type = SIDE_TYPE_GATHER_ARRAY, \ .u = { \ @@ -1016,40 +1387,40 @@ struct side_event_description { .access_mode = _access_mode, \ .type = { \ .elem_type = _elem_type_gather, \ - .attr = _attr, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ .length = _length, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ }, \ }, \ }, \ }, \ } -#define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr) \ - _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM(_attr))) +#define side_field_gather_array(_name, _elem_type, _length, _offset, _access_mode, _attr...) \ + _side_field(_name, side_type_gather_array(SIDE_PARAM(_elem_type), _length, _offset, _access_mode, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) -#define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \ +#define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \ { \ .type = SIDE_TYPE_GATHER_VLA, \ .u = { \ .side_gather = { \ .u = { \ .side_vla = { \ + .length_type = _length_type_gather, \ .offset = _offset, \ .access_mode = _access_mode, \ .type = { \ .elem_type = _elem_type_gather, \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ - .length_type = _length_type_gather, \ }, \ }, \ }, \ }, \ } -#define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr) \ - _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM(_attr))) +#define side_field_gather_vla(_name, _elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \ + _side_field(_name, side_type_gather_vla(SIDE_PARAM(_elem_type_gather), _offset, _access_mode, SIDE_PARAM(_length_type_gather), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) #define side_elem(...) \ SIDE_COMPOUND_LITERAL(const struct side_type, __VA_ARGS__) @@ -1060,12 +1431,17 @@ struct side_event_description { #define side_field_list(...) \ SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__) -/* Static field arguments */ +#define side_option_list(...) \ + SIDE_COMPOUND_LITERAL(const struct side_variant_option, __VA_ARGS__) + +/* Stack-copy field arguments */ #define side_arg_null(_val) { .type = SIDE_TYPE_NULL } -#define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = !!(_val) } } } +#define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } } #define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_static = { .byte_value = (_val) } } } -#define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } } +#define side_arg_string(_val) { .type = SIDE_TYPE_STRING_UTF8, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } } +#define side_arg_string16(_val) { .type = SIDE_TYPE_STRING_UTF16, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } } +#define side_arg_string32(_val) { .type = SIDE_TYPE_STRING_UTF32, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } } #define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } } #define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } } @@ -1075,125 +1451,139 @@ struct side_event_description { #define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } } #define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } } #define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } } -#define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER_HOST, .u = { .side_static = { .integer_value = { SIDE_PTR_HOST = (uintptr_t) (_val) } } } } -#define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } } -#define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } } -#define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } } -#define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } } -#define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } } -#define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_static = { .side_vla = (_side_type) } } } +#define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER, .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } } #define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } } #define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } } #define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } } #define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } } #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = (_side_type) } } } + +#define side_arg_define_variant(_identifier, _selector_val, _option) \ + const struct side_arg_variant _identifier = { \ + .selector = _selector_val, \ + .option = _option, \ + } +#define side_arg_variant(_side_variant) \ + { \ + .type = SIDE_TYPE_VARIANT, \ + .u = { \ + .side_static = { \ + .side_variant = (_side_variant), \ + }, \ + }, \ + } + #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } } #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = (_side_type) } } } #define side_arg_vla_visitor(_ctx) { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } } -#define side_arg_array_u8(_ptr) { .type = SIDE_TYPE_ARRAY_U8, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_u16(_ptr) { .type = SIDE_TYPE_ARRAY_U16, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_u32(_ptr) { .type = SIDE_TYPE_ARRAY_U32, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_u64(_ptr) { .type = SIDE_TYPE_ARRAY_U64, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_s8(_ptr) { .type = SIDE_TYPE_ARRAY_S8, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_static = { .side_array_fixint = (_ptr) } } } -#define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER_HOST, .u = { .side_static = { .side_array_fixint = (_ptr) } } } - -#define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } -#define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } -#define side_arg_vla_u32(_ptr, _length) { .type = SIDE_TYPE_VLA_U32, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } -#define side_arg_vla_u64(_ptr, _length) { .type = SIDE_TYPE_VLA_U64, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } -#define side_arg_vla_s8(_ptr, _length) { .type = SIDE_TYPE_VLA_S8, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } -#define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } -#define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } -#define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } -#define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } -#define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER_HOST, .u = { .side_static = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } } - /* Gather field arguments */ -#define side_arg_gather_unsigned_integer(_ptr) { .type = SIDE_TYPE_GATHER_UNSIGNED_INT, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } } -#define side_arg_gather_signed_integer(_ptr) { .type = SIDE_TYPE_GATHER_SIGNED_INT, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } } + +#define side_arg_gather_bool(_ptr) { .type = SIDE_TYPE_GATHER_BOOL, .u = { .side_static = { .side_bool_gather_ptr = (_ptr) } } } +#define side_arg_gather_byte(_ptr) { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = (_ptr) } } } +#define side_arg_gather_pointer(_ptr) { .type = SIDE_TYPE_GATHER_POINTER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } } +#define side_arg_gather_integer(_ptr) { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } } #define side_arg_gather_float(_ptr) { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = (_ptr) } } } +#define side_arg_gather_string(_ptr) { .type = SIDE_TYPE_GATHER_STRING, .u = { .side_static = { .side_string_gather_ptr = (_ptr) } } } #define side_arg_gather_struct(_ptr) { .type = SIDE_TYPE_GATHER_STRUCT, .u = { .side_static = { .side_struct_gather_ptr = (_ptr) } } } #define side_arg_gather_array(_ptr) { .type = SIDE_TYPE_GATHER_ARRAY, .u = { .side_static = { .side_array_gather_ptr = (_ptr) } } } #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) } } } } /* Dynamic field arguments */ -#define side_arg_dynamic_null(_attr) \ +#define side_arg_dynamic_null(_attr...) \ { \ .type = SIDE_TYPE_DYNAMIC_NULL, \ .u = { \ .side_dynamic = { \ .side_null = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ }, \ }, \ } -#define side_arg_dynamic_bool(_val, _attr) \ +#define side_arg_dynamic_bool(_val, _attr...) \ { \ .type = SIDE_TYPE_DYNAMIC_BOOL, \ .u = { \ .side_dynamic = { \ .side_bool = { \ .type = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .bool_size = sizeof(uint8_t), \ + .len_bits = 0, \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + }, \ + .value = { \ + .side_bool8 = !!(_val), \ }, \ - .value = !!(_val), \ }, \ }, \ }, \ } -#define side_arg_dynamic_byte(_val, _attr) \ +#define side_arg_dynamic_byte(_val, _attr...) \ { \ .type = SIDE_TYPE_DYNAMIC_BYTE, \ .u = { \ .side_dynamic = { \ .side_byte = { \ .type = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ .value = (_val), \ }, \ }, \ }, \ } -#define side_arg_dynamic_string(_val, _attr) \ + +#define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr...) \ { \ .type = SIDE_TYPE_DYNAMIC_STRING, \ .u = { \ .side_dynamic = { \ .side_string = { \ .type = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .unit_size = _unit_size, \ + .byte_order = _byte_order, \ }, \ .value = (uintptr_t) (_val), \ }, \ }, \ }, \ } - -#define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size_bits, _len_bits, _attr) \ +#define side_arg_dynamic_string(_val, _attr...) \ + _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_string16(_val, _attr...) \ + _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_string16_le(_val, _attr...) \ + _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_string16_be(_val, _attr...) \ + _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_string32(_val, _attr...) \ + _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_string32_le(_val, _attr...) \ + _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_string32_be(_val, _attr...) \ + _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr...) \ { \ .type = _type, \ .u = { \ .side_dynamic = { \ .side_integer = { \ .type = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - .integer_size_bits = _integer_size_bits, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .integer_size = _integer_size, \ .len_bits = _len_bits, \ .signedness = _signedness, \ .byte_order = _byte_order, \ @@ -1206,39 +1596,39 @@ struct side_event_description { }, \ } -#define side_arg_dynamic_u8(_val, _attr) \ - _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s8(_val, _attr) \ - _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_S8, true, SIDE_TYPE_BYTE_ORDER_HOST, 8, 8, SIDE_PARAM(_attr)) - -#define _side_arg_dynamic_u16(_val, _byte_order, _attr) \ - _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_U16, false, _byte_order, 16, 16, SIDE_PARAM(_attr)) -#define _side_arg_dynamic_u32(_val, _byte_order, _attr) \ - _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_U32, false, _byte_order, 32, 32, SIDE_PARAM(_attr)) -#define _side_arg_dynamic_u64(_val, _byte_order, _attr) \ - _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_U64, false, _byte_order, 64, 64, SIDE_PARAM(_attr)) - -#define _side_arg_dynamic_s16(_val, _byte_order, _attr) \ - _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_S16, true, _byte_order, 16, 16, SIDE_PARAM(_attr)) -#define _side_arg_dynamic_s32(_val, _byte_order, _attr) \ - _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_S32, true, _byte_order, 32, 32, SIDE_PARAM(_attr)) -#define _side_arg_dynamic_s64(_val, _byte_order, _attr) \ - _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_S64, true, _byte_order, 64, 64, SIDE_PARAM(_attr)) - -#define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \ - _side_arg_dynamic_integer(SIDE_PTR_HOST, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER_HOST, false, _byte_order, \ - SIDE_BITS_PER_LONG, SIDE_BITS_PER_LONG, SIDE_PARAM(_attr)) - -#define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size_bits, _attr) \ +#define side_arg_dynamic_u8(_val, _attr...) \ + _side_arg_dynamic_integer(.side_u8, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s8(_val, _attr...) \ + _side_arg_dynamic_integer(.side_s8, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(int8_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define _side_arg_dynamic_u16(_val, _byte_order, _attr...) \ + _side_arg_dynamic_integer(.side_u16, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define _side_arg_dynamic_u32(_val, _byte_order, _attr...) \ + _side_arg_dynamic_integer(.side_u32, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define _side_arg_dynamic_u64(_val, _byte_order, _attr...) \ + _side_arg_dynamic_integer(.side_u64, _val, SIDE_TYPE_DYNAMIC_INTEGER, false, _byte_order, sizeof(uint64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define _side_arg_dynamic_s16(_val, _byte_order, _attr...) \ + _side_arg_dynamic_integer(.side_s16, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int16_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define _side_arg_dynamic_s32(_val, _byte_order, _attr...) \ + _side_arg_dynamic_integer(.side_s32, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int32_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define _side_arg_dynamic_s64(_val, _byte_order, _attr...) \ + _side_arg_dynamic_integer(.side_s64, _val, SIDE_TYPE_DYNAMIC_INTEGER, true, _byte_order, sizeof(int64_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define _side_arg_dynamic_pointer(_val, _byte_order, _attr...) \ + _side_arg_dynamic_integer(.side_uptr, (uintptr_t) (_val), SIDE_TYPE_DYNAMIC_POINTER, false, _byte_order, \ + sizeof(uintptr_t), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) + +#define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr...) \ { \ .type = _type, \ .u = { \ .side_dynamic = { \ .side_float = { \ .type = { \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - .float_size_bits = _float_size_bits, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ + .float_size = _float_size, \ .byte_order = _byte_order, \ }, \ .value = { \ @@ -1249,53 +1639,53 @@ struct side_event_description { }, \ } -#define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \ - _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY16, _byte_order, 16, SIDE_PARAM(_attr)) -#define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \ - _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY32, _byte_order, 32, SIDE_PARAM(_attr)) -#define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \ - _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY64, _byte_order, 64, SIDE_PARAM(_attr)) -#define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \ - _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT_BINARY128, _byte_order, 128, SIDE_PARAM(_attr)) +#define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr...) \ + _side_arg_dynamic_float(.side_float_binary16, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float16), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr...) \ + _side_arg_dynamic_float(.side_float_binary32, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float32), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr...) \ + _side_arg_dynamic_float(.side_float_binary64, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float64), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr...) \ + _side_arg_dynamic_float(.side_float_binary128, _val, SIDE_TYPE_DYNAMIC_FLOAT, _byte_order, sizeof(_Float128), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) /* Host endian */ -#define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u16(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_u32(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_u64(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s16(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s32(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s64(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_pointer(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary16(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary32(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary64(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary128(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) /* Little endian */ -#define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u16_le(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_u32_le(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_u64_le(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s16_le(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s32_le(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s64_le(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_pointer_le(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary16_le(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary32_le(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary64_le(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary128_le(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) /* Big endian */ -#define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) -#define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u16_be(_val, _attr...) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_u32_be(_val, _attr...) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_u64_be(_val, _attr...) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s16_be(_val, _attr...) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s32_be(_val, _attr...) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_s64_be(_val, _attr...) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_pointer_be(_val, _attr...) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary16_be(_val, _attr...) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary32_be(_val, _attr...) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary64_be(_val, _attr...) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) +#define side_arg_dynamic_float_binary128_be(_val, _attr...) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) #define side_arg_dynamic_vla(_vla) \ { \ @@ -1307,7 +1697,7 @@ struct side_event_description { }, \ } -#define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \ +#define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr...) \ { \ .type = SIDE_TYPE_DYNAMIC_VLA_VISITOR, \ .u = { \ @@ -1315,8 +1705,8 @@ struct side_event_description { .side_dynamic_vla_visitor = { \ .app_ctx = _ctx, \ .visitor = _dynamic_vla_visitor, \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ }, \ }, \ @@ -1332,7 +1722,7 @@ struct side_event_description { }, \ } -#define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \ +#define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr...) \ { \ .type = SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, \ .u = { \ @@ -1340,29 +1730,29 @@ struct side_event_description { .side_dynamic_struct_visitor = { \ .app_ctx = _ctx, \ .visitor = _dynamic_struct_visitor, \ - .attr = _attr, \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ }, \ }, \ } -#define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \ +#define side_arg_dynamic_define_vec(_identifier, _sav, _attr...) \ const struct side_arg _identifier##_vec[] = { _sav }; \ const struct side_arg_dynamic_vla _identifier = { \ .sav = _identifier##_vec, \ - .attr = _attr, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ } -#define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \ +#define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr...) \ const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \ const struct side_arg_dynamic_struct _identifier = { \ .fields = _identifier##_fields, \ - .attr = _attr, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ .len = SIDE_ARRAY_SIZE(_identifier##_fields), \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ } #define side_arg_define_vec(_identifier, _sav) \ @@ -1378,60 +1768,15 @@ struct side_event_description { .elem = _elem, \ } -#define side_arg_list(...) __VA_ARGS__ - -#define side_define_enum(_identifier, _mappings, _attr) \ - const struct side_enum_mappings _identifier = { \ - .mappings = _mappings, \ - .attr = _attr, \ - .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - } - -#define side_enum_mapping_list(...) \ - SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__) - -#define side_enum_mapping_range(_label, _begin, _end) \ - { \ - .range_begin = _begin, \ - .range_end = _end, \ - .label = _label, \ - } - -#define side_enum_mapping_value(_label, _value) \ - { \ - .range_begin = _value, \ - .range_end = _value, \ - .label = _label, \ - } - -#define side_define_enum_bitmap(_identifier, _mappings, _attr) \ - const struct side_enum_bitmap_mappings _identifier = { \ - .mappings = _mappings, \ - .attr = _attr, \ - .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - } - -#define side_enum_bitmap_mapping_list(...) \ - SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__) - -#define side_enum_bitmap_mapping_range(_label, _begin, _end) \ - { \ - .range_begin = _begin, \ - .range_end = _end, \ - .label = _label, \ - } +/* + * Event instrumentation description registration, runtime enabled state + * check, and instrumentation invocation. + */ -#define side_enum_bitmap_mapping_value(_label, _value) \ - { \ - .range_begin = _value, \ - .range_end = _value, \ - .label = _label, \ - } +#define side_arg_list(...) __VA_ARGS__ #define side_event_cond(_identifier) \ - if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \ + if (side_unlikely(__atomic_load_n(&side_event_state__##_identifier.enabled, \ __ATOMIC_RELAXED))) #define side_event_call(_identifier, _sav) \ @@ -1448,7 +1793,7 @@ struct side_event_description { side_event_cond(_identifier) \ side_event_call(_identifier, SIDE_PARAM(_sav)) -#define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \ +#define side_event_call_variadic(_identifier, _sav, _var_fields, _attr...) \ { \ const struct side_arg side_sav[] = { _sav }; \ const struct side_arg_vec side_arg_vec = { \ @@ -1458,65 +1803,72 @@ struct side_event_description { const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \ const struct side_arg_dynamic_struct var_struct = { \ .fields = side_fields, \ - .attr = _attr, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ .len = SIDE_ARRAY_SIZE(side_fields), \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }; \ side_call_variadic(&(_identifier), &side_arg_vec, &var_struct); \ } -#define side_event_variadic(_identifier, _sav, _var, _attr) \ +#define side_event_variadic(_identifier, _sav, _var, _attr...) \ side_event_cond(_identifier) \ - side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr)) + side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) -#define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \ - _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \ +#define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _flags, _attr...) \ + _linkage struct side_event_state __attribute__((section("side_event_state"))) \ + side_event_state__##_identifier = { \ + .enabled = 0, \ + .callbacks = &side_empty_callback, \ + .nr_callbacks = 0, \ + }; \ _linkage struct side_event_description __attribute__((section("side_event_description"))) \ _identifier = { \ - .enabled = &(side_event_enable__##_identifier), \ + .state = &(side_event_state__##_identifier), \ .provider_name = _provider, \ .event_name = _event, \ .fields = _fields, \ - .attr = _attr, \ - .callbacks = &side_empty_callback, \ + .attr = SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()), \ .flags = (_flags), \ .version = 0, \ .loglevel = _loglevel, \ .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ - .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ - .nr_callbacks = 0, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }; \ static const struct side_event_description *side_event_ptr__##_identifier \ __attribute__((section("side_event_description_ptr"), used)) = &(_identifier); -#define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \ +#define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ - SIDE_PARAM(_attr), 0) + 0, ##_attr) -#define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \ +#define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ - SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC) + SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) -#define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \ +#define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \ - _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0) + _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) -#define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \ +#define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, \ - _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC) + _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) -#define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \ +#define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \ - _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), 0) + _loglevel, SIDE_PARAM(_fields), 0, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) -#define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \ +#define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr...) \ _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, \ - _loglevel, SIDE_PARAM(_fields), SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC) + _loglevel, SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())) #define side_declare_event(_identifier) \ - extern uintptr_t side_event_enable_##_identifier; \ + extern struct side_event_state side_event_state_##_identifier; \ extern struct side_event_description _identifier +#ifdef __cplusplus +extern "C" { +#endif + extern const struct side_callback side_empty_callback; void side_call(const struct side_event_description *desc, @@ -1525,6 +1877,16 @@ void side_call_variadic(const struct side_event_description *desc, const struct side_arg_vec *side_arg_vec, const struct side_arg_dynamic_struct *var_struct); +struct side_events_register_handle *side_events_register(struct side_event_description **events, + uint32_t nr_events); +void side_events_unregister(struct side_events_register_handle *handle); + +/* + * Userspace tracer registration API. This allows userspace tracers to + * register event notification callbacks to be notified of the currently + * registered instrumentation, and to register their callbacks to + * specific events. + */ typedef void (*side_tracer_callback_func)(const struct side_event_description *desc, const struct side_arg_vec *side_arg_vec, void *priv); @@ -1546,10 +1908,6 @@ int side_tracer_callback_variadic_unregister(struct side_event_description *desc side_tracer_callback_variadic_func call_variadic, void *priv); -struct side_events_register_handle *side_events_register(struct side_event_description **events, - uint32_t nr_events); -void side_events_unregister(struct side_events_register_handle *handle); - enum side_tracer_notification { SIDE_TRACER_NOTIFICATION_INSERT_EVENTS, SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS, @@ -1562,8 +1920,18 @@ struct side_tracer_handle *side_tracer_event_notification_register( void *priv); void side_tracer_event_notification_unregister(struct side_tracer_handle *handle); -void side_init(void); -void side_exit(void); +/* + * Explicit hooks to initialize/finalize the side instrumentation + * library. Those are also library constructor/destructor. + */ +void side_init(void) __attribute__((constructor)); +void side_exit(void) __attribute__((destructor)); + +/* + * The following constructors/destructors perform automatic registration + * of the declared side events. Those may have to be called explicitly + * in a statically linked library. + */ /* * These weak symbols, the constructor, and destructor take care of @@ -1605,4 +1973,8 @@ side_event_description_ptr_exit(void) side_events_handle = NULL; } +#ifdef __cplusplus +} +#endif + #endif /* _SIDE_TRACE_H */