X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust-java-agent%2Fjni%2Fcommon%2Flttng_ust_context.c;h=7ba4403a05588daee1176181671673de08fc4e9f;hb=4e48b5d2debaf6c0c598489c183cc6cb2125c8a3;hp=51b7c8e5f0617c295b1aff129eb35f49113404d0;hpb=5152f6df156d6ccb234965d1b3d26b167bd6b94e;p=lttng-ust.git 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 51b7c8e5..7ba4403a 100644 --- a/liblttng-ust-java-agent/jni/common/lttng_ust_context.c +++ b/liblttng-ust-java-agent/jni/common/lttng_ust_context.c @@ -44,6 +44,12 @@ struct lttng_ust_jni_ctx_entry { } value; } __attribute__((packed)); +struct lttng_ust_jni_provider { + struct lttng_ust_registered_context_provider *reg_provider; + char *name; + struct lttng_ust_context_provider provider; +}; + /* TLS passing context info from JNI to callbacks. */ __thread struct lttng_ust_jni_tls lttng_ust_context_info_tls; @@ -73,14 +79,14 @@ 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_ust_ctx_field *field, size_t offset) +static size_t get_size_cb(void *priv, size_t offset) { struct lttng_ust_jni_ctx_entry *jctx; size_t size = 0; - const char *ctx_name = field->event_field->name; + struct lttng_ust_jni_provider *jni_provider = (struct lttng_ust_jni_provider *) priv; + const char *ctx_name = jni_provider->name; enum lttng_ust_jni_type jni_type; - size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(char)); size += sizeof(char); /* tag */ jctx = lookup_ctx_by_name(ctx_name); @@ -135,12 +141,13 @@ static size_t get_size_cb(struct lttng_ust_ctx_field *field, size_t offset) } -static void record_cb(struct lttng_ust_ctx_field *field, +static void record_cb(void *priv, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_ust_channel_buffer *lttng_chan_buf) { struct lttng_ust_jni_ctx_entry *jctx; - const char *ctx_name = field->event_field->name; + struct lttng_ust_jni_provider *jni_provider = (struct lttng_ust_jni_provider *) priv; + const char *ctx_name = jni_provider->name; enum lttng_ust_jni_type jni_type; char sel_char; @@ -240,11 +247,11 @@ static void record_cb(struct lttng_ust_ctx_field *field, } } -static void get_value_cb(struct lttng_ust_ctx_field *field, - struct lttng_ust_ctx_value *value) +static void get_value_cb(void *priv, struct lttng_ust_ctx_value *value) { + struct lttng_ust_jni_provider *jni_provider = (struct lttng_ust_jni_provider *) priv; struct lttng_ust_jni_ctx_entry *jctx; - const char *ctx_name = field->event_field->name; + const char *ctx_name = jni_provider->name; enum lttng_ust_jni_type jni_type; jctx = lookup_ctx_by_name(ctx_name); @@ -318,6 +325,7 @@ JNIEXPORT jlong JNICALL Java_org_lttng_ust_agent_context_LttngContextApi_registe const char *provider_name_jstr; char *provider_name_cstr; struct lttng_ust_context_provider *provider; + struct lttng_ust_jni_provider *jni_provider; /* * Note: a "jlong" is 8 bytes on all architectures, whereas a * C "long" varies. @@ -334,26 +342,30 @@ JNIEXPORT jlong JNICALL Java_org_lttng_ust_agent_context_LttngContextApi_registe if (!provider_name_cstr) { goto error_strdup; } - provider = zmalloc(sizeof(*provider)); - if (!provider) { + jni_provider = zmalloc(sizeof(*jni_provider)); + if (!jni_provider) { goto error_provider; } + provider = &jni_provider->provider; provider->struct_size = sizeof(*provider); - provider->name = provider_name_cstr; + jni_provider->name = provider_name_cstr; + provider->name = jni_provider->name; provider->get_size = get_size_cb; provider->record = record_cb; provider->get_value = get_value_cb; + provider->priv = jni_provider; - if (lttng_ust_context_provider_register(provider)) { + jni_provider->reg_provider = lttng_ust_context_provider_register(provider); + if (!jni_provider->reg_provider) { goto error_register; } - provider_ref = (jlong) (long) provider; + provider_ref = (jlong) (long) jni_provider; return provider_ref; /* Error handling. */ error_register: - free(provider); + free(jni_provider); error_provider: free(provider_name_cstr); error_strdup: @@ -371,15 +383,15 @@ JNIEXPORT void JNICALL Java_org_lttng_ust_agent_context_LttngContextApi_unregist jobject jobj __attribute__((unused)), jlong provider_ref) { - struct lttng_ust_context_provider *provider = - (struct lttng_ust_context_provider*) (unsigned long) provider_ref; + struct lttng_ust_jni_provider *jni_provider = + (struct lttng_ust_jni_provider *) (unsigned long) provider_ref; - if (!provider) { + if (!jni_provider) { return; } - lttng_ust_context_provider_unregister(provider); + lttng_ust_context_provider_unregister(jni_provider->reg_provider); - free(provider->name); - free(provider); + free(jni_provider->name); + free(jni_provider); }