From 35c1f459092b630dd2825450014e27c84b31ddee Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 16 Mar 2021 22:12:13 -0400 Subject: [PATCH] Refactoring: remove struct_size from struct lttng_ust_ctx_value The struct_size scheme is not appropriate to extend struct lttng_ust_ctx_value because its type selector and union already act as a mean to extend it. When new entries are added to the union, the size of that union may increase, thus shifting the offset of fields following that union. It is therefore not possible to extend it by adding fields after the union, thus making the struct_size scheme irrelevant. Signed-off-by: Mathieu Desnoyers Change-Id: I9e80e0ea87c3df3fe76863ed5343de733210045e --- include/ust-context-provider.h | 16 +++++----------- liblttng-ust/lttng-bytecode-interpreter.c | 5 ----- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/include/ust-context-provider.h b/include/ust-context-provider.h index 3b41a66e..e62950e1 100644 --- a/include/ust-context-provider.h +++ b/include/ust-context-provider.h @@ -21,26 +21,20 @@ * Context value * * IMPORTANT: this structure is part of the ABI between the probe and - * UST. Fields need to be only added at the end, never reordered, never - * removed. - * - * The field @struct_size should be used to determine the size of the - * structure. It should be queried before using additional fields added - * at the end of the structure. + * UST. Additional selectors may be added in the future, mapping to new + * union fields, which means the overall size of this structure may + * increase. This means this structure should never be nested within a + * public structure interface, nor embedded in an array. */ struct lttng_ust_ctx_value { - uint32_t struct_size; - - enum lttng_ust_dynamic_type sel; + enum lttng_ust_dynamic_type sel; /* Type selector */ union { int64_t s64; uint64_t u64; const char *str; double d; } u; - - /* End of base ABI. Fields below should be used after checking struct_size. */ }; /* diff --git a/liblttng-ust/lttng-bytecode-interpreter.c b/liblttng-ust/lttng-bytecode-interpreter.c index 5b2dc51a..947da3ee 100644 --- a/liblttng-ust/lttng-bytecode-interpreter.c +++ b/liblttng-ust/lttng-bytecode-interpreter.c @@ -226,7 +226,6 @@ static int context_get_index(struct lttng_ust_ctx *ctx, struct lttng_ust_event_field *field; struct lttng_ust_ctx_value v; - v.struct_size = sizeof(struct lttng_ust_ctx_value); ctx_field = ctx->fields[idx]; field = ctx_field->event_field; ptr->type = LOAD_OBJECT; @@ -2140,7 +2139,6 @@ uint64_t bytecode_interpret(void *interpreter_data, struct lttng_ust_ctx_field *ctx_field; struct lttng_ust_ctx_value v; - v.struct_size = sizeof(struct lttng_ust_ctx_value); dbg_printf("get context ref offset %u type dynamic\n", ref->offset); ctx_field = ctx->fields[ref->offset]; @@ -2189,7 +2187,6 @@ uint64_t bytecode_interpret(void *interpreter_data, struct lttng_ust_ctx_field *ctx_field; struct lttng_ust_ctx_value v; - v.struct_size = sizeof(struct lttng_ust_ctx_value); dbg_printf("get context ref offset %u type string\n", ref->offset); ctx_field = ctx->fields[ref->offset]; @@ -2217,7 +2214,6 @@ uint64_t bytecode_interpret(void *interpreter_data, struct lttng_ust_ctx_field *ctx_field; struct lttng_ust_ctx_value v; - v.struct_size = sizeof(struct lttng_ust_ctx_value); dbg_printf("get context ref offset %u type s64\n", ref->offset); ctx_field = ctx->fields[ref->offset]; @@ -2237,7 +2233,6 @@ uint64_t bytecode_interpret(void *interpreter_data, struct lttng_ust_ctx_field *ctx_field; struct lttng_ust_ctx_value v; - v.struct_size = sizeof(struct lttng_ust_ctx_value); dbg_printf("get context ref offset %u type double\n", ref->offset); ctx_field = ctx->fields[ref->offset]; -- 2.34.1