From daacdbfc04fe07ecff0a0d1878b4f48d38912c78 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 16 Mar 2021 14:51:18 -0400 Subject: [PATCH] Refactoring: context structures The context structures are now hidden in headers which are not installed, but those are still part of the UST ABI. Therefore, we need to update them to make sure those are extensible. - Namespace theses structures with lttng_ust_ prefix, - Use struct_size extensibility scheme. There was no prior padding, so extensibility was an issue in the past. - Remove padding. - This requires that none of those structures can be nested. It also requires that all arrays of structures must be replaced by arrays of pointers to structures. - Replace struct lttng_perf_counter_field pointer by a private data pointer. Signed-off-by: Mathieu Desnoyers Change-Id: I4ecb8f73652770f15c693c1b5b2acce3e871a64b --- include/lttng/ust-events.h | 10 +- include/ust-comm.h | 4 +- include/ust-context-provider.h | 120 +++++++++++---- liblttng-ust-comm/lttng-ust-comm.c | 10 +- .../jni/common/lttng_ust_context.c | 9 +- liblttng-ust/context-internal.h | 64 ++++---- liblttng-ust/context-provider-internal.h | 8 +- liblttng-ust/lttng-bytecode-interpreter.c | 43 +++--- liblttng-ust/lttng-bytecode-specialize.c | 20 +-- liblttng-ust/lttng-bytecode.c | 12 +- liblttng-ust/lttng-context-cgroup-ns.c | 28 ++-- liblttng-ust/lttng-context-cpu-id.c | 28 ++-- liblttng-ust/lttng-context-ip.c | 24 +-- liblttng-ust/lttng-context-ipc-ns.c | 28 ++-- liblttng-ust/lttng-context-mnt-ns.c | 28 ++-- liblttng-ust/lttng-context-net-ns.c | 28 ++-- liblttng-ust/lttng-context-perf-counters.c | 40 ++--- liblttng-ust/lttng-context-pid-ns.c | 28 ++-- liblttng-ust/lttng-context-procname.c | 20 +-- liblttng-ust/lttng-context-provider.c | 62 +++++--- liblttng-ust/lttng-context-pthread-id.c | 28 ++-- liblttng-ust/lttng-context-time-ns.c | 28 ++-- liblttng-ust/lttng-context-user-ns.c | 28 ++-- liblttng-ust/lttng-context-uts-ns.c | 28 ++-- liblttng-ust/lttng-context-vegid.c | 28 ++-- liblttng-ust/lttng-context-veuid.c | 28 ++-- liblttng-ust/lttng-context-vgid.c | 28 ++-- liblttng-ust/lttng-context-vpid.c | 28 ++-- liblttng-ust/lttng-context-vsgid.c | 28 ++-- liblttng-ust/lttng-context-vsuid.c | 28 ++-- liblttng-ust/lttng-context-vtid.c | 28 ++-- liblttng-ust/lttng-context-vuid.c | 28 ++-- liblttng-ust/lttng-context.c | 145 +++++++++++------- liblttng-ust/lttng-events.c | 26 ++-- liblttng-ust/lttng-ring-buffer-client.h | 22 +-- liblttng-ust/lttng-tracer-core.h | 12 +- liblttng-ust/lttng-ust-abi.c | 2 +- liblttng-ust/ust-core.c | 8 +- liblttng-ust/ust-events-internal.h | 14 +- tests/compile/test-app-ctx/hello.c | 9 +- 40 files changed, 656 insertions(+), 532 deletions(-) diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 65078427..18e4cd55 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -343,7 +343,7 @@ struct lttng_ust_bytecode_runtime { * removed. */ -struct lttng_ctx; +struct lttng_ust_ctx; struct lttng_ust_event_common_private; enum lttng_ust_event_type { @@ -404,7 +404,7 @@ struct lttng_ust_event_recorder { unsigned int id; struct lttng_channel *chan; - struct lttng_ctx *ctx; + struct lttng_ust_ctx *ctx; /* End of base ABI. Fields below should be used after checking struct_size. */ }; @@ -499,7 +499,7 @@ struct lttng_channel { */ struct lttng_ust_lib_ring_buffer_channel *chan; /* Channel buffers */ int enabled; - struct lttng_ctx *ctx; + struct lttng_ust_ctx *ctx; /* Event ID management */ struct lttng_session *session; int objd; /* Object associated to channel */ @@ -528,8 +528,8 @@ struct lttng_ust_stack_ctx { uint32_t struct_size; /* Size of this structure */ struct lttng_ust_event_recorder *event_recorder; - struct lttng_ctx *chan_ctx; /* RCU dereferenced. */ - struct lttng_ctx *event_ctx; /* RCU dereferenced. */ + struct lttng_ust_ctx *chan_ctx; /* RCU dereferenced. */ + struct lttng_ust_ctx *event_ctx; /* RCU dereferenced. */ /* End of base ABI. Fields below should be used after checking struct_size. */ }; diff --git a/include/ust-comm.h b/include/ust-comm.h index da10b408..b45797ef 100644 --- a/include/ust-comm.h +++ b/include/ust-comm.h @@ -42,7 +42,7 @@ #define LTTNG_UST_COMM_REG_MSG_PADDING 64 struct lttng_ust_event_field; -struct lttng_ctx_field; +struct lttng_ust_ctx_field; struct lttng_ust_enum_entry; struct lttng_integer_type; struct lttng_session; @@ -318,7 +318,7 @@ int ustcomm_register_channel(int sock, int session_objd, /* session descriptor */ int channel_objd, /* channel descriptor */ size_t nr_ctx_fields, - const struct lttng_ctx_field *ctx_fields, + struct lttng_ust_ctx_field **ctx_fields, uint32_t *chan_id, /* channel id (output) */ int *header_type); /* header type (output) */ diff --git a/include/ust-context-provider.h b/include/ust-context-provider.h index 670c3863..3b41a66e 100644 --- a/include/ust-context-provider.h +++ b/include/ust-context-provider.h @@ -17,7 +17,21 @@ #include "ust-dynamic-type.h" -struct lttng_ctx_value { +/* + * 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. + */ + +struct lttng_ust_ctx_value { + uint32_t struct_size; + enum lttng_ust_dynamic_type sel; union { int64_t s64; @@ -25,66 +39,108 @@ struct lttng_ctx_value { const char *str; double d; } u; + + /* End of base ABI. Fields below should be used after checking struct_size. */ }; -struct lttng_perf_counter_field; +/* + * Context field + * + * 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. + */ + +struct lttng_ust_ctx_field { + uint32_t struct_size; + void *priv; -#define LTTNG_UST_CTX_FIELD_PADDING 40 -struct lttng_ctx_field { - struct lttng_ust_event_field event_field; - size_t (*get_size)(struct lttng_ctx_field *field, size_t offset); - void (*record)(struct lttng_ctx_field *field, + struct lttng_ust_event_field *event_field; + size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset); + void (*record)(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan); - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value); - union { - struct lttng_perf_counter_field *perf_counter; - char padding[LTTNG_UST_CTX_FIELD_PADDING]; - } u; - void (*destroy)(struct lttng_ctx_field *field); + void (*get_value)(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value); + void (*destroy)(struct lttng_ust_ctx_field *field); char *field_name; /* Has ownership, dynamically allocated. */ + + /* End of base ABI. Fields below should be used after checking struct_size. */ }; -#define LTTNG_UST_CTX_PADDING 20 -struct lttng_ctx { - struct lttng_ctx_field *fields; +/* + * All context fields for a given event/channel + * + * 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. + */ + +struct lttng_ust_ctx { + uint32_t struct_size; + + struct lttng_ust_ctx_field **fields; unsigned int nr_fields; unsigned int allocated_fields; unsigned int largest_align; - char padding[LTTNG_UST_CTX_PADDING]; + + /* End of base ABI. Fields below should be used after checking struct_size. */ }; +/* + * Context provider + * + * 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. + */ + struct lttng_ust_context_provider { + uint32_t struct_size; + char *name; - size_t (*get_size)(struct lttng_ctx_field *field, size_t offset); - void (*record)(struct lttng_ctx_field *field, + size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset); + void (*record)(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan); - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value); + void (*get_value)(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value); struct cds_hlist_node node; + + /* End of base ABI. Fields below should be used after checking struct_size. */ }; int lttng_ust_context_provider_register(struct lttng_ust_context_provider *provider); void lttng_ust_context_provider_unregister(struct lttng_ust_context_provider *provider); void lttng_ust_context_set_session_provider(const char *name, - size_t (*get_size)(struct lttng_ctx_field *field, size_t offset), - void (*record)(struct lttng_ctx_field *field, + size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset), + void (*record)(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan), - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value)); + void (*get_value)(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value)); -int lttng_ust_add_app_context_to_ctx_rcu(const char *name, struct lttng_ctx **ctx); -int lttng_ust_context_set_provider_rcu(struct lttng_ctx **_ctx, +int lttng_ust_add_app_context_to_ctx_rcu(const char *name, struct lttng_ust_ctx **ctx); +int lttng_ust_context_set_provider_rcu(struct lttng_ust_ctx **_ctx, const char *name, - size_t (*get_size)(struct lttng_ctx_field *field, size_t offset), - void (*record)(struct lttng_ctx_field *field, + size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset), + void (*record)(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan), - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value)); + void (*get_value)(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value)); #endif /* _LTTNG_UST_CONTEXT_PROVIDER_H */ diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index 656e170b..6a801b5c 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -929,7 +929,7 @@ ssize_t count_fields_recursive(size_t nr_fields, static ssize_t count_ctx_fields_recursive(size_t nr_fields, - const struct lttng_ctx_field *lttng_fields) + struct lttng_ust_ctx_field **lttng_fields) { int i; ssize_t ret, count = 0; @@ -937,7 +937,7 @@ ssize_t count_ctx_fields_recursive(size_t nr_fields, for (i = 0; i < nr_fields; i++) { const struct lttng_ust_event_field *lf; - lf = <tng_fields[i].event_field; + lf = lttng_fields[i]->event_field; /* skip 'nowrite' fields */ if (lf->nowrite) continue; @@ -1340,7 +1340,7 @@ int serialize_ctx_fields(struct lttng_session *session, size_t *_nr_write_fields, struct ustctl_field **ustctl_fields, size_t nr_fields, - const struct lttng_ctx_field *lttng_fields) + struct lttng_ust_ctx_field **lttng_fields) { struct ustctl_field *fields; int ret; @@ -1359,7 +1359,7 @@ int serialize_ctx_fields(struct lttng_session *session, for (i = 0; i < nr_fields; i++) { ret = serialize_one_field(session, fields, &iter_output, - <tng_fields[i].event_field); + lttng_fields[i]->event_field); if (ret) goto error_type; } @@ -1628,7 +1628,7 @@ int ustcomm_register_channel(int sock, int session_objd, /* session descriptor */ int channel_objd, /* channel descriptor */ size_t nr_ctx_fields, - const struct lttng_ctx_field *ctx_fields, + struct lttng_ust_ctx_field **ctx_fields, uint32_t *chan_id, /* channel id (output) */ int *header_type) /* header type (output) */ { diff --git a/liblttng-ust-java-agent/jni/common/lttng_ust_context.c b/liblttng-ust-java-agent/jni/common/lttng_ust_context.c index bda3b6ee..52097896 100644 --- a/liblttng-ust-java-agent/jni/common/lttng_ust_context.c +++ b/liblttng-ust-java-agent/jni/common/lttng_ust_context.c @@ -73,7 +73,7 @@ static struct lttng_ust_jni_ctx_entry *lookup_ctx_by_name(const char *ctx_name) return NULL; } -static size_t get_size_cb(struct lttng_ctx_field *field, size_t offset) +static size_t get_size_cb(struct lttng_ust_ctx_field *field, size_t offset) { struct lttng_ust_jni_ctx_entry *jctx; size_t size = 0; @@ -135,7 +135,7 @@ static size_t get_size_cb(struct lttng_ctx_field *field, size_t offset) } -static void record_cb(struct lttng_ctx_field *field, +static void record_cb(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -256,8 +256,8 @@ static void record_cb(struct lttng_ctx_field *field, } } -static void get_value_cb(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +static void get_value_cb(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { struct lttng_ust_jni_ctx_entry *jctx; const char *ctx_name = field->event_field.name; @@ -354,6 +354,7 @@ JNIEXPORT jlong JNICALL Java_org_lttng_ust_agent_context_LttngContextApi_registe if (!provider) { goto error_provider; } + provider->struct_size = sizeof(*provider); provider->name = provider_name_cstr; provider->get_size = get_size_cb; provider->record = record_cb; diff --git a/liblttng-ust/context-internal.h b/liblttng-ust/context-internal.h index f31d8a24..7060e281 100644 --- a/liblttng-ust/context-internal.h +++ b/liblttng-ust/context-internal.h @@ -12,35 +12,35 @@ #include "ust-context-provider.h" __attribute__((visibility("hidden"))) -int lttng_context_init_all(struct lttng_ctx **ctx); +int lttng_context_init_all(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) int lttng_attach_context(struct lttng_ust_abi_context *context_param, union lttng_ust_abi_args *uargs, - struct lttng_ctx **ctx, struct lttng_session *session); + struct lttng_ust_ctx **ctx, struct lttng_session *session); __attribute__((visibility("hidden"))) -int lttng_find_context(struct lttng_ctx *ctx, const char *name); +int lttng_find_context(struct lttng_ust_ctx *ctx, const char *name); __attribute__((visibility("hidden"))) -int lttng_get_context_index(struct lttng_ctx *ctx, const char *name); +int lttng_get_context_index(struct lttng_ust_ctx *ctx, const char *name); __attribute__((visibility("hidden"))) -struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p); +struct lttng_ust_ctx_field *lttng_append_context(struct lttng_ust_ctx **ctx_p); __attribute__((visibility("hidden"))) -void lttng_context_update(struct lttng_ctx *ctx); +void lttng_context_update(struct lttng_ust_ctx *ctx); __attribute__((visibility("hidden"))) -void lttng_remove_context_field(struct lttng_ctx **ctx_p, - struct lttng_ctx_field *field); +void lttng_remove_context_field(struct lttng_ust_ctx **ctx_p, + struct lttng_ust_ctx_field *field); __attribute__((visibility("hidden"))) -void lttng_destroy_context(struct lttng_ctx *ctx); +void lttng_destroy_context(struct lttng_ust_ctx *ctx); __attribute__((visibility("hidden"))) -int lttng_context_add_rcu(struct lttng_ctx **ctx_p, - const struct lttng_ctx_field *f); +int lttng_context_add_rcu(struct lttng_ust_ctx **ctx_p, + struct lttng_ust_ctx_field *f); __attribute__((visibility("hidden"))) int lttng_context_is_app(const char *name); @@ -94,66 +94,66 @@ __attribute__((visibility("hidden"))) void lttng_context_vsgid_reset(void); __attribute__((visibility("hidden"))) -int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_vtid_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_vpid_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx); +int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_procname_to_ctx(struct lttng_ctx **ctx); +int lttng_add_procname_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_ip_to_ctx(struct lttng_ctx **ctx); +int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx); +int lttng_add_cpu_id_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_dyntest_to_ctx(struct lttng_ctx **ctx); +int lttng_add_dyntest_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx); +int lttng_add_cgroup_ns_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx); +int lttng_add_ipc_ns_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx); +int lttng_add_mnt_ns_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx); +int lttng_add_net_ns_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx); +int lttng_add_pid_ns_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx); +int lttng_add_user_ns_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx); +int lttng_add_uts_ns_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_time_ns_to_ctx(struct lttng_ctx **ctx); +int lttng_add_time_ns_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_vuid_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_veuid_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_vsuid_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_vgid_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_vegid_to_ctx(struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) -int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_vsgid_to_ctx(struct lttng_ust_ctx **ctx); #endif /* _LTTNG_UST_CONTEXT_INTERNAL_H */ diff --git a/liblttng-ust/context-provider-internal.h b/liblttng-ust/context-provider-internal.h index 0ada2ccf..96343d90 100644 --- a/liblttng-ust/context-provider-internal.h +++ b/liblttng-ust/context-provider-internal.h @@ -12,11 +12,11 @@ __attribute__((visibility("hidden"))) void lttng_ust_context_set_event_notifier_group_provider(const char *name, - size_t (*get_size)(struct lttng_ctx_field *field, size_t offset), - void (*record)(struct lttng_ctx_field *field, + size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset), + void (*record)(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan), - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value)); + void (*get_value)(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value)); #endif /* _LTTNG_UST_CONTEXT_PROVIDER_INTERNAL_H */ diff --git a/liblttng-ust/lttng-bytecode-interpreter.c b/liblttng-ust/lttng-bytecode-interpreter.c index 46351a25..5b2dc51a 100644 --- a/liblttng-ust/lttng-bytecode-interpreter.c +++ b/liblttng-ust/lttng-bytecode-interpreter.c @@ -217,17 +217,18 @@ LABEL_##name #define IS_INTEGER_REGISTER(reg_type) \ (reg_type == REG_U64 || reg_type == REG_S64) -static int context_get_index(struct lttng_ctx *ctx, +static int context_get_index(struct lttng_ust_ctx *ctx, struct load_ptr *ptr, uint32_t idx) { - struct lttng_ctx_field *ctx_field; + struct lttng_ust_ctx_field *ctx_field; struct lttng_ust_event_field *field; - struct lttng_ctx_value v; + struct lttng_ust_ctx_value v; - ctx_field = &ctx->fields[idx]; - field = &ctx_field->event_field; + v.struct_size = sizeof(struct lttng_ust_ctx_value); + ctx_field = ctx->fields[idx]; + field = ctx_field->event_field; ptr->type = LOAD_OBJECT; ptr->field = field; @@ -345,7 +346,7 @@ static int context_get_index(struct lttng_ctx *ctx, return 0; } -static int dynamic_get_index(struct lttng_ctx *ctx, +static int dynamic_get_index(struct lttng_ust_ctx *ctx, struct bytecode_runtime *runtime, uint64_t index, struct estack_entry *stack_top) { @@ -717,7 +718,7 @@ uint64_t bytecode_interpret(void *interpreter_data, struct lttng_interpreter_output *output) { struct bytecode_runtime *bytecode = interpreter_data; - struct lttng_ctx *ctx = lttng_ust_rcu_dereference(*bytecode->p.priv->pctx); + struct lttng_ust_ctx *ctx = lttng_ust_rcu_dereference(*bytecode->p.priv->pctx); void *pc, *next_pc, *start_pc; int ret = -EINVAL; uint64_t retval = 0; @@ -2136,12 +2137,13 @@ uint64_t bytecode_interpret(void *interpreter_data, { struct load_op *insn = (struct load_op *) pc; struct field_ref *ref = (struct field_ref *) insn->data; - struct lttng_ctx_field *ctx_field; - struct lttng_ctx_value v; + 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]; + ctx_field = ctx->fields[ref->offset]; ctx_field->get_value(ctx_field, &v); estack_push(stack, top, ax, bx, ax_t, bx_t); switch (v.sel) { @@ -2184,12 +2186,13 @@ uint64_t bytecode_interpret(void *interpreter_data, { struct load_op *insn = (struct load_op *) pc; struct field_ref *ref = (struct field_ref *) insn->data; - struct lttng_ctx_field *ctx_field; - struct lttng_ctx_value v; + 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]; + ctx_field = ctx->fields[ref->offset]; ctx_field->get_value(ctx_field, &v); estack_push(stack, top, ax, bx, ax_t, bx_t); estack_ax(stack, top)->u.s.str = v.u.str; @@ -2211,12 +2214,13 @@ uint64_t bytecode_interpret(void *interpreter_data, { struct load_op *insn = (struct load_op *) pc; struct field_ref *ref = (struct field_ref *) insn->data; - struct lttng_ctx_field *ctx_field; - struct lttng_ctx_value v; + 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]; + ctx_field = ctx->fields[ref->offset]; ctx_field->get_value(ctx_field, &v); estack_push(stack, top, ax, bx, ax_t, bx_t); estack_ax_v = v.u.s64; @@ -2230,12 +2234,13 @@ uint64_t bytecode_interpret(void *interpreter_data, { struct load_op *insn = (struct load_op *) pc; struct field_ref *ref = (struct field_ref *) insn->data; - struct lttng_ctx_field *ctx_field; - struct lttng_ctx_value v; + 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]; + ctx_field = ctx->fields[ref->offset]; ctx_field->get_value(ctx_field, &v); estack_push(stack, top, ax, bx, ax_t, bx_t); memcpy(&estack_ax(stack, top)->u.d, &v.u.d, sizeof(struct literal_double)); diff --git a/liblttng-ust/lttng-bytecode-specialize.c b/liblttng-ust/lttng-bytecode-specialize.c index 1ba4ffeb..c546c8d6 100644 --- a/liblttng-ust/lttng-bytecode-specialize.c +++ b/liblttng-ust/lttng-bytecode-specialize.c @@ -366,7 +366,7 @@ end: return ret; } -static int specialize_context_lookup_name(struct lttng_ctx *ctx, +static int specialize_context_lookup_name(struct lttng_ust_ctx *ctx, struct bytecode_runtime *bytecode, struct load_op *insn) { @@ -452,13 +452,13 @@ static int specialize_load_object(const struct lttng_ust_event_field *field, return 0; } -static int specialize_context_lookup(struct lttng_ctx *ctx, +static int specialize_context_lookup(struct lttng_ust_ctx *ctx, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) { int idx, ret; - struct lttng_ctx_field *ctx_field; + struct lttng_ust_ctx_field *ctx_field; struct lttng_ust_event_field *field; struct bytecode_get_index_data gid; ssize_t data_offset; @@ -467,8 +467,8 @@ static int specialize_context_lookup(struct lttng_ctx *ctx, if (idx < 0) { return -ENOENT; } - ctx_field = &ctx->fields[idx]; - field = &ctx_field->event_field; + ctx_field = ctx->fields[idx]; + field = ctx_field->event_field; ret = specialize_load_object(field, load, true); if (ret) return ret; @@ -488,7 +488,7 @@ static int specialize_context_lookup(struct lttng_ctx *ctx, return 0; } -static int specialize_app_context_lookup(struct lttng_ctx **pctx, +static int specialize_app_context_lookup(struct lttng_ust_ctx **pctx, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) @@ -497,7 +497,7 @@ static int specialize_app_context_lookup(struct lttng_ctx **pctx, const char *orig_name; char *name = NULL; int idx, ret; - struct lttng_ctx_field *ctx_field; + struct lttng_ust_ctx_field *ctx_field; struct lttng_ust_event_field *field; struct bytecode_get_index_data gid; ssize_t data_offset; @@ -522,8 +522,8 @@ static int specialize_app_context_lookup(struct lttng_ctx **pctx, if (idx < 0) return -ENOENT; } - ctx_field = &(*pctx)->fields[idx]; - field = &ctx_field->event_field; + ctx_field = (*pctx)->fields[idx]; + field = ctx_field->event_field; ret = specialize_load_object(field, load, true); if (ret) goto end; @@ -631,7 +631,7 @@ int lttng_bytecode_specialize(const struct lttng_ust_event_desc *event_desc, int ret = -EINVAL; struct vstack _stack; struct vstack *stack = &_stack; - struct lttng_ctx **pctx = bytecode->p.priv->pctx; + struct lttng_ust_ctx **pctx = bytecode->p.priv->pctx; vstack_init(stack); diff --git a/liblttng-ust/lttng-bytecode.c b/liblttng-ust/lttng-bytecode.c index 6c86c634..f9ebc476 100644 --- a/liblttng-ust/lttng-bytecode.c +++ b/liblttng-ust/lttng-bytecode.c @@ -274,9 +274,9 @@ int apply_context_reloc(struct bytecode_runtime *runtime, enum bytecode_op bytecode_op) { struct load_op *op; - struct lttng_ctx_field *ctx_field; + struct lttng_ust_ctx_field *ctx_field; int idx; - struct lttng_ctx **pctx = runtime->p.priv->pctx; + struct lttng_ust_ctx **pctx = runtime->p.priv->pctx; dbg_printf("Apply context reloc: %u %s\n", reloc_offset, context_name); @@ -302,7 +302,7 @@ int apply_context_reloc(struct bytecode_runtime *runtime, return -EINVAL; /* Get context return type */ - ctx_field = &(*pctx)->fields[idx]; + ctx_field = (*pctx)->fields[idx]; op = (struct load_op *) &runtime->code[reloc_offset]; switch (bytecode_op) { @@ -311,7 +311,7 @@ int apply_context_reloc(struct bytecode_runtime *runtime, struct field_ref *field_ref; field_ref = (struct field_ref *) op->data; - switch (ctx_field->event_field.type.atype) { + switch (ctx_field->event_field->type.atype) { case atype_integer: case atype_enum_nestable: op->op = BYTECODE_OP_GET_CONTEXT_REF_S64; @@ -397,7 +397,7 @@ int bytecode_is_linked(struct lttng_ust_bytecode_node *bytecode, */ static int link_bytecode(const struct lttng_ust_event_desc *event_desc, - struct lttng_ctx **ctx, + struct lttng_ust_ctx **ctx, struct lttng_ust_bytecode_node *bytecode, struct cds_list_head *bytecode_runtime_head, struct cds_list_head *insert_loc) @@ -530,7 +530,7 @@ void lttng_bytecode_capture_sync_state(struct lttng_ust_bytecode_runtime *runtim * instance are name matching (or glob pattern matching). */ void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc, - struct lttng_ctx **ctx, + struct lttng_ust_ctx **ctx, struct cds_list_head *instance_bytecode_head, struct cds_list_head *enabler_bytecode_head) { diff --git a/liblttng-ust/lttng-context-cgroup-ns.c b/liblttng-ust/lttng-context-cgroup-ns.c index 681eea49..2ba495b3 100644 --- a/liblttng-ust/lttng-context-cgroup-ns.c +++ b/liblttng-ust/lttng-context-cgroup-ns.c @@ -90,7 +90,7 @@ void lttng_context_cgroup_ns_reset(void) } static -size_t cgroup_ns_get_size(struct lttng_ctx_field *field, size_t offset) +size_t cgroup_ns_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -100,7 +100,7 @@ size_t cgroup_ns_get_size(struct lttng_ctx_field *field, size_t offset) } static -void cgroup_ns_record(struct lttng_ctx_field *field, +void cgroup_ns_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -112,15 +112,15 @@ void cgroup_ns_record(struct lttng_ctx_field *field, } static -void cgroup_ns_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void cgroup_ns_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_cgroup_ns(); } -int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx) +int lttng_add_cgroup_ns_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -129,14 +129,14 @@ int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "cgroup_ns"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "cgroup_ns"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = cgroup_ns_get_size; field->record = cgroup_ns_record; field->get_value = cgroup_ns_get_value; diff --git a/liblttng-ust/lttng-context-cpu-id.c b/liblttng-ust/lttng-context-cpu-id.c index 2a8f2812..1221bf6c 100644 --- a/liblttng-ust/lttng-context-cpu-id.c +++ b/liblttng-ust/lttng-context-cpu-id.c @@ -24,7 +24,7 @@ #include "context-internal.h" static -size_t cpu_id_get_size(struct lttng_ctx_field *field, size_t offset) +size_t cpu_id_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -34,7 +34,7 @@ size_t cpu_id_get_size(struct lttng_ctx_field *field, size_t offset) } static -void cpu_id_record(struct lttng_ctx_field *field, +void cpu_id_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -46,15 +46,15 @@ void cpu_id_record(struct lttng_ctx_field *field, } static -void cpu_id_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void cpu_id_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = lttng_ust_get_cpu(); } -int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx) +int lttng_add_cpu_id_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -63,14 +63,14 @@ int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "cpu_id"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(int) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(int) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(int); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "cpu_id"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(int) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(int) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(int); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = cpu_id_get_size; field->record = cpu_id_record; field->get_value = cpu_id_get_value; diff --git a/liblttng-ust/lttng-context-ip.c b/liblttng-ust/lttng-context-ip.c index af4f02ac..20c6fef3 100644 --- a/liblttng-ust/lttng-context-ip.c +++ b/liblttng-ust/lttng-context-ip.c @@ -17,7 +17,7 @@ #include "context-internal.h" static -size_t ip_get_size(struct lttng_ctx_field *field, size_t offset) +size_t ip_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -27,7 +27,7 @@ size_t ip_get_size(struct lttng_ctx_field *field, size_t offset) } static -void ip_record(struct lttng_ctx_field *field, +void ip_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -38,9 +38,9 @@ void ip_record(struct lttng_ctx_field *field, chan->ops->event_write(ctx, &ip, sizeof(ip)); } -int lttng_add_ip_to_ctx(struct lttng_ctx **ctx) +int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -49,14 +49,14 @@ int lttng_add_ip_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "ip"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(void *) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(void *) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(void *); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 16; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "ip"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(void *) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(void *) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(void *); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 16; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = ip_get_size; field->record = ip_record; lttng_context_update(*ctx); diff --git a/liblttng-ust/lttng-context-ipc-ns.c b/liblttng-ust/lttng-context-ipc-ns.c index f265c397..a9d2024d 100644 --- a/liblttng-ust/lttng-context-ipc-ns.c +++ b/liblttng-ust/lttng-context-ipc-ns.c @@ -89,7 +89,7 @@ void lttng_context_ipc_ns_reset(void) } static -size_t ipc_ns_get_size(struct lttng_ctx_field *field, size_t offset) +size_t ipc_ns_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -99,7 +99,7 @@ size_t ipc_ns_get_size(struct lttng_ctx_field *field, size_t offset) } static -void ipc_ns_record(struct lttng_ctx_field *field, +void ipc_ns_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -111,15 +111,15 @@ void ipc_ns_record(struct lttng_ctx_field *field, } static -void ipc_ns_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void ipc_ns_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_ipc_ns(); } -int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx) +int lttng_add_ipc_ns_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -128,14 +128,14 @@ int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "ipc_ns"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "ipc_ns"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = ipc_ns_get_size; field->record = ipc_ns_record; field->get_value = ipc_ns_get_value; diff --git a/liblttng-ust/lttng-context-mnt-ns.c b/liblttng-ust/lttng-context-mnt-ns.c index 4ce93845..930bd618 100644 --- a/liblttng-ust/lttng-context-mnt-ns.c +++ b/liblttng-ust/lttng-context-mnt-ns.c @@ -72,7 +72,7 @@ void lttng_context_mnt_ns_reset(void) } static -size_t mnt_ns_get_size(struct lttng_ctx_field *field, size_t offset) +size_t mnt_ns_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -82,7 +82,7 @@ size_t mnt_ns_get_size(struct lttng_ctx_field *field, size_t offset) } static -void mnt_ns_record(struct lttng_ctx_field *field, +void mnt_ns_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -94,15 +94,15 @@ void mnt_ns_record(struct lttng_ctx_field *field, } static -void mnt_ns_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void mnt_ns_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_mnt_ns(); } -int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx) +int lttng_add_mnt_ns_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -111,14 +111,14 @@ int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "mnt_ns"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "mnt_ns"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = mnt_ns_get_size; field->record = mnt_ns_record; field->get_value = mnt_ns_get_value; diff --git a/liblttng-ust/lttng-context-net-ns.c b/liblttng-ust/lttng-context-net-ns.c index 08b61340..c7022b54 100644 --- a/liblttng-ust/lttng-context-net-ns.c +++ b/liblttng-ust/lttng-context-net-ns.c @@ -89,7 +89,7 @@ void lttng_context_net_ns_reset(void) } static -size_t net_ns_get_size(struct lttng_ctx_field *field, size_t offset) +size_t net_ns_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -99,7 +99,7 @@ size_t net_ns_get_size(struct lttng_ctx_field *field, size_t offset) } static -void net_ns_record(struct lttng_ctx_field *field, +void net_ns_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -111,15 +111,15 @@ void net_ns_record(struct lttng_ctx_field *field, } static -void net_ns_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void net_ns_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_net_ns(); } -int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx) +int lttng_add_net_ns_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -128,14 +128,14 @@ int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "net_ns"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "net_ns"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = net_ns_get_size; field->record = net_ns_record; field->get_value = net_ns_get_value; diff --git a/liblttng-ust/lttng-context-perf-counters.c b/liblttng-ust/lttng-context-perf-counters.c index 74e07dc5..fa283324 100644 --- a/liblttng-ust/lttng-context-perf-counters.c +++ b/liblttng-ust/lttng-context-perf-counters.c @@ -156,7 +156,7 @@ void lttng_perf_unlock(void) } static -size_t perf_counter_get_size(struct lttng_ctx_field *field, size_t offset) +size_t perf_counter_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -425,18 +425,18 @@ struct lttng_perf_counter_thread_field * } static -uint64_t wrapper_perf_counter_read(struct lttng_ctx_field *field) +uint64_t wrapper_perf_counter_read(struct lttng_ust_ctx_field *field) { struct lttng_perf_counter_field *perf_field; struct lttng_perf_counter_thread_field *perf_thread_field; - perf_field = field->u.perf_counter; + perf_field = (struct lttng_perf_counter_field *) field->priv; perf_thread_field = get_thread_field(perf_field); return arch_read_perf_counter(perf_thread_field); } static -void perf_counter_record(struct lttng_ctx_field *field, +void perf_counter_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -448,8 +448,8 @@ void perf_counter_record(struct lttng_ctx_field *field, } static -void perf_counter_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void perf_counter_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = wrapper_perf_counter_read(field); } @@ -482,13 +482,13 @@ void lttng_destroy_perf_thread_key(void *_key) /* Called with UST lock held */ static -void lttng_destroy_perf_counter_field(struct lttng_ctx_field *field) +void lttng_destroy_perf_counter_field(struct lttng_ust_ctx_field *field) { struct lttng_perf_counter_field *perf_field; struct lttng_perf_counter_thread_field *pos, *p; - free((char *) field->event_field.name); - perf_field = field->u.perf_counter; + free((char *) field->event_field->name); + perf_field = (struct lttng_perf_counter_field *) field->priv; /* * This put is performed when no threads can concurrently * perform a "get" concurrently, thanks to urcu-bp grace @@ -526,9 +526,9 @@ int perf_get_exclude_kernel(void) int lttng_add_perf_counter_to_ctx(uint32_t type, uint64_t config, const char *name, - struct lttng_ctx **ctx) + struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; struct lttng_perf_counter_field *perf_field; char *name_alloc; int ret; @@ -555,17 +555,17 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, field->destroy = lttng_destroy_perf_counter_field; - field->event_field.name = name_alloc; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = + field->event_field->name = name_alloc; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(uint64_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = + field->event_field->type.u.integer.alignment = lttng_alignof(uint64_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = + field->event_field->type.u.integer.signedness = lttng_is_signed_type(uint64_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = perf_counter_get_size; field->record = perf_counter_record; field->get_value = perf_counter_get_value; @@ -574,7 +574,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, perf_field->attr.config = config; perf_field->attr.exclude_kernel = perf_get_exclude_kernel(); CDS_INIT_LIST_HEAD(&perf_field->thread_field_list); - field->u.perf_counter = perf_field; + field->priv = perf_field; /* Ensure that this perf counter can be used in this process. */ ret = open_perf_fd(&perf_field->attr); diff --git a/liblttng-ust/lttng-context-pid-ns.c b/liblttng-ust/lttng-context-pid-ns.c index df7a764d..4ab4246c 100644 --- a/liblttng-ust/lttng-context-pid-ns.c +++ b/liblttng-ust/lttng-context-pid-ns.c @@ -75,7 +75,7 @@ void lttng_context_pid_ns_reset(void) } static -size_t pid_ns_get_size(struct lttng_ctx_field *field, size_t offset) +size_t pid_ns_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -85,7 +85,7 @@ size_t pid_ns_get_size(struct lttng_ctx_field *field, size_t offset) } static -void pid_ns_record(struct lttng_ctx_field *field, +void pid_ns_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -97,15 +97,15 @@ void pid_ns_record(struct lttng_ctx_field *field, } static -void pid_ns_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void pid_ns_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_pid_ns(); } -int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx) +int lttng_add_pid_ns_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -114,14 +114,14 @@ int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "pid_ns"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "pid_ns"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = pid_ns_get_size; field->record = pid_ns_record; field->get_value = pid_ns_get_value; diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index d467b43c..9e24cb06 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -65,13 +65,13 @@ void lttng_ust_context_procname_reset(void) } static -size_t procname_get_size(struct lttng_ctx_field *field, size_t offset) +size_t procname_get_size(struct lttng_ust_ctx_field *field, size_t offset) { return LTTNG_UST_ABI_PROCNAME_LEN; } static -void procname_record(struct lttng_ctx_field *field, +void procname_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -82,8 +82,8 @@ void procname_record(struct lttng_ctx_field *field, } static -void procname_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void procname_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.str = wrapper_getprocname(); } @@ -91,9 +91,9 @@ void procname_get_value(struct lttng_ctx_field *field, static const struct lttng_type procname_array_elem_type = __type_integer(char, BYTE_ORDER, 10, UTF8); -int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) +int lttng_add_procname_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -102,11 +102,11 @@ int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "procname"; - field->event_field.type.atype = atype_array_nestable; - field->event_field.type.u.array_nestable.elem_type = + field->event_field->name = "procname"; + field->event_field->type.atype = atype_array_nestable; + field->event_field->type.u.array_nestable.elem_type = &procname_array_elem_type; - field->event_field.type.u.array_nestable.length = LTTNG_UST_ABI_PROCNAME_LEN; + field->event_field->type.u.array_nestable.length = LTTNG_UST_ABI_PROCNAME_LEN; field->get_size = procname_get_size; field->record = procname_record; field->get_value = procname_get_value; diff --git a/liblttng-ust/lttng-context-provider.c b/liblttng-ust/lttng-context-provider.c index 46a18c9f..fe67c2ee 100644 --- a/liblttng-ust/lttng-context-provider.c +++ b/liblttng-ust/lttng-context-provider.c @@ -120,42 +120,64 @@ end: * metadata describing the context. */ int lttng_ust_add_app_context_to_ctx_rcu(const char *name, - struct lttng_ctx **ctx) + struct lttng_ust_ctx **ctx) { struct lttng_ust_context_provider *provider; - struct lttng_ctx_field new_field; + struct lttng_ust_ctx_field *new_field = NULL; int ret; if (*ctx && lttng_find_context(*ctx, name)) return -EEXIST; - /* - * For application context, add it by expanding - * ctx array. - */ - memset(&new_field, 0, sizeof(new_field)); - new_field.field_name = strdup(name); - if (!new_field.field_name) - return -ENOMEM; - new_field.event_field.name = new_field.field_name; - new_field.event_field.type.atype = atype_dynamic; + new_field = zmalloc(sizeof(struct lttng_ust_ctx_field)); + if (!new_field) { + ret = -ENOMEM; + goto error_field_alloc; + } + new_field->struct_size = sizeof(struct lttng_ust_ctx_field); + new_field->event_field = zmalloc(sizeof(struct lttng_ust_event_field)); + if (!new_field->event_field) { + ret = -ENOMEM; + goto error_event_field_alloc; + } + new_field->field_name = strdup(name); + if (!new_field->field_name) { + ret = -ENOMEM; + goto error_field_name_alloc; + } + new_field->event_field->name = new_field->field_name; + new_field->event_field->type.atype = atype_dynamic; /* * If provider is not found, we add the context anyway, but * it will provide a dummy context. */ provider = lookup_provider_by_name(name); if (provider) { - new_field.get_size = provider->get_size; - new_field.record = provider->record; - new_field.get_value = provider->get_value; + new_field->get_size = provider->get_size; + new_field->record = provider->record; + new_field->get_value = provider->get_value; } else { - new_field.get_size = lttng_ust_dummy_get_size; - new_field.record = lttng_ust_dummy_record; - new_field.get_value = lttng_ust_dummy_get_value; + new_field->get_size = lttng_ust_dummy_get_size; + new_field->record = lttng_ust_dummy_record; + new_field->get_value = lttng_ust_dummy_get_value; } - ret = lttng_context_add_rcu(ctx, &new_field); + /* + * For application context, add it by expanding + * ctx array. Ownership of new_field is passed to the callee on + * success. + */ + ret = lttng_context_add_rcu(ctx, new_field); if (ret) { - free(new_field.field_name); + free(new_field->field_name); + free(new_field->event_field); + free(new_field); return ret; } return 0; + +error_field_name_alloc: + free(new_field->event_field); +error_event_field_alloc: + free(new_field); +error_field_alloc: + return ret; } diff --git a/liblttng-ust/lttng-context-pthread-id.c b/liblttng-ust/lttng-context-pthread-id.c index 2502f75f..162b2cf4 100644 --- a/liblttng-ust/lttng-context-pthread-id.c +++ b/liblttng-ust/lttng-context-pthread-id.c @@ -16,7 +16,7 @@ #include "context-internal.h" static -size_t pthread_id_get_size(struct lttng_ctx_field *field, size_t offset) +size_t pthread_id_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -26,7 +26,7 @@ size_t pthread_id_get_size(struct lttng_ctx_field *field, size_t offset) } static -void pthread_id_record(struct lttng_ctx_field *field, +void pthread_id_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -38,15 +38,15 @@ void pthread_id_record(struct lttng_ctx_field *field, } static -void pthread_id_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void pthread_id_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = (unsigned long) pthread_self(); } -int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx) +int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -55,14 +55,14 @@ int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "pthread_id"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(unsigned long); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "pthread_id"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(unsigned long); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = pthread_id_get_size; field->record = pthread_id_record; field->get_value = pthread_id_get_value; diff --git a/liblttng-ust/lttng-context-time-ns.c b/liblttng-ust/lttng-context-time-ns.c index a2365cd2..8edc1fae 100644 --- a/liblttng-ust/lttng-context-time-ns.c +++ b/liblttng-ust/lttng-context-time-ns.c @@ -88,7 +88,7 @@ void lttng_context_time_ns_reset(void) } static -size_t time_ns_get_size(struct lttng_ctx_field *field, size_t offset) +size_t time_ns_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -98,7 +98,7 @@ size_t time_ns_get_size(struct lttng_ctx_field *field, size_t offset) } static -void time_ns_record(struct lttng_ctx_field *field, +void time_ns_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -110,15 +110,15 @@ void time_ns_record(struct lttng_ctx_field *field, } static -void time_ns_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void time_ns_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_time_ns(); } -int lttng_add_time_ns_to_ctx(struct lttng_ctx **ctx) +int lttng_add_time_ns_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -127,14 +127,14 @@ int lttng_add_time_ns_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "time_ns"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "time_ns"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = time_ns_get_size; field->record = time_ns_record; field->get_value = time_ns_get_value; diff --git a/liblttng-ust/lttng-context-user-ns.c b/liblttng-ust/lttng-context-user-ns.c index d2a79b52..fccf70f2 100644 --- a/liblttng-ust/lttng-context-user-ns.c +++ b/liblttng-ust/lttng-context-user-ns.c @@ -72,7 +72,7 @@ void lttng_context_user_ns_reset(void) } static -size_t user_ns_get_size(struct lttng_ctx_field *field, size_t offset) +size_t user_ns_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -82,7 +82,7 @@ size_t user_ns_get_size(struct lttng_ctx_field *field, size_t offset) } static -void user_ns_record(struct lttng_ctx_field *field, +void user_ns_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -94,15 +94,15 @@ void user_ns_record(struct lttng_ctx_field *field, } static -void user_ns_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void user_ns_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_user_ns(); } -int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx) +int lttng_add_user_ns_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -111,14 +111,14 @@ int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "user_ns"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "user_ns"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = user_ns_get_size; field->record = user_ns_record; field->get_value = user_ns_get_value; diff --git a/liblttng-ust/lttng-context-uts-ns.c b/liblttng-ust/lttng-context-uts-ns.c index 2cd23939..af8aad46 100644 --- a/liblttng-ust/lttng-context-uts-ns.c +++ b/liblttng-ust/lttng-context-uts-ns.c @@ -90,7 +90,7 @@ void lttng_context_uts_ns_reset(void) } static -size_t uts_ns_get_size(struct lttng_ctx_field *field, size_t offset) +size_t uts_ns_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -100,7 +100,7 @@ size_t uts_ns_get_size(struct lttng_ctx_field *field, size_t offset) } static -void uts_ns_record(struct lttng_ctx_field *field, +void uts_ns_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -112,15 +112,15 @@ void uts_ns_record(struct lttng_ctx_field *field, } static -void uts_ns_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void uts_ns_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_uts_ns(); } -int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx) +int lttng_add_uts_ns_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -129,14 +129,14 @@ int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "uts_ns"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "uts_ns"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = uts_ns_get_size; field->record = uts_ns_record; field->get_value = uts_ns_get_value; diff --git a/liblttng-ust/lttng-context-vegid.c b/liblttng-ust/lttng-context-vegid.c index 436b566a..a7bac4e2 100644 --- a/liblttng-ust/lttng-context-vegid.c +++ b/liblttng-ust/lttng-context-vegid.c @@ -61,7 +61,7 @@ void lttng_context_vegid_reset(void) } static -size_t vegid_get_size(struct lttng_ctx_field *field, size_t offset) +size_t vegid_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -71,7 +71,7 @@ size_t vegid_get_size(struct lttng_ctx_field *field, size_t offset) } static -void vegid_record(struct lttng_ctx_field *field, +void vegid_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -83,15 +83,15 @@ void vegid_record(struct lttng_ctx_field *field, } static -void vegid_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void vegid_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_vegid(); } -int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx) +int lttng_add_vegid_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -100,14 +100,14 @@ int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "vegid"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "vegid"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = vegid_get_size; field->record = vegid_record; field->get_value = vegid_get_value; diff --git a/liblttng-ust/lttng-context-veuid.c b/liblttng-ust/lttng-context-veuid.c index 3d630575..e2174503 100644 --- a/liblttng-ust/lttng-context-veuid.c +++ b/liblttng-ust/lttng-context-veuid.c @@ -61,7 +61,7 @@ void lttng_context_veuid_reset(void) } static -size_t veuid_get_size(struct lttng_ctx_field *field, size_t offset) +size_t veuid_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -71,7 +71,7 @@ size_t veuid_get_size(struct lttng_ctx_field *field, size_t offset) } static -void veuid_record(struct lttng_ctx_field *field, +void veuid_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -83,15 +83,15 @@ void veuid_record(struct lttng_ctx_field *field, } static -void veuid_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void veuid_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_veuid(); } -int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx) +int lttng_add_veuid_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -100,14 +100,14 @@ int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "veuid"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "veuid"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = veuid_get_size; field->record = veuid_record; field->get_value = veuid_get_value; diff --git a/liblttng-ust/lttng-context-vgid.c b/liblttng-ust/lttng-context-vgid.c index 04933405..7bc12544 100644 --- a/liblttng-ust/lttng-context-vgid.c +++ b/liblttng-ust/lttng-context-vgid.c @@ -61,7 +61,7 @@ void lttng_context_vgid_reset(void) } static -size_t vgid_get_size(struct lttng_ctx_field *field, size_t offset) +size_t vgid_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -71,7 +71,7 @@ size_t vgid_get_size(struct lttng_ctx_field *field, size_t offset) } static -void vgid_record(struct lttng_ctx_field *field, +void vgid_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -83,15 +83,15 @@ void vgid_record(struct lttng_ctx_field *field, } static -void vgid_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void vgid_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_vgid(); } -int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx) +int lttng_add_vgid_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -100,14 +100,14 @@ int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "vgid"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "vgid"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = vgid_get_size; field->record = vgid_record; field->get_value = vgid_get_value; diff --git a/liblttng-ust/lttng-context-vpid.c b/liblttng-ust/lttng-context-vpid.c index f41119f9..ddcfb8ad 100644 --- a/liblttng-ust/lttng-context-vpid.c +++ b/liblttng-ust/lttng-context-vpid.c @@ -45,7 +45,7 @@ void lttng_context_vpid_reset(void) } static -size_t vpid_get_size(struct lttng_ctx_field *field, size_t offset) +size_t vpid_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -55,7 +55,7 @@ size_t vpid_get_size(struct lttng_ctx_field *field, size_t offset) } static -void vpid_record(struct lttng_ctx_field *field, +void vpid_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -66,15 +66,15 @@ void vpid_record(struct lttng_ctx_field *field, } static -void vpid_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void vpid_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = wrapper_getvpid(); } -int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx) +int lttng_add_vpid_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -83,14 +83,14 @@ int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "vpid"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "vpid"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = vpid_get_size; field->record = vpid_record; field->get_value = vpid_get_value; diff --git a/liblttng-ust/lttng-context-vsgid.c b/liblttng-ust/lttng-context-vsgid.c index 0778d875..0d7b0426 100644 --- a/liblttng-ust/lttng-context-vsgid.c +++ b/liblttng-ust/lttng-context-vsgid.c @@ -65,7 +65,7 @@ void lttng_context_vsgid_reset(void) } static -size_t vsgid_get_size(struct lttng_ctx_field *field, size_t offset) +size_t vsgid_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -75,7 +75,7 @@ size_t vsgid_get_size(struct lttng_ctx_field *field, size_t offset) } static -void vsgid_record(struct lttng_ctx_field *field, +void vsgid_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -87,15 +87,15 @@ void vsgid_record(struct lttng_ctx_field *field, } static -void vsgid_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void vsgid_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_vsgid(); } -int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx) +int lttng_add_vsgid_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -104,14 +104,14 @@ int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "vsgid"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "vsgid"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(gid_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(gid_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = vsgid_get_size; field->record = vsgid_record; field->get_value = vsgid_get_value; diff --git a/liblttng-ust/lttng-context-vsuid.c b/liblttng-ust/lttng-context-vsuid.c index ecc239bc..0428292a 100644 --- a/liblttng-ust/lttng-context-vsuid.c +++ b/liblttng-ust/lttng-context-vsuid.c @@ -65,7 +65,7 @@ void lttng_context_vsuid_reset(void) } static -size_t vsuid_get_size(struct lttng_ctx_field *field, size_t offset) +size_t vsuid_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -75,7 +75,7 @@ size_t vsuid_get_size(struct lttng_ctx_field *field, size_t offset) } static -void vsuid_record(struct lttng_ctx_field *field, +void vsuid_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -87,15 +87,15 @@ void vsuid_record(struct lttng_ctx_field *field, } static -void vsuid_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void vsuid_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_vsuid(); } -int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx) +int lttng_add_vsuid_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -104,14 +104,14 @@ int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "vsuid"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "vsuid"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = vsuid_get_size; field->record = vsuid_record; field->get_value = vsuid_get_value; diff --git a/liblttng-ust/lttng-context-vtid.c b/liblttng-ust/lttng-context-vtid.c index 15c11edd..9b91e57c 100644 --- a/liblttng-ust/lttng-context-vtid.c +++ b/liblttng-ust/lttng-context-vtid.c @@ -36,7 +36,7 @@ void lttng_context_vtid_reset(void) } static -size_t vtid_get_size(struct lttng_ctx_field *field, size_t offset) +size_t vtid_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -59,7 +59,7 @@ pid_t wrapper_getvtid(void) } static -void vtid_record(struct lttng_ctx_field *field, +void vtid_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -70,15 +70,15 @@ void vtid_record(struct lttng_ctx_field *field, } static -void vtid_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void vtid_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = wrapper_getvtid(); } -int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx) +int lttng_add_vtid_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -87,14 +87,14 @@ int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "vtid"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "vtid"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = vtid_get_size; field->record = vtid_record; field->get_value = vtid_get_value; diff --git a/liblttng-ust/lttng-context-vuid.c b/liblttng-ust/lttng-context-vuid.c index f4bcb5c9..754218d2 100644 --- a/liblttng-ust/lttng-context-vuid.c +++ b/liblttng-ust/lttng-context-vuid.c @@ -61,7 +61,7 @@ void lttng_context_vuid_reset(void) } static -size_t vuid_get_size(struct lttng_ctx_field *field, size_t offset) +size_t vuid_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -71,7 +71,7 @@ size_t vuid_get_size(struct lttng_ctx_field *field, size_t offset) } static -void vuid_record(struct lttng_ctx_field *field, +void vuid_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -83,15 +83,15 @@ void vuid_record(struct lttng_ctx_field *field, } static -void vuid_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void vuid_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->u.s64 = get_vuid(); } -int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx) +int lttng_add_vuid_to_ctx(struct lttng_ust_ctx **ctx) { - struct lttng_ctx_field *field; + struct lttng_ust_ctx_field *field; field = lttng_append_context(ctx); if (!field) @@ -100,14 +100,14 @@ int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx) lttng_remove_context_field(ctx, field); return -EEXIST; } - field->event_field.name = "vuid"; - field->event_field.type.atype = atype_integer; - field->event_field.type.u.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field.type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field.type.u.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field.type.u.integer.reverse_byte_order = 0; - field->event_field.type.u.integer.base = 10; - field->event_field.type.u.integer.encoding = lttng_encode_none; + field->event_field->name = "vuid"; + field->event_field->type.atype = atype_integer; + field->event_field->type.u.integer.size = sizeof(uid_t) * CHAR_BIT; + field->event_field->type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; + field->event_field->type.u.integer.signedness = lttng_is_signed_type(uid_t); + field->event_field->type.u.integer.reverse_byte_order = 0; + field->event_field->type.u.integer.base = 10; + field->event_field->type.u.integer.encoding = lttng_encode_none; field->get_size = vuid_get_size; field->record = vuid_record; field->get_value = vuid_get_value; diff --git a/liblttng-ust/lttng-context.c b/liblttng-ust/lttng-context.c index dc6e13b3..8ed9bbd4 100644 --- a/liblttng-ust/lttng-context.c +++ b/liblttng-ust/lttng-context.c @@ -26,7 +26,7 @@ * same context performed by the same thread return the same result. */ -int lttng_find_context(struct lttng_ctx *ctx, const char *name) +int lttng_find_context(struct lttng_ust_ctx *ctx, const char *name) { unsigned int i; const char *subname; @@ -38,15 +38,15 @@ int lttng_find_context(struct lttng_ctx *ctx, const char *name) } for (i = 0; i < ctx->nr_fields; i++) { /* Skip allocated (but non-initialized) contexts */ - if (!ctx->fields[i].event_field.name) + if (!ctx->fields[i]->event_field->name) continue; - if (!strcmp(ctx->fields[i].event_field.name, subname)) + if (!strcmp(ctx->fields[i]->event_field->name, subname)) return 1; } return 0; } -int lttng_get_context_index(struct lttng_ctx *ctx, const char *name) +int lttng_get_context_index(struct lttng_ust_ctx *ctx, const char *name) { unsigned int i; const char *subname; @@ -60,23 +60,23 @@ int lttng_get_context_index(struct lttng_ctx *ctx, const char *name) } for (i = 0; i < ctx->nr_fields; i++) { /* Skip allocated (but non-initialized) contexts */ - if (!ctx->fields[i].event_field.name) + if (!ctx->fields[i]->event_field->name) continue; - if (!strcmp(ctx->fields[i].event_field.name, subname)) + if (!strcmp(ctx->fields[i]->event_field->name, subname)) return i; } return -1; } -static int lttng_find_context_provider(struct lttng_ctx *ctx, const char *name) +static int lttng_find_context_provider(struct lttng_ust_ctx *ctx, const char *name) { unsigned int i; for (i = 0; i < ctx->nr_fields; i++) { /* Skip allocated (but non-initialized) contexts */ - if (!ctx->fields[i].event_field.name) + if (!ctx->fields[i]->event_field->name) continue; - if (!strncmp(ctx->fields[i].event_field.name, name, + if (!strncmp(ctx->fields[i]->event_field->name, name, strlen(name))) return 1; } @@ -85,65 +85,100 @@ static int lttng_find_context_provider(struct lttng_ctx *ctx, const char *name) /* * Note: as we append context information, the pointer location may change. + * lttng_add_context leaves the new last context initialized to NULL. */ -struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p) +static +int lttng_add_context(struct lttng_ust_ctx **ctx_p) { - struct lttng_ctx_field *field; - struct lttng_ctx *ctx; + struct lttng_ust_ctx *ctx; if (!*ctx_p) { - *ctx_p = zmalloc(sizeof(struct lttng_ctx)); + *ctx_p = zmalloc(sizeof(struct lttng_ust_ctx)); if (!*ctx_p) - return NULL; + return -ENOMEM; + (*ctx_p)->struct_size = sizeof(struct lttng_ust_ctx); (*ctx_p)->largest_align = 1; } ctx = *ctx_p; if (ctx->nr_fields + 1 > ctx->allocated_fields) { - struct lttng_ctx_field *new_fields; + struct lttng_ust_ctx_field **new_fields; ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields); - new_fields = zmalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field)); + new_fields = zmalloc(ctx->allocated_fields * sizeof(*new_fields)); if (!new_fields) - return NULL; + return -ENOMEM; + /* Copy pointers */ if (ctx->fields) memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields); free(ctx->fields); ctx->fields = new_fields; } - field = &ctx->fields[ctx->nr_fields]; ctx->nr_fields++; + return 0; +} + +struct lttng_ust_ctx_field *lttng_append_context(struct lttng_ust_ctx **ctx_p) +{ + struct lttng_ust_ctx_field *field; + int ret; + + field = zmalloc(sizeof(struct lttng_ust_ctx_field)); + if (!field) + goto error_alloc_field; + field->struct_size = sizeof(struct lttng_ust_ctx_field); + field->event_field = zmalloc(sizeof(struct lttng_ust_event_field)); + if (!field->event_field) + goto error_alloc_event_field; + field->event_field->struct_size = sizeof(struct lttng_ust_event_field); + + ret = lttng_add_context(ctx_p); + if (ret) + goto error_add_context; + (*ctx_p)->fields[(*ctx_p)->nr_fields - 1] = field; return field; + +error_add_context: + free(field->event_field); +error_alloc_event_field: + free(field); +error_alloc_field: + return NULL; } -int lttng_context_add_rcu(struct lttng_ctx **ctx_p, - const struct lttng_ctx_field *f) +/* + * Takes ownership of @f on success. + */ +int lttng_context_add_rcu(struct lttng_ust_ctx **ctx_p, + struct lttng_ust_ctx_field *f) { - struct lttng_ctx *old_ctx = *ctx_p, *new_ctx = NULL; - struct lttng_ctx_field *new_fields = NULL; - struct lttng_ctx_field *nf; + struct lttng_ust_ctx *old_ctx = *ctx_p, *new_ctx = NULL; + struct lttng_ust_ctx_field **new_fields = NULL; + int ret; if (old_ctx) { - new_ctx = zmalloc(sizeof(struct lttng_ctx)); + new_ctx = zmalloc(sizeof(struct lttng_ust_ctx)); if (!new_ctx) return -ENOMEM; + new_ctx->struct_size = sizeof(struct lttng_ust_ctx); *new_ctx = *old_ctx; - new_fields = zmalloc(new_ctx->allocated_fields - * sizeof(struct lttng_ctx_field)); + new_fields = zmalloc(new_ctx->allocated_fields * sizeof(*new_fields)); if (!new_fields) { free(new_ctx); return -ENOMEM; } + /* Copy pointers */ memcpy(new_fields, old_ctx->fields, sizeof(*old_ctx->fields) * old_ctx->nr_fields); new_ctx->fields = new_fields; } - nf = lttng_append_context(&new_ctx); - if (!nf) { + ret = lttng_add_context(&new_ctx); + if (ret) { free(new_fields); free(new_ctx); - return -ENOMEM; + return ret; } - *nf = *f; + /* Taking ownership of f. */ + (*ctx_p)->fields[(*ctx_p)->nr_fields - 1] = f; lttng_context_update(new_ctx); lttng_ust_rcu_assign_pointer(*ctx_p, new_ctx); lttng_ust_urcu_synchronize_rcu(); @@ -158,7 +193,7 @@ int lttng_context_add_rcu(struct lttng_ctx **ctx_p, * lttng_context_update() should be called at least once between context * modification and trace start. */ -void lttng_context_update(struct lttng_ctx *ctx) +void lttng_context_update(struct lttng_ust_ctx *ctx) { int i; size_t largest_align = 8; /* in bits */ @@ -167,7 +202,7 @@ void lttng_context_update(struct lttng_ctx *ctx) struct lttng_type *type; size_t field_align = 8; - type = &ctx->fields[i].event_field.type; + type = &ctx->fields[i]->event_field->type; switch (type->atype) { case atype_integer: field_align = type->u.integer.alignment; @@ -234,28 +269,30 @@ void lttng_context_update(struct lttng_ctx *ctx) /* * Remove last context field. */ -void lttng_remove_context_field(struct lttng_ctx **ctx_p, - struct lttng_ctx_field *field) +void lttng_remove_context_field(struct lttng_ust_ctx **ctx_p, + struct lttng_ust_ctx_field *field) { - struct lttng_ctx *ctx; + struct lttng_ust_ctx *ctx; ctx = *ctx_p; ctx->nr_fields--; - assert(&ctx->fields[ctx->nr_fields] == field); + assert(ctx->fields[ctx->nr_fields] == field); assert(field->field_name == NULL); - memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field)); + ctx->fields[ctx->nr_fields] = NULL; } -void lttng_destroy_context(struct lttng_ctx *ctx) +void lttng_destroy_context(struct lttng_ust_ctx *ctx) { int i; if (!ctx) return; for (i = 0; i < ctx->nr_fields; i++) { - if (ctx->fields[i].destroy) - ctx->fields[i].destroy(&ctx->fields[i]); - free(ctx->fields[i].field_name); + if (ctx->fields[i]->destroy) + ctx->fields[i]->destroy(ctx->fields[i]); + free(ctx->fields[i]->field_name); + free(ctx->fields[i]->event_field); + free(ctx->fields[i]); } free(ctx->fields); free(ctx); @@ -273,18 +310,18 @@ void lttng_destroy_context(struct lttng_ctx *ctx) * a single RCU read-side critical section see either all old, or all * new handlers. */ -int lttng_ust_context_set_provider_rcu(struct lttng_ctx **_ctx, +int lttng_ust_context_set_provider_rcu(struct lttng_ust_ctx **_ctx, const char *name, - size_t (*get_size)(struct lttng_ctx_field *field, size_t offset), - void (*record)(struct lttng_ctx_field *field, + size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset), + void (*record)(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan), - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value)) + void (*get_value)(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value)) { int i, ret; - struct lttng_ctx *ctx = *_ctx, *new_ctx; - struct lttng_ctx_field *new_fields; + struct lttng_ust_ctx *ctx = *_ctx, *new_ctx; + struct lttng_ust_ctx_field **new_fields; if (!ctx || !lttng_find_context_provider(ctx, name)) return 0; @@ -294,21 +331,23 @@ int lttng_ust_context_set_provider_rcu(struct lttng_ctx **_ctx, new_ctx = zmalloc(sizeof(*new_ctx)); if (!new_ctx) return -ENOMEM; + new_ctx->struct_size = sizeof(*new_ctx); *new_ctx = *ctx; new_fields = zmalloc(sizeof(*new_fields) * ctx->allocated_fields); if (!new_fields) { ret = -ENOMEM; goto field_error; } + /* Copy pointers */ memcpy(new_fields, ctx->fields, sizeof(*new_fields) * ctx->allocated_fields); for (i = 0; i < ctx->nr_fields; i++) { - if (strncmp(new_fields[i].event_field.name, + if (strncmp(new_fields[i]->event_field->name, name, strlen(name)) != 0) continue; - new_fields[i].get_size = get_size; - new_fields[i].record = record; - new_fields[i].get_value = get_value; + new_fields[i]->get_size = get_size; + new_fields[i]->record = record; + new_fields[i]->get_value = get_value; } new_ctx->fields = new_fields; lttng_ust_rcu_assign_pointer(*_ctx, new_ctx); @@ -322,7 +361,7 @@ field_error: return ret; } -int lttng_context_init_all(struct lttng_ctx **ctx) +int lttng_context_init_all(struct lttng_ust_ctx **ctx) { int ret; diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index 4af0bc6d..03554894 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -516,7 +516,7 @@ int lttng_create_all_event_enums(size_t nr_fields, static int lttng_create_all_ctx_enums(size_t nr_fields, - const struct lttng_ctx_field *ctx_fields, + struct lttng_ust_ctx_field **ctx_fields, struct lttng_session *session) { size_t i; @@ -524,7 +524,7 @@ int lttng_create_all_ctx_enums(size_t nr_fields, /* For each field, ensure enum is part of the session. */ for (i = 0; i < nr_fields; i++) { - const struct lttng_type *type = &ctx_fields[i].event_field.type; + const struct lttng_type *type = &ctx_fields[i]->event_field->type; ret = lttng_create_enum_check(type, session); if (ret) @@ -570,8 +570,8 @@ int lttng_session_enable(struct lttng_session *session) * we need to use. */ cds_list_for_each_entry(chan, &session->priv->chan_head, node) { - const struct lttng_ctx *ctx; - const struct lttng_ctx_field *fields = NULL; + const struct lttng_ust_ctx *ctx; + struct lttng_ust_ctx_field **fields = NULL; size_t nr_fields = 0; uint32_t chan_id; @@ -1546,7 +1546,7 @@ int lttng_event_notifier_enabler_attach_exclusion( int lttng_attach_context(struct lttng_ust_abi_context *context_param, union lttng_ust_abi_args *uargs, - struct lttng_ctx **ctx, struct lttng_session *session) + struct lttng_ust_ctx **ctx, struct lttng_session *session) { /* * We cannot attach a context after trace has been started for a @@ -1947,12 +1947,12 @@ void lttng_session_lazy_sync_event_enablers(struct lttng_session *session) * context (either app context callbacks, or dummy callbacks). */ void lttng_ust_context_set_session_provider(const char *name, - size_t (*get_size)(struct lttng_ctx_field *field, size_t offset), - void (*record)(struct lttng_ctx_field *field, + size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset), + void (*record)(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan), - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value)) + void (*get_value)(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value)) { struct lttng_ust_session_private *session_priv; @@ -1988,12 +1988,12 @@ void lttng_ust_context_set_session_provider(const char *name, * context (either app context callbacks, or dummy callbacks). */ void lttng_ust_context_set_event_notifier_group_provider(const char *name, - size_t (*get_size)(struct lttng_ctx_field *field, size_t offset), - void (*record)(struct lttng_ctx_field *field, + size_t (*get_size)(struct lttng_ust_ctx_field *field, size_t offset), + void (*record)(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan), - void (*get_value)(struct lttng_ctx_field *field, - struct lttng_ctx_value *value)) + void (*get_value)(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value)) { struct lttng_event_notifier_group *event_notifier_group; diff --git a/liblttng-ust/lttng-ring-buffer-client.h b/liblttng-ust/lttng-ring-buffer-client.h index 09d58c5f..31934b67 100644 --- a/liblttng-ust/lttng-ring-buffer-client.h +++ b/liblttng-ust/lttng-ring-buffer-client.h @@ -70,7 +70,7 @@ static inline uint64_t lib_ring_buffer_clock_read(struct lttng_ust_lib_ring_buff } static inline -size_t ctx_get_aligned_size(size_t offset, struct lttng_ctx *ctx, +size_t ctx_get_aligned_size(size_t offset, struct lttng_ust_ctx *ctx, size_t ctx_len) { size_t orig_offset = offset; @@ -83,7 +83,7 @@ size_t ctx_get_aligned_size(size_t offset, struct lttng_ctx *ctx, } static inline -void ctx_get_struct_size(struct lttng_ctx *ctx, size_t *ctx_len, +void ctx_get_struct_size(struct lttng_ust_ctx *ctx, size_t *ctx_len, enum app_ctx_mode mode) { int i; @@ -95,9 +95,9 @@ void ctx_get_struct_size(struct lttng_ctx *ctx, size_t *ctx_len, } for (i = 0; i < ctx->nr_fields; i++) { if (mode == APP_CTX_ENABLED) { - offset += ctx->fields[i].get_size(&ctx->fields[i], offset); + offset += ctx->fields[i]->get_size(ctx->fields[i], offset); } else { - if (lttng_context_is_app(ctx->fields[i].event_field.name)) { + if (lttng_context_is_app(ctx->fields[i]->event_field->name)) { /* * Before UST 2.8, we cannot use the * application context, because we @@ -108,9 +108,9 @@ void ctx_get_struct_size(struct lttng_ctx *ctx, size_t *ctx_len, * concurrently with application context * register/unregister. */ - offset += lttng_ust_dummy_get_size(&ctx->fields[i], offset); + offset += lttng_ust_dummy_get_size(ctx->fields[i], offset); } else { - offset += ctx->fields[i].get_size(&ctx->fields[i], offset); + offset += ctx->fields[i]->get_size(ctx->fields[i], offset); } } } @@ -120,7 +120,7 @@ void ctx_get_struct_size(struct lttng_ctx *ctx, size_t *ctx_len, static inline void ctx_record(struct lttng_ust_lib_ring_buffer_ctx *bufctx, struct lttng_channel *chan, - struct lttng_ctx *ctx, + struct lttng_ust_ctx *ctx, enum app_ctx_mode mode) { int i; @@ -130,9 +130,9 @@ void ctx_record(struct lttng_ust_lib_ring_buffer_ctx *bufctx, lib_ring_buffer_align_ctx(bufctx, ctx->largest_align); for (i = 0; i < ctx->nr_fields; i++) { if (mode == APP_CTX_ENABLED) { - ctx->fields[i].record(&ctx->fields[i], bufctx, chan); + ctx->fields[i]->record(ctx->fields[i], bufctx, chan); } else { - if (lttng_context_is_app(ctx->fields[i].event_field.name)) { + if (lttng_context_is_app(ctx->fields[i]->event_field->name)) { /* * Before UST 2.8, we cannot use the * application context, because we @@ -143,9 +143,9 @@ void ctx_record(struct lttng_ust_lib_ring_buffer_ctx *bufctx, * concurrently with application context * register/unregister. */ - lttng_ust_dummy_record(&ctx->fields[i], bufctx, chan); + lttng_ust_dummy_record(ctx->fields[i], bufctx, chan); } else { - ctx->fields[i].record(&ctx->fields[i], bufctx, chan); + ctx->fields[i]->record(ctx->fields[i], bufctx, chan); } } } diff --git a/liblttng-ust/lttng-tracer-core.h b/liblttng-ust/lttng-tracer-core.h index 59b2700e..325fb5f9 100644 --- a/liblttng-ust/lttng-tracer-core.h +++ b/liblttng-ust/lttng-tracer-core.h @@ -28,9 +28,9 @@ struct lttng_session; struct lttng_channel; struct lttng_event; -struct lttng_ctx_field; +struct lttng_ust_ctx_field; struct lttng_ust_lib_ring_buffer_ctx; -struct lttng_ctx_value; +struct lttng_ust_ctx_value; struct lttng_ust_event_notifier; __attribute__((visibility("hidden"))) @@ -88,15 +88,15 @@ __attribute__((visibility("hidden"))) ssize_t lttng_ust_read(int fd, void *buf, size_t len); __attribute__((visibility("hidden"))) -size_t lttng_ust_dummy_get_size(struct lttng_ctx_field *field, size_t offset); +size_t lttng_ust_dummy_get_size(struct lttng_ust_ctx_field *field, size_t offset); __attribute__((visibility("hidden"))) -void lttng_ust_dummy_record(struct lttng_ctx_field *field, +void lttng_ust_dummy_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan); __attribute__((visibility("hidden"))) -void lttng_ust_dummy_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value); +void lttng_ust_dummy_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value); __attribute__((visibility("hidden"))) void lttng_event_notifier_notification_send( diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 79531763..3ed0f198 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -379,7 +379,7 @@ static long lttng_abi_add_context(int objd, struct lttng_ust_abi_context *context_param, union lttng_ust_abi_args *uargs, - struct lttng_ctx **ctx, struct lttng_session *session) + struct lttng_ust_ctx **ctx, struct lttng_session *session) { return lttng_attach_context(context_param, uargs, ctx, session); } diff --git a/liblttng-ust/ust-core.c b/liblttng-ust/ust-core.c index 1f291c4e..19f62840 100644 --- a/liblttng-ust/ust-core.c +++ b/liblttng-ust/ust-core.c @@ -105,7 +105,7 @@ struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session, return NULL; } -size_t lttng_ust_dummy_get_size(struct lttng_ctx_field *field, size_t offset) +size_t lttng_ust_dummy_get_size(struct lttng_ust_ctx_field *field, size_t offset) { size_t size = 0; @@ -114,7 +114,7 @@ size_t lttng_ust_dummy_get_size(struct lttng_ctx_field *field, size_t offset) return size; } -void lttng_ust_dummy_record(struct lttng_ctx_field *field, +void lttng_ust_dummy_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -124,8 +124,8 @@ void lttng_ust_dummy_record(struct lttng_ctx_field *field, chan->ops->event_write(ctx, &sel_char, sizeof(sel_char)); } -void lttng_ust_dummy_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void lttng_ust_dummy_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { value->sel = LTTNG_UST_DYNAMIC_TYPE_NONE; } diff --git a/liblttng-ust/ust-events-internal.h b/liblttng-ust/ust-events-internal.h index 505db0b1..e568d5ee 100644 --- a/liblttng-ust/ust-events-internal.h +++ b/liblttng-ust/ust-events-internal.h @@ -79,7 +79,7 @@ struct lttng_event_enabler { * Unused, but kept around to make it explicit that the tracer can do * it. */ - struct lttng_ctx *ctx; + struct lttng_ust_ctx *ctx; }; struct lttng_event_notifier_enabler { @@ -220,7 +220,7 @@ struct lttng_event_notifier_group { struct cds_list_head enablers_head; struct cds_list_head event_notifiers_head; /* list of event_notifiers */ struct lttng_ust_event_notifier_ht event_notifiers_ht; /* hashtable of event_notifiers */ - struct lttng_ctx *ctx; /* contexts for filters. */ + struct lttng_ust_ctx *ctx; /* contexts for filters. */ struct lttng_counter *error_counter; size_t error_counter_len; @@ -278,7 +278,7 @@ struct lttng_ust_bytecode_runtime_private { * Pointer to a URCU-protected pointer owned by an `struct * lttng_session`or `struct lttng_event_notifier_group`. */ - struct lttng_ctx **pctx; + struct lttng_ust_ctx **pctx; }; struct lttng_ust_session_private { @@ -303,7 +303,7 @@ struct lttng_ust_session_private { /* New UST 2.8 */ struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */ struct cds_list_head enums_head; - struct lttng_ctx *ctx; /* contexts for filters. */ + struct lttng_ust_ctx *ctx; /* contexts for filters. */ }; struct lttng_enum { @@ -395,7 +395,7 @@ int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler, */ __attribute__((visibility("hidden"))) void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc, - struct lttng_ctx **ctx, + struct lttng_ust_ctx **ctx, struct cds_list_head *instance_bytecode_runtime_head, struct cds_list_head *enabler_bytecode_runtime_head); @@ -498,7 +498,7 @@ __attribute__((visibility("hidden"))) int lttng_add_perf_counter_to_ctx(uint32_t type, uint64_t config, const char *name, - struct lttng_ctx **ctx); + struct lttng_ust_ctx **ctx); __attribute__((visibility("hidden"))) int lttng_perf_counter_init(void); @@ -512,7 +512,7 @@ static inline int lttng_add_perf_counter_to_ctx(uint32_t type, uint64_t config, const char *name, - struct lttng_ctx **ctx) + struct lttng_ust_ctx **ctx) { return -ENOSYS; } diff --git a/tests/compile/test-app-ctx/hello.c b/tests/compile/test-app-ctx/hello.c index 3d026095..20df12db 100644 --- a/tests/compile/test-app-ctx/hello.c +++ b/tests/compile/test-app-ctx/hello.c @@ -41,7 +41,7 @@ void test_inc_count(void) } static -size_t test_get_size(struct lttng_ctx_field *field, size_t offset) +size_t test_get_size(struct lttng_ust_ctx_field *field, size_t offset) { int sel = test_count % _NR_LTTNG_UST_DYNAMIC_TYPES; size_t size = 0; @@ -102,7 +102,7 @@ size_t test_get_size(struct lttng_ctx_field *field, size_t offset) } static -void test_record(struct lttng_ctx_field *field, +void test_record(struct lttng_ust_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { @@ -206,8 +206,8 @@ void test_record(struct lttng_ctx_field *field, } static -void test_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void test_get_value(struct lttng_ust_ctx_field *field, + struct lttng_ust_ctx_value *value) { int sel = test_count % _NR_LTTNG_UST_DYNAMIC_TYPES; @@ -254,6 +254,7 @@ void test_get_value(struct lttng_ctx_field *field, } struct lttng_ust_context_provider myprovider = { + .struct_size = sizeof(struct lttng_ust_context_provider), .name = "$app.myprovider", .get_size = test_get_size, .record = test_record, -- 2.34.1