X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-filter-interpreter.c;h=6c77cfe983f97fb02eb8e827166ab0d61087f6e7;hb=d97f9b785f05c29dbabb57da9a32c8c4317da8d3;hp=49daa211e1a59b3e24d59bfa00faceda9de2115b;hpb=d8d2416dab454962b90222ba46c82cdce0c666a4;p=lttng-ust.git diff --git a/liblttng-ust/lttng-filter-interpreter.c b/liblttng-ust/lttng-filter-interpreter.c index 49daa211..6c77cfe9 100644 --- a/liblttng-ust/lttng-filter-interpreter.c +++ b/liblttng-ust/lttng-filter-interpreter.c @@ -220,6 +220,9 @@ LABEL_##name #endif +#define IS_INTEGER_REGISTER(reg_type) \ + (reg_type == REG_U64 || reg_type == REG_S64) + static int context_get_index(struct lttng_ctx *ctx, struct load_ptr *ptr, uint32_t idx) @@ -521,7 +524,7 @@ static int dynamic_load_field(struct estack_entry *stack_top) case OBJECT_TYPE_U8: dbg_printf("op load field u8\n"); stack_top->u.v = *(uint8_t *) stack_top->u.ptr.ptr; - stack_top->type = REG_S64; + stack_top->type = REG_U64; break; case OBJECT_TYPE_U16: { @@ -532,7 +535,7 @@ static int dynamic_load_field(struct estack_entry *stack_top) if (stack_top->u.ptr.rev_bo) tmp = bswap_16(tmp); stack_top->u.v = tmp; - stack_top->type = REG_S64; + stack_top->type = REG_U64; break; } case OBJECT_TYPE_U32: @@ -544,7 +547,7 @@ static int dynamic_load_field(struct estack_entry *stack_top) if (stack_top->u.ptr.rev_bo) tmp = bswap_32(tmp); stack_top->u.v = tmp; - stack_top->type = REG_S64; + stack_top->type = REG_U64; break; } case OBJECT_TYPE_U64: @@ -556,7 +559,7 @@ static int dynamic_load_field(struct estack_entry *stack_top) if (stack_top->u.ptr.rev_bo) tmp = bswap_64(tmp); stack_top->u.v = tmp; - stack_top->type = REG_S64; + stack_top->type = REG_U64; break; } case OBJECT_TYPE_DOUBLE: @@ -794,6 +797,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, /* Handle dynamic typing. */ switch (estack_ax_t) { case REG_S64: + case REG_U64: retval = !!estack_ax_v; break; case REG_DOUBLE: @@ -827,9 +831,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { /* Dynamic typing. */ switch (estack_ax_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_EQ_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_EQ_DOUBLE_S64); @@ -846,7 +852,8 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, break; case REG_DOUBLE: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_EQ_S64_DOUBLE); case REG_DOUBLE: JUMP_TO(FILTER_OP_EQ_DOUBLE); @@ -864,6 +871,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, case REG_STRING: switch (estack_bx_t) { case REG_S64: /* Fall-through */ + case REG_U64: /* Fall-through */ case REG_DOUBLE: ret = -EINVAL; goto end; @@ -881,6 +889,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, case REG_STAR_GLOB_STRING: switch (estack_bx_t) { case REG_S64: /* Fall-through */ + case REG_U64: /* Fall-through */ case REG_DOUBLE: ret = -EINVAL; goto end; @@ -907,9 +916,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { /* Dynamic typing. */ switch (estack_ax_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_NE_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_NE_DOUBLE_S64); @@ -926,7 +937,8 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, break; case REG_DOUBLE: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_NE_S64_DOUBLE); case REG_DOUBLE: JUMP_TO(FILTER_OP_NE_DOUBLE); @@ -944,6 +956,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, case REG_STRING: switch (estack_bx_t) { case REG_S64: /* Fall-through */ + case REG_U64: case REG_DOUBLE: ret = -EINVAL; goto end; @@ -961,6 +974,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, case REG_STAR_GLOB_STRING: switch (estack_bx_t) { case REG_S64: /* Fall-through */ + case REG_U64: case REG_DOUBLE: ret = -EINVAL; goto end; @@ -987,9 +1001,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { /* Dynamic typing. */ switch (estack_ax_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_GT_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_GT_DOUBLE_S64); @@ -1006,7 +1022,8 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, break; case REG_DOUBLE: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_GT_S64_DOUBLE); case REG_DOUBLE: JUMP_TO(FILTER_OP_GT_DOUBLE); @@ -1024,6 +1041,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, case REG_STRING: switch (estack_bx_t) { case REG_S64: /* Fall-through */ + case REG_U64: /* Fall-through */ case REG_DOUBLE: /* Fall-through */ case REG_STAR_GLOB_STRING: ret = -EINVAL; @@ -1048,9 +1066,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { /* Dynamic typing. */ switch (estack_ax_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_LT_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_LT_DOUBLE_S64); @@ -1067,7 +1087,8 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, break; case REG_DOUBLE: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_LT_S64_DOUBLE); case REG_DOUBLE: JUMP_TO(FILTER_OP_LT_DOUBLE); @@ -1085,6 +1106,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, case REG_STRING: switch (estack_bx_t) { case REG_S64: /* Fall-through */ + case REG_U64: /* Fall-through */ case REG_DOUBLE: /* Fall-through */ case REG_STAR_GLOB_STRING: ret = -EINVAL; @@ -1109,9 +1131,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { /* Dynamic typing. */ switch (estack_ax_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_GE_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_GE_DOUBLE_S64); @@ -1128,7 +1152,8 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, break; case REG_DOUBLE: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_GE_S64_DOUBLE); case REG_DOUBLE: JUMP_TO(FILTER_OP_GE_DOUBLE); @@ -1146,6 +1171,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, case REG_STRING: switch (estack_bx_t) { case REG_S64: /* Fall-through */ + case REG_U64: /* Fall-through */ case REG_DOUBLE: /* Fall-through */ case REG_STAR_GLOB_STRING: ret = -EINVAL; @@ -1170,9 +1196,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { /* Dynamic typing. */ switch (estack_ax_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_LE_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_LE_DOUBLE_S64); @@ -1189,7 +1217,8 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, break; case REG_DOUBLE: switch (estack_bx_t) { - case REG_S64: + case REG_S64: /* Fall-through */ + case REG_U64: JUMP_TO(FILTER_OP_LE_S64_DOUBLE); case REG_DOUBLE: JUMP_TO(FILTER_OP_LE_DOUBLE); @@ -1207,6 +1236,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, case REG_STRING: switch (estack_bx_t) { case REG_S64: /* Fall-through */ + case REG_U64: /* Fall-through */ case REG_DOUBLE: /* Fall-through */ case REG_STAR_GLOB_STRING: ret = -EINVAL; @@ -1590,11 +1620,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { int64_t res; - /* Dynamic typing. */ - if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { + if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { ret = -EINVAL; goto end; } + /* Catch undefined behavior. */ if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) { ret = -EINVAL; @@ -1603,7 +1633,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, res = ((uint64_t) estack_bx_v >> (uint32_t) estack_ax_v); estack_pop(stack, top, ax, bx, ax_t, bx_t); estack_ax_v = res; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct binary_op); PO; } @@ -1611,11 +1641,11 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { int64_t res; - /* Dynamic typing. */ - if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { + if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { ret = -EINVAL; goto end; } + /* Catch undefined behavior. */ if (caa_unlikely(estack_ax_v < 0 || estack_ax_v >= 64)) { ret = -EINVAL; @@ -1624,7 +1654,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, res = ((uint64_t) estack_bx_v << (uint32_t) estack_ax_v); estack_pop(stack, top, ax, bx, ax_t, bx_t); estack_ax_v = res; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct binary_op); PO; } @@ -1632,8 +1662,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { int64_t res; - /* Dynamic typing. */ - if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { + if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { ret = -EINVAL; goto end; } @@ -1641,7 +1670,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, res = ((uint64_t) estack_bx_v & (uint64_t) estack_ax_v); estack_pop(stack, top, ax, bx, ax_t, bx_t); estack_ax_v = res; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct binary_op); PO; } @@ -1649,8 +1678,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { int64_t res; - /* Dynamic typing. */ - if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { + if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { ret = -EINVAL; goto end; } @@ -1658,7 +1686,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, res = ((uint64_t) estack_bx_v | (uint64_t) estack_ax_v); estack_pop(stack, top, ax, bx, ax_t, bx_t); estack_ax_v = res; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct binary_op); PO; } @@ -1666,8 +1694,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { int64_t res; - /* Dynamic typing. */ - if (estack_ax_t != REG_S64 || estack_bx_t != REG_S64) { + if (!IS_INTEGER_REGISTER(estack_ax_t) || !IS_INTEGER_REGISTER(estack_bx_t)) { ret = -EINVAL; goto end; } @@ -1675,7 +1702,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, res = ((uint64_t) estack_bx_v ^ (uint64_t) estack_ax_v); estack_pop(stack, top, ax, bx, ax_t, bx_t); estack_ax_v = res; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct binary_op); PO; } @@ -1686,6 +1713,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, /* Dynamic typing. */ switch (estack_ax_t) { case REG_S64: /* Fall-through. */ + case REG_U64: JUMP_TO(FILTER_OP_UNARY_PLUS_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_UNARY_PLUS_DOUBLE); @@ -1704,7 +1732,8 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { /* Dynamic typing. */ switch (estack_ax_t) { - case REG_S64: + case REG_S64: /* Fall-through. */ + case REG_U64: JUMP_TO(FILTER_OP_UNARY_MINUS_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_UNARY_MINUS_DOUBLE); @@ -1723,7 +1752,8 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { /* Dynamic typing. */ switch (estack_ax_t) { - case REG_S64: + case REG_S64: /* Fall-through. */ + case REG_U64: JUMP_TO(FILTER_OP_UNARY_NOT_S64); case REG_DOUBLE: JUMP_TO(FILTER_OP_UNARY_NOT_DOUBLE); @@ -1744,12 +1774,13 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, OP(FILTER_OP_UNARY_BIT_NOT): { /* Dynamic typing. */ - if (estack_ax_t != REG_S64) { + if (!IS_INTEGER_REGISTER(estack_ax_t)) { ret = -EINVAL; goto end; } estack_ax_v = ~(uint64_t) estack_ax_v; + estack_ax_t = REG_U64; next_pc += sizeof(struct unary_op); PO; } @@ -1775,6 +1806,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, OP(FILTER_OP_UNARY_NOT_S64): { estack_ax_v = !estack_ax_v; + estack_ax_t = REG_S64; next_pc += sizeof(struct unary_op); PO; } @@ -1791,7 +1823,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { struct logical_op *insn = (struct logical_op *) pc; - if (estack_ax_t != REG_S64) { + if (estack_ax_t != REG_S64 && estack_ax_t != REG_U64) { ret = -EINVAL; goto end; } @@ -1811,7 +1843,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, { struct logical_op *insn = (struct logical_op *) pc; - if (estack_ax_t != REG_S64) { + if (estack_ax_t != REG_S64 && estack_ax_t != REG_U64) { ret = -EINVAL; goto end; } @@ -1979,6 +2011,9 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, JUMP_TO(FILTER_OP_CAST_NOP); case REG_DOUBLE: JUMP_TO(FILTER_OP_CAST_DOUBLE_TO_S64); + case REG_U64: + estack_ax_t = REG_S64; + next_pc += sizeof(struct cast_op); case REG_STRING: /* Fall-through */ case REG_STAR_GLOB_STRING: ret = -EINVAL; @@ -2271,7 +2306,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, dbg_printf("op load field u8\n"); estack_ax_v = *(uint8_t *) estack_ax(stack, top)->u.ptr.ptr; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct load_op); PO; } @@ -2280,7 +2315,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, dbg_printf("op load field u16\n"); estack_ax_v = *(uint16_t *) estack_ax(stack, top)->u.ptr.ptr; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct load_op); PO; } @@ -2289,7 +2324,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, dbg_printf("op load field u32\n"); estack_ax_v = *(uint32_t *) estack_ax(stack, top)->u.ptr.ptr; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct load_op); PO; } @@ -2298,7 +2333,7 @@ uint64_t lttng_filter_interpret_bytecode(void *filter_data, dbg_printf("op load field u64\n"); estack_ax_v = *(uint64_t *) estack_ax(stack, top)->u.ptr.ptr; - estack_ax_t = REG_S64; + estack_ax_t = REG_U64; next_pc += sizeof(struct load_op); PO; }