X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-bytecode.c;h=c52c79bb6ee35a3893e33e5b4607baae217b7312;hb=bd640d74f149ce079f81103221a8aaafca02ce04;hp=a6527ff191e1a34f706933523a1248c48d4c2321;hpb=621c07fc1b90c12ec997d539770da1937d11c450;p=lttng-ust.git diff --git a/liblttng-ust/lttng-bytecode.c b/liblttng-ust/lttng-bytecode.c index a6527ff1..c52c79bb 100644 --- a/liblttng-ust/lttng-bytecode.c +++ b/liblttng-ust/lttng-bytecode.c @@ -1,27 +1,9 @@ /* - * lttng-bytecode.c - * - * LTTng UST bytecode code. + * SPDX-License-Identifier: MIT * * Copyright (C) 2010-2016 Mathieu Desnoyers * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * LTTng UST bytecode code. */ #define _LGPL_SOURCE @@ -30,6 +12,7 @@ #include +#include "context-internal.h" #include "lttng-bytecode.h" #include "ust-events-internal.h" @@ -179,7 +162,7 @@ static const char *opnames[] = { [ BYTECODE_OP_RETURN_S64 ] = "RETURN_S64", }; -const char *print_op(enum bytecode_op op) +const char *lttng_bytecode_print_op(enum bytecode_op op) { if (op >= NR_BYTECODE_OPS) return "UNKNOWN"; @@ -298,21 +281,21 @@ int apply_context_reloc(struct bytecode_runtime *runtime, struct load_op *op; struct lttng_ctx_field *ctx_field; int idx; - struct lttng_ctx *ctx = *runtime->p.pctx; + struct lttng_ctx **pctx = runtime->p.priv->pctx; dbg_printf("Apply context reloc: %u %s\n", reloc_offset, context_name); /* Get context index */ - idx = lttng_get_context_index(ctx, context_name); + idx = lttng_get_context_index(*pctx, context_name); if (idx < 0) { if (lttng_context_is_app(context_name)) { int ret; ret = lttng_ust_add_app_context_to_ctx_rcu(context_name, - &ctx); + pctx); if (ret) return ret; - idx = lttng_get_context_index(ctx, context_name); + idx = lttng_get_context_index(*pctx, context_name); if (idx < 0) return -ENOENT; } else { @@ -324,7 +307,7 @@ int apply_context_reloc(struct bytecode_runtime *runtime, return -EINVAL; /* Get context return type */ - ctx_field = &ctx->fields[idx]; + ctx_field = &(*pctx)->fields[idx]; op = (struct load_op *) &runtime->code[reloc_offset]; switch (bytecode_op) { @@ -410,7 +393,7 @@ int bytecode_is_linked(struct lttng_ust_bytecode_node *bytecode, struct lttng_bytecode_runtime *bc_runtime; cds_list_for_each_entry(bc_runtime, bytecode_runtime_head, node) { - if (bc_runtime->bc == bytecode) + if (bc_runtime->priv->bc == bytecode) return 1; } return 0; @@ -428,6 +411,7 @@ int link_bytecode(const struct lttng_event_desc *event_desc, { int ret, offset, next_offset; struct bytecode_runtime *runtime = NULL; + struct lttng_ust_bytecode_runtime_private *runtime_priv = NULL; size_t runtime_alloc_len; if (!bytecode) @@ -445,8 +429,17 @@ int link_bytecode(const struct lttng_event_desc *event_desc, ret = -ENOMEM; goto alloc_error; } - runtime->p.bc = bytecode; - runtime->p.pctx = ctx; + runtime_priv = zmalloc(sizeof(struct lttng_ust_bytecode_runtime_private)); + if (!runtime_priv) { + free(runtime); + runtime = NULL; + ret = -ENOMEM; + goto alloc_error; + } + runtime->p.priv = runtime_priv; + runtime_priv->pub = runtime; + runtime_priv->bc = bytecode; + runtime_priv->pctx = ctx; runtime->len = bytecode->bc.reloc_offset; /* copy original bytecode */ memcpy(runtime->code, bytecode->bc.data, runtime->len); @@ -483,11 +476,14 @@ int link_bytecode(const struct lttng_event_desc *event_desc, case LTTNG_UST_BYTECODE_NODE_TYPE_FILTER: runtime->p.interpreter_funcs.filter = lttng_bytecode_filter_interpret; break; + case LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE: + runtime->p.interpreter_funcs.capture = lttng_bytecode_capture_interpret; + break; default: abort(); } - runtime->p.link_failed = 0; + runtime->p.priv->link_failed = 0; cds_list_add_rcu(&runtime->p.node, insert_loc); dbg_printf("Linking successful.\n"); return 0; @@ -497,11 +493,14 @@ link_error: case LTTNG_UST_BYTECODE_NODE_TYPE_FILTER: runtime->p.interpreter_funcs.filter = lttng_bytecode_filter_interpret_false; break; + case LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE: + runtime->p.interpreter_funcs.capture = lttng_bytecode_capture_interpret_false; + break; default: abort(); } - runtime->p.link_failed = 1; + runtime_priv->link_failed = 1; cds_list_add_rcu(&runtime->p.node, insert_loc); alloc_error: dbg_printf("Linking failed.\n"); @@ -510,14 +509,24 @@ alloc_error: void lttng_bytecode_filter_sync_state(struct lttng_bytecode_runtime *runtime) { - struct lttng_ust_bytecode_node *bc = runtime->bc; + struct lttng_ust_bytecode_node *bc = runtime->priv->bc; - if (!bc->enabler->enabled || runtime->link_failed) + if (!bc->enabler->enabled || runtime->priv->link_failed) runtime->interpreter_funcs.filter = lttng_bytecode_filter_interpret_false; else runtime->interpreter_funcs.filter = lttng_bytecode_filter_interpret; } +void lttng_bytecode_capture_sync_state(struct lttng_bytecode_runtime *runtime) +{ + struct lttng_ust_bytecode_node *bc = runtime->priv->bc; + + if (!bc->enabler->enabled || runtime->priv->link_failed) + runtime->interpreter_funcs.capture = lttng_bytecode_capture_interpret_false; + else + runtime->interpreter_funcs.capture = lttng_bytecode_capture_interpret; +} + /* * Given the lists of bytecode programs of an instance (trigger or event) and * of a matching enabler, try to link all the enabler's bytecode programs with @@ -546,7 +555,7 @@ void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, * linked with the instance. */ cds_list_for_each_entry(runtime, instance_bytecode_head, node) { - if (runtime->bc == enabler_bc) { + if (runtime->priv->bc == enabler_bc) { found = 1; break; } @@ -566,7 +575,7 @@ void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, */ cds_list_for_each_entry_reverse(runtime, instance_bytecode_head, node) { - if (runtime->bc->bc.seqnum <= enabler_bc->bc.seqnum) { + if (runtime->priv->bc->bc.seqnum <= enabler_bc->bc.seqnum) { /* insert here */ insert_loc = &runtime->node; goto add_within; @@ -602,6 +611,7 @@ void free_filter_runtime(struct cds_list_head *bytecode_runtime_head) cds_list_for_each_entry_safe(runtime, tmp, bytecode_runtime_head, p.node) { free(runtime->data); + free(runtime->p.priv); free(runtime); } } @@ -616,8 +626,3 @@ void lttng_free_event_notifier_filter_runtime( { free_filter_runtime(&event_notifier->filter_bytecode_runtime_head); } - -/* For backward compatibility. Leave those exported symbols in place. */ -void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime) -{ -}