+ break;
+ }
+ case FILTER_OP_CAST_NOP:
+ {
+ break;
+ }
+
+ }
+end:
+ return ret;
+}
+
+/*
+ * Return value:
+ * 0: success
+ * <0: error
+ */
+static
+int validate_instruction_all_contexts(struct bytecode_runtime *bytecode,
+ struct cds_lfht *merge_points,
+ const struct vreg reg[NR_REG],
+ void *start_pc,
+ void *pc)
+{
+ int ret;
+ unsigned long target_pc = pc - start_pc;
+ struct cds_lfht_iter iter;
+ struct cds_lfht_node *node;
+ unsigned long hash;
+
+ /* Validate the context resulting from the previous instruction */
+ ret = validate_instruction_context(bytecode, reg, start_pc, pc);
+ if (ret)
+ return ret;
+
+ /* Validate merge points */
+ hash = lttng_hash_mix((const void *) target_pc, sizeof(target_pc),
+ lttng_hash_seed);
+ cds_lfht_for_each_duplicate(merge_points, hash, lttng_hash_match,
+ (const void *) target_pc, &iter, node) {
+ struct lfht_mp_node *mp_node =
+ caa_container_of(node, struct lfht_mp_node, node);
+
+ dbg_printf("Filter: validate merge point at offset %lu\n",
+ target_pc);
+ ret = validate_instruction_context(bytecode, mp_node->reg,
+ start_pc, pc);
+ if (ret)
+ return ret;
+ /* Once validated, we can remove the merge point */
+ dbg_printf("Filter: remove one merge point at offset %lu\n",
+ target_pc);
+ ret = cds_lfht_del(merge_points, node);
+ assert(!ret);
+ }
+ return 0;
+}
+
+/*
+ * Return value:
+ * >0: going to next insn.
+ * 0: success, stop iteration.
+ * <0: error
+ */
+static
+int exec_insn(struct bytecode_runtime *bytecode,
+ struct cds_lfht *merge_points,
+ struct vreg reg[NR_REG],
+ void **_next_pc,
+ void *pc)
+{
+ int ret = 1;
+ void *next_pc = *_next_pc;
+
+ switch (*(filter_opcode_t *) pc) {
+ case FILTER_OP_UNKNOWN:
+ default:
+ {
+ ERR("unknown bytecode op %u\n",
+ (unsigned int) *(filter_opcode_t *) pc);
+ ret = -EINVAL;
+ goto end;
+ }
+
+ case FILTER_OP_RETURN:
+ {
+ ret = 0;
+ goto end;
+ }
+
+ /* binary */
+ case FILTER_OP_MUL:
+ case FILTER_OP_DIV:
+ case FILTER_OP_MOD:
+ case FILTER_OP_PLUS:
+ case FILTER_OP_MINUS:
+ case FILTER_OP_RSHIFT:
+ case FILTER_OP_LSHIFT:
+ case FILTER_OP_BIN_AND:
+ case FILTER_OP_BIN_OR:
+ case FILTER_OP_BIN_XOR:
+ {
+ ERR("unsupported bytecode op %u\n",
+ (unsigned int) *(filter_opcode_t *) pc);
+ ret = -EINVAL;
+ goto end;
+ }
+
+ case FILTER_OP_EQ:
+ case FILTER_OP_NE:
+ case FILTER_OP_GT:
+ case FILTER_OP_LT:
+ case FILTER_OP_GE:
+ case FILTER_OP_LE:
+ case FILTER_OP_EQ_STRING:
+ case FILTER_OP_NE_STRING:
+ case FILTER_OP_GT_STRING:
+ case FILTER_OP_LT_STRING:
+ case FILTER_OP_GE_STRING:
+ case FILTER_OP_LE_STRING:
+ case FILTER_OP_EQ_S64:
+ case FILTER_OP_NE_S64:
+ case FILTER_OP_GT_S64:
+ case FILTER_OP_LT_S64:
+ case FILTER_OP_GE_S64:
+ case FILTER_OP_LE_S64:
+ {
+ reg[REG_R0].type = REG_S64;
+ next_pc += sizeof(struct binary_op);
+ break;
+ }
+
+ case FILTER_OP_EQ_DOUBLE:
+ case FILTER_OP_NE_DOUBLE:
+ case FILTER_OP_GT_DOUBLE:
+ case FILTER_OP_LT_DOUBLE:
+ case FILTER_OP_GE_DOUBLE:
+ case FILTER_OP_LE_DOUBLE:
+ {
+ reg[REG_R0].type = REG_DOUBLE;
+ next_pc += sizeof(struct binary_op);
+ break;
+ }
+
+ /* unary */
+ case FILTER_OP_UNARY_PLUS:
+ case FILTER_OP_UNARY_MINUS:
+ case FILTER_OP_UNARY_NOT:
+ case FILTER_OP_UNARY_PLUS_S64:
+ case FILTER_OP_UNARY_MINUS_S64:
+ case FILTER_OP_UNARY_NOT_S64:
+ {
+ reg[REG_R0].type = REG_S64;
+ next_pc += sizeof(struct unary_op);
+ break;
+ }
+
+ case FILTER_OP_UNARY_PLUS_DOUBLE:
+ case FILTER_OP_UNARY_MINUS_DOUBLE:
+ case FILTER_OP_UNARY_NOT_DOUBLE:
+ {
+ reg[REG_R0].type = REG_DOUBLE;
+ next_pc += sizeof(struct unary_op);
+ break;
+ }
+
+ /* logical */
+ case FILTER_OP_AND:
+ case FILTER_OP_OR:
+ {
+ struct logical_op *insn = (struct logical_op *) pc;
+ int merge_ret;
+
+ /* Add merge point to table */
+ merge_ret = merge_point_add(merge_points, insn->skip_offset, reg);
+ if (merge_ret) {
+ ret = merge_ret;
+ goto end;