... | ... |
@@ -1529,6 +1529,13 @@ void cli_bytecode_destroy(struct cli_bc *bc) |
1529 | 1529 |
}\ |
1530 | 1530 |
val = map[o]; } while (0) |
1531 | 1531 |
|
1532 |
+#define MAPPTR(val) {\ |
|
1533 |
+ if ((val < bcfunc->numValues) && bcfunc->types[val]&0x8000)\ |
|
1534 |
+ val = map[val] | 0x40000000;\ |
|
1535 |
+ else\ |
|
1536 |
+ MAP(val);\ |
|
1537 |
+} |
|
1538 |
+ |
|
1532 | 1539 |
static inline int64_t ptr_compose(int32_t id, uint32_t offset) |
1533 | 1540 |
{ |
1534 | 1541 |
uint64_t i = id; |
... | ... |
@@ -1726,7 +1733,7 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
1726 | 1726 |
break; |
1727 | 1727 |
} |
1728 | 1728 |
case OP_BC_LOAD: |
1729 |
- MAP(inst->u.unaryop); |
|
1729 |
+ MAPPTR(inst->u.unaryop); |
|
1730 | 1730 |
break; |
1731 | 1731 |
case OP_BC_GEP1: |
1732 | 1732 |
case OP_BC_GEPZ: |
... | ... |
@@ -1745,10 +1752,9 @@ static int cli_bytecode_prepare_interpreter(struct cli_bc *bc) |
1745 | 1745 |
case OP_BC_MEMCPY: |
1746 | 1746 |
case OP_BC_MEMMOVE: |
1747 | 1747 |
case OP_BC_MEMCMP: |
1748 |
- MAP(inst->u.three[0]); |
|
1749 |
- MAP(inst->u.three[1]); |
|
1748 |
+ MAPPTR(inst->u.three[0]); |
|
1749 |
+ MAPPTR(inst->u.three[1]); |
|
1750 | 1750 |
MAP(inst->u.three[2]); |
1751 |
- /*TODO*/ |
|
1752 | 1751 |
break; |
1753 | 1752 |
case OP_BC_ISBIGENDIAN: |
1754 | 1753 |
/*TODO */ |
... | ... |
@@ -298,6 +298,15 @@ static always_inline struct stack_entry *pop_stack(struct stack *stack, |
298 | 298 |
}\ |
299 | 299 |
TRACE_R(x)\ |
300 | 300 |
} |
301 |
+#define READPOP(x, p, asize) {\ |
|
302 |
+ if ((p)&0x40000000) {\ |
|
303 |
+ unsigned ptr__ = (p)&0xbfffffff;\ |
|
304 |
+ CHECK_GT(func->numBytes, ptr__);\ |
|
305 |
+ x = (void*)&values[ptr__];\ |
|
306 |
+ } else {\ |
|
307 |
+ READP(x, p, asize)\ |
|
308 |
+ }\ |
|
309 |
+} |
|
301 | 310 |
|
302 | 311 |
#define READOLD8(x, p) CHECK_GT(func->numBytes, p);\ |
303 | 312 |
x = *(uint8_t*)&old_values[p];\ |
... | ... |
@@ -928,28 +937,28 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
928 | 928 |
case OP_BC_LOAD*5+1: |
929 | 929 |
{ |
930 | 930 |
uint8_t *ptr; |
931 |
- READP(ptr, inst->u.unaryop, 1); |
|
931 |
+ READPOP(ptr, inst->u.unaryop, 1); |
|
932 | 932 |
WRITE8(inst->dest, (*ptr)); |
933 | 933 |
break; |
934 | 934 |
} |
935 | 935 |
case OP_BC_LOAD*5+2: |
936 | 936 |
{ |
937 | 937 |
const union unaligned_16 *ptr; |
938 |
- READP(ptr, inst->u.unaryop, 2); |
|
938 |
+ READPOP(ptr, inst->u.unaryop, 2); |
|
939 | 939 |
WRITE16(inst->dest, (ptr->una_u16)); |
940 | 940 |
break; |
941 | 941 |
} |
942 | 942 |
case OP_BC_LOAD*5+3: |
943 | 943 |
{ |
944 | 944 |
const union unaligned_32 *ptr; |
945 |
- READP(ptr, inst->u.unaryop, 4); |
|
945 |
+ READPOP(ptr, inst->u.unaryop, 4); |
|
946 | 946 |
WRITE32(inst->dest, (ptr->una_u32)); |
947 | 947 |
break; |
948 | 948 |
} |
949 | 949 |
case OP_BC_LOAD*5+4: |
950 | 950 |
{ |
951 | 951 |
const union unaligned_64 *ptr; |
952 |
- READP(ptr, inst->u.unaryop, 8); |
|
952 |
+ READPOP(ptr, inst->u.unaryop, 8); |
|
953 | 953 |
WRITE64(inst->dest, (ptr->una_u64)); |
954 | 954 |
break; |
955 | 955 |
} |
... | ... |
@@ -1020,47 +1029,47 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct |
1020 | 1020 |
int32_t arg3; |
1021 | 1021 |
void *arg1, *arg2; |
1022 | 1022 |
READ32(arg3, inst->u.three[2]); |
1023 |
- READP(arg1, inst->u.three[0], arg3); |
|
1024 |
- READP(arg2, inst->u.three[1], arg3); |
|
1023 |
+ READPOP(arg1, inst->u.three[0], arg3); |
|
1024 |
+ READPOP(arg2, inst->u.three[1], arg3); |
|
1025 | 1025 |
WRITE32(inst->dest, memcmp(arg1, arg2, arg3)); |
1026 | 1026 |
break; |
1027 | 1027 |
} |
1028 | 1028 |
DEFINE_OP(OP_BC_MEMCPY) { |
1029 | 1029 |
int32_t arg3; |
1030 | 1030 |
void *arg1, *arg2, *resp; |
1031 |
- int64_t res; |
|
1031 |
+ int64_t res=0; |
|
1032 | 1032 |
|
1033 | 1033 |
READ32(arg3, inst->u.three[2]); |
1034 |
- READP(arg1, inst->u.three[0], arg3); |
|
1035 |
- READP(arg2, inst->u.three[1], arg3); |
|
1034 |
+ READPOP(arg1, inst->u.three[0], arg3); |
|
1035 |
+ READPOP(arg2, inst->u.three[1], arg3); |
|
1036 | 1036 |
memcpy(arg1, arg2, arg3); |
1037 |
- READ64(res, inst->u.three[0]); |
|
1037 |
+/* READ64(res, inst->u.three[0]);*/ |
|
1038 | 1038 |
WRITE64(inst->dest, res); |
1039 | 1039 |
break; |
1040 | 1040 |
} |
1041 | 1041 |
DEFINE_OP(OP_BC_MEMMOVE) { |
1042 | 1042 |
int32_t arg3; |
1043 | 1043 |
void *arg1, *arg2, *resp; |
1044 |
- int64_t res; |
|
1044 |
+ int64_t res=0; |
|
1045 | 1045 |
|
1046 | 1046 |
READ32(arg3, inst->u.three[2]); |
1047 |
- READP(arg1, inst->u.three[0], arg3); |
|
1048 |
- READP(arg2, inst->u.three[1], arg3); |
|
1047 |
+ READPOP(arg1, inst->u.three[0], arg3); |
|
1048 |
+ READPOP(arg2, inst->u.three[1], arg3); |
|
1049 | 1049 |
memmove(arg1, arg2, arg3); |
1050 |
- READ64(res, inst->u.three[0]); |
|
1050 |
+/* READ64(res, inst->u.three[0]);*/ |
|
1051 | 1051 |
WRITE64(inst->dest, res); |
1052 | 1052 |
break; |
1053 | 1053 |
} |
1054 | 1054 |
DEFINE_OP(OP_BC_MEMSET) { |
1055 | 1055 |
int32_t arg2, arg3; |
1056 | 1056 |
void *arg1; |
1057 |
- int64_t res; |
|
1057 |
+ int64_t res=0; |
|
1058 | 1058 |
|
1059 | 1059 |
READ32(arg3, inst->u.three[2]); |
1060 |
- READP(arg1, inst->u.three[0], arg3); |
|
1060 |
+ READPOP(arg1, inst->u.three[0], arg3); |
|
1061 | 1061 |
READ32(arg2, inst->u.three[1]); |
1062 | 1062 |
memset(arg1, arg2, arg3); |
1063 |
- READ64(res, inst->u.three[0]); |
|
1063 |
+/* READ64(res, inst->u.three[0]);*/ |
|
1064 | 1064 |
WRITE64(inst->dest, res); |
1065 | 1065 |
break; |
1066 | 1066 |
} |
... | ... |
@@ -213,9 +213,8 @@ END_TEST |
213 | 213 |
START_TEST (test_bswap) |
214 | 214 |
{ |
215 | 215 |
cl_init(CL_INIT_DEFAULT); |
216 |
- if (have_clamjit) |
|
217 |
- runtest("input/bswap.cbc", 0xbeef, 0, 0, NULL, NULL, NULL, NULL); |
|
218 |
-// runtest("input/bswap.cbc", 0xbeef, 0, 1, NULL, NULL, NULL, NULL); |
|
216 |
+ runtest("input/bswap.cbc", 0xbeef, 0, 0, NULL, NULL, NULL, NULL); |
|
217 |
+ runtest("input/bswap.cbc", 0xbeef, 0, 1, NULL, NULL, NULL, NULL); |
|
219 | 218 |
} |
220 | 219 |
END_TEST |
221 | 220 |
|
... | ... |
@@ -233,7 +232,6 @@ Suite *test_bytecode_suite(void) |
233 | 233 |
Suite *s = suite_create("bytecode"); |
234 | 234 |
TCase *tc_cli_arith = tcase_create("arithmetic"); |
235 | 235 |
suite_add_tcase(s, tc_cli_arith); |
236 |
-#if 0 |
|
237 | 236 |
tcase_add_test(tc_cli_arith, test_retmagic); |
238 | 237 |
tcase_add_test(tc_cli_arith, test_arith); |
239 | 238 |
tcase_add_test(tc_cli_arith, test_apicalls); |
... | ... |
@@ -244,7 +242,6 @@ Suite *test_bytecode_suite(void) |
244 | 244 |
tcase_add_test(tc_cli_arith, test_matchwithread); |
245 | 245 |
tcase_add_test(tc_cli_arith, test_pdf); |
246 | 246 |
tcase_add_test(tc_cli_arith, test_bswap); |
247 |
-#endif |
|
248 | 247 |
tcase_add_test(tc_cli_arith, test_inflate); |
249 | 248 |
return s; |
250 | 249 |
} |