bytecode: generalize `struct lttng_ust_filter_bytecode_node`
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Mon, 13 Apr 2020 16:24:09 +0000 (12:24 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 26 Nov 2020 18:33:53 +0000 (13:33 -0500)
Rename `struct lttng_ust_filter_bytecode_node` to `struct
lttng_ust_bytecode_node` so it can be used by capture bytecode as well.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I0bb4ba4962601f1c83bf92494be4c47032f47db3

include/lttng/ust-events.h
liblttng-ust/lttng-events.c
liblttng-ust/lttng-filter.c
liblttng-ust/lttng-ust-abi.c
liblttng-ust/lttng-ust-comm.c
liblttng-ust/ust-events-internal.h

index 7fa992efd77d86a93464e73336c596703f773a4f..4c02ffa3307027ecb7a12a54ca11a25d5503cca7 100644 (file)
@@ -442,8 +442,9 @@ enum lttng_filter_ret {
  */
 struct lttng_bytecode_runtime {
        /* Associated bytecode */
-       struct lttng_ust_filter_bytecode_node *bc;
-       uint64_t (*filter)(void *filter_data, const char *filter_stack_data);
+       struct lttng_ust_bytecode_node *bc;
+       uint64_t (*filter)(void *interpreter_data,
+                       const char *interpreter_stack_data);
        int link_failed;
        struct cds_list_head node;      /* list of bytecode runtime in event */
        /*
index 495536762407cc9dbe01163472bc3d279f0036cd..716a764e85ac0bcda00e6470e0fd55ffd9c3e150 100644 (file)
@@ -365,7 +365,7 @@ void lttng_event_notifier_group_destroy(
 static
 void lttng_enabler_destroy(struct lttng_enabler *enabler)
 {
-       struct lttng_ust_filter_bytecode_node *filter_node, *tmp_filter_node;
+       struct lttng_ust_bytecode_node *filter_node, *tmp_filter_node;
        struct lttng_ust_excluder_node *excluder_node, *tmp_excluder_node;
 
        if (!enabler) {
@@ -1403,14 +1403,14 @@ int lttng_event_enabler_disable(struct lttng_event_enabler *event_enabler)
 
 static
 void _lttng_enabler_attach_filter_bytecode(struct lttng_enabler *enabler,
-               struct lttng_ust_filter_bytecode_node *bytecode)
+               struct lttng_ust_bytecode_node *bytecode)
 {
        bytecode->enabler = enabler;
        cds_list_add_tail(&bytecode->node, &enabler->filter_bytecode_head);
 }
 
 int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler *event_enabler,
-               struct lttng_ust_filter_bytecode_node *bytecode)
+               struct lttng_ust_bytecode_node *bytecode)
 {
        _lttng_enabler_attach_filter_bytecode(
                lttng_event_enabler_as_enabler(event_enabler), bytecode);
@@ -1457,7 +1457,7 @@ int lttng_event_notifier_enabler_disable(
 
 int lttng_event_notifier_enabler_attach_filter_bytecode(
                struct lttng_event_notifier_enabler *event_notifier_enabler,
-               struct lttng_ust_filter_bytecode_node *bytecode)
+               struct lttng_ust_bytecode_node *bytecode)
 {
        _lttng_enabler_attach_filter_bytecode(
                lttng_event_notifier_enabler_as_enabler(event_notifier_enabler),
index aa258e5c5d76a475999be9d4a96205ae783b5066..55d707b87d59259f022d3b8e50f65796cfdd8ad7 100644 (file)
@@ -404,13 +404,13 @@ int apply_reloc(const struct lttng_event_desc *event_desc,
 }
 
 static
-int bytecode_is_linked(struct lttng_ust_filter_bytecode_node *filter_bytecode,
+int bytecode_is_linked(struct lttng_ust_bytecode_node *bytecode,
                struct cds_list_head *bytecode_runtime_head)
 {
        struct lttng_bytecode_runtime *bc_runtime;
 
        cds_list_for_each_entry(bc_runtime, bytecode_runtime_head, node) {
-               if (bc_runtime->bc == filter_bytecode)
+               if (bc_runtime->bc == bytecode)
                        return 1;
        }
        return 0;
@@ -423,44 +423,44 @@ int bytecode_is_linked(struct lttng_ust_filter_bytecode_node *filter_bytecode,
 static
 int _lttng_filter_link_bytecode(const struct lttng_event_desc *event_desc,
                struct lttng_ctx **ctx,
-               struct lttng_ust_filter_bytecode_node *filter_bytecode,
+               struct lttng_ust_bytecode_node *bytecode,
                struct cds_list_head *insert_loc)
 {
        int ret, offset, next_offset;
        struct bytecode_runtime *runtime = NULL;
        size_t runtime_alloc_len;
 
-       if (!filter_bytecode)
+       if (!bytecode)
                return 0;
        /* Bytecode already linked */
-       if (bytecode_is_linked(filter_bytecode, insert_loc))
+       if (bytecode_is_linked(bytecode, insert_loc))
                return 0;
 
        dbg_printf("Linking...\n");
 
        /* We don't need the reloc table in the runtime */
-       runtime_alloc_len = sizeof(*runtime) + filter_bytecode->bc.reloc_offset;
+       runtime_alloc_len = sizeof(*runtime) + bytecode->bc.reloc_offset;
        runtime = zmalloc(runtime_alloc_len);
        if (!runtime) {
                ret = -ENOMEM;
                goto alloc_error;
        }
-       runtime->p.bc = filter_bytecode;
+       runtime->p.bc = bytecode;
        runtime->p.pctx = ctx;
-       runtime->len = filter_bytecode->bc.reloc_offset;
+       runtime->len = bytecode->bc.reloc_offset;
        /* copy original bytecode */
-       memcpy(runtime->code, filter_bytecode->bc.data, runtime->len);
+       memcpy(runtime->code, bytecode->bc.data, runtime->len);
        /*
         * apply relocs. Those are a uint16_t (offset in bytecode)
         * followed by a string (field name).
         */
-       for (offset = filter_bytecode->bc.reloc_offset;
-                       offset < filter_bytecode->bc.len;
+       for (offset = bytecode->bc.reloc_offset;
+                       offset < bytecode->bc.len;
                        offset = next_offset) {
                uint16_t reloc_offset =
-                       *(uint16_t *) &filter_bytecode->bc.data[offset];
+                       *(uint16_t *) &bytecode->bc.data[offset];
                const char *name =
-                       (const char *) &filter_bytecode->bc.data[offset + sizeof(uint16_t)];
+                       (const char *) &bytecode->bc.data[offset + sizeof(uint16_t)];
 
                ret = apply_reloc(event_desc, runtime, runtime->len, reloc_offset, name);
                if (ret) {
@@ -495,7 +495,7 @@ alloc_error:
 
 void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime)
 {
-       struct lttng_ust_filter_bytecode_node *bc = runtime->bc;
+       struct lttng_ust_bytecode_node *bc = runtime->bc;
 
        if (!bc->enabler->enabled || runtime->link_failed)
                runtime->filter = lttng_filter_interpret_bytecode_false;
@@ -511,7 +511,7 @@ void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
                struct cds_list_head *bytecode_runtime_head,
                struct lttng_enabler *enabler)
 {
-       struct lttng_ust_filter_bytecode_node *bc;
+       struct lttng_ust_bytecode_node *bc;
        struct lttng_bytecode_runtime *runtime;
 
        assert(event_desc);
@@ -559,12 +559,12 @@ void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
 }
 
 /*
- * We own the filter_bytecode if we return success.
+ * We own the bytecode if we return success.
  */
 int lttng_filter_enabler_attach_bytecode(struct lttng_enabler *enabler,
-               struct lttng_ust_filter_bytecode_node *filter_bytecode)
+               struct lttng_ust_bytecode_node *bytecode)
 {
-       cds_list_add(&filter_bytecode->node, &enabler->filter_bytecode_head);
+       cds_list_add(&bytecode->node, &enabler->filter_bytecode_head);
        return 0;
 }
 
index 1361f5cc0cb6e4b7939c5f03ba6676195c34e9a1..4f32f55511acd25b860ab9c4a11eebde8ca9acf4 100644 (file)
@@ -718,7 +718,7 @@ long lttng_event_notifier_enabler_cmd(int objd, unsigned int cmd, unsigned long
        case LTTNG_UST_FILTER:
                return lttng_event_notifier_enabler_attach_filter_bytecode(
                        event_notifier_enabler,
-                       (struct lttng_ust_filter_bytecode_node *) arg);
+                       (struct lttng_ust_bytecode_node *) arg);
        case LTTNG_UST_EXCLUSION:
                return lttng_event_notifier_enabler_attach_exclusion(event_notifier_enabler,
                        (struct lttng_ust_excluder_node *) arg);
@@ -1148,7 +1148,7 @@ long lttng_event_enabler_cmd(int objd, unsigned int cmd, unsigned long arg,
                int ret;
 
                ret = lttng_event_enabler_attach_filter_bytecode(enabler,
-                               (struct lttng_ust_filter_bytecode_node *) arg);
+                               (struct lttng_ust_bytecode_node *) arg);
                if (ret)
                        return ret;
                return 0;
index 530102b54aee47864dc463d63ce9d3b6dc774453..c48bd29a14d620a285b38f574a68a82b1ef439eb 100644 (file)
@@ -784,7 +784,7 @@ int handle_message(struct sock_info *sock_info,
        case LTTNG_UST_FILTER:
        {
                /* Receive filter data */
-               struct lttng_ust_filter_bytecode_node *bytecode;
+               struct lttng_ust_bytecode_node *bytecode;
 
                if (lum->u.filter.data_size > FILTER_BYTECODE_MAX_LEN) {
                        ERR("Filter data size is too large: %u bytes",
@@ -805,6 +805,7 @@ int handle_message(struct sock_info *sock_info,
                        ret = -ENOMEM;
                        goto error;
                }
+
                len = ustcomm_recv_unix_sock(sock, bytecode->bc.data,
                                lum->u.filter.data_size);
                switch (len) {
index eea9c666e72482de82e5c43ab5fdeeb4e57f410d..24393936f2df4b40f4ab48cbd099e28d8612fb2c 100644 (file)
@@ -51,14 +51,20 @@ struct lttng_event_notifier_enabler {
        uint64_t user_token;            /* User-provided token */
 };
 
-struct lttng_ust_filter_bytecode_node {
+enum lttng_ust_bytecode_node_type {
+       LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
+};
+
+struct lttng_ust_bytecode_node {
+       enum lttng_ust_bytecode_node_type type;
        struct cds_list_head node;
        struct lttng_enabler *enabler;
-       /*
-        * struct lttng_ust_filter_bytecode has var. sized array, must
-        * be last field.
-        */
-       struct lttng_ust_filter_bytecode bc;
+       struct  {
+               uint32_t len;
+               uint32_t reloc_offset;
+               uint64_t seqnum;
+               char data[];
+       } bc;
 };
 
 struct lttng_ust_excluder_node {
@@ -124,7 +130,7 @@ int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
 LTTNG_HIDDEN
 int lttng_event_enabler_attach_filter_bytecode(
                struct lttng_event_enabler *enabler,
-               struct lttng_ust_filter_bytecode_node *bytecode);
+               struct lttng_ust_bytecode_node *bytecode);
 
 /*
  * Attach an application context to an event enabler.
@@ -213,7 +219,7 @@ int lttng_event_notifier_enabler_disable(
 LTTNG_HIDDEN
 int lttng_event_notifier_enabler_attach_filter_bytecode(
                struct lttng_event_notifier_enabler *event_notifier_enabler,
-               struct lttng_ust_filter_bytecode_node *bytecode);
+               struct lttng_ust_bytecode_node *bytecode);
 
 /*
  * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
This page took 0.031566 seconds and 4 git commands to generate.