mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2024-11-26 15:32:05 +00:00
Refine codes and fix several issues (#882)
Refine some codes in wasm loader Add -Wshadow to gcc compile flags and fix some variable shadowed issues Fix function parameter/return types not checked issue Fix fast-interp loader reserve_block_ret() not handle V128 return type issue Fix mini loader load_table_segment_section() failed issue Add detailed comments for argc argument in wasm_runtime_call_wasm()
This commit is contained in:
parent
915b26b0ec
commit
5547924e28
|
@ -1454,14 +1454,14 @@ load_text_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
|
|||
/* Now code points to an ELF object, we pull it down to .text section */
|
||||
uint64 offset;
|
||||
uint64 size;
|
||||
char *buf = module->code;
|
||||
module->elf_hdr = buf;
|
||||
if (!get_text_section(buf, &offset, &size)) {
|
||||
char *code_buf = module->code;
|
||||
module->elf_hdr = code_buf;
|
||||
if (!get_text_section(code_buf, &offset, &size)) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"get text section of ELF failed");
|
||||
return false;
|
||||
}
|
||||
module->code = buf + offset;
|
||||
module->code = code_buf + offset;
|
||||
module->code_size -= (uint32)offset;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -216,8 +216,6 @@ table_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
|
|||
|
||||
/* fill table with element segment content */
|
||||
for (i = 0; i < module->table_init_data_count; i++) {
|
||||
AOTTableInstance *tbl_inst;
|
||||
|
||||
table_seg = module->table_init_data_list[i];
|
||||
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
|
@ -1404,6 +1402,16 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
|
|||
uint32 ext_ret_count = result_count > 1 ? result_count - 1 : 0;
|
||||
bool ret;
|
||||
|
||||
if (argc < func_type->param_cell_num) {
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf),
|
||||
"invalid argument count %u, must be no smaller than %u", argc,
|
||||
func_type->param_cell_num);
|
||||
aot_set_exception(module_inst, buf);
|
||||
return false;
|
||||
}
|
||||
argc = func_type->param_cell_num;
|
||||
|
||||
/* set thread handle and stack boundary */
|
||||
wasm_exec_env_set_thread_info(exec_env);
|
||||
|
||||
|
|
|
@ -283,10 +283,10 @@ destroy_wait_info(void *wait_info)
|
|||
}
|
||||
|
||||
static void
|
||||
release_wait_info(HashMap *wait_map, AtomicWaitInfo *wait_info, void *address)
|
||||
release_wait_info(HashMap *wait_map_, AtomicWaitInfo *wait_info, void *address)
|
||||
{
|
||||
if (wait_info->wait_list->len == 0) {
|
||||
bh_hash_map_remove(wait_map, address, NULL, NULL);
|
||||
bh_hash_map_remove(wait_map_, address, NULL, NULL);
|
||||
destroy_wait_info(wait_info);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,35 +311,35 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
|
|||
if (!(func_type = \
|
||||
LLVMFunctionType(ret_type, param_types, argc, false))) { \
|
||||
aot_set_last_error("llvm add function type failed."); \
|
||||
return false; \
|
||||
goto fail; \
|
||||
} \
|
||||
if (comp_ctx->is_jit_mode) { \
|
||||
/* JIT mode, call the function directly */ \
|
||||
if (!(func_ptr_type = LLVMPointerType(func_type, 0))) { \
|
||||
aot_set_last_error("llvm add pointer type failed."); \
|
||||
return false; \
|
||||
goto fail; \
|
||||
} \
|
||||
if (!(value = I64_CONST((uint64)(uintptr_t)name)) \
|
||||
|| !(func = LLVMConstIntToPtr(value, func_ptr_type))) { \
|
||||
aot_set_last_error("create LLVM value failed."); \
|
||||
return false; \
|
||||
goto fail; \
|
||||
} \
|
||||
} \
|
||||
else if (comp_ctx->is_indirect_mode) { \
|
||||
int32 func_index; \
|
||||
if (!(func_ptr_type = LLVMPointerType(func_type, 0))) { \
|
||||
aot_set_last_error("create LLVM function type failed."); \
|
||||
return false; \
|
||||
goto fail; \
|
||||
} \
|
||||
\
|
||||
func_index = aot_get_native_symbol_index(comp_ctx, #name); \
|
||||
if (func_index < 0) { \
|
||||
return false; \
|
||||
goto fail; \
|
||||
} \
|
||||
if (!(func = aot_get_func_from_table( \
|
||||
comp_ctx, func_ctx->native_symbol, func_ptr_type, \
|
||||
func_index))) { \
|
||||
return false; \
|
||||
goto fail; \
|
||||
} \
|
||||
} \
|
||||
else { \
|
||||
|
@ -349,7 +349,7 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
|
|||
&& !(func = LLVMAddFunction(comp_ctx->module, func_name, \
|
||||
func_type))) { \
|
||||
aot_set_last_error("llvm add function failed."); \
|
||||
return false; \
|
||||
goto fail; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
|
@ -345,6 +345,8 @@ call_aot_free_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
|||
}
|
||||
|
||||
return true;
|
||||
fail:
|
||||
return false;
|
||||
}
|
||||
#endif /* end of (WASM_ENABLE_DUMP_CALL_STACK != 0) \
|
||||
|| (WASM_ENABLE_PERF_PROFILING != 0) */
|
||||
|
|
|
@ -477,7 +477,10 @@ wasm_runtime_get_module_inst(wasm_exec_env_t exec_env);
|
|||
* @param exec_env the execution environment to call the function,
|
||||
* which must be created from wasm_create_exec_env()
|
||||
* @param function the function to call
|
||||
* @param argc the number of arguments
|
||||
* @param argc total cell number that the function parameters occupy,
|
||||
* a cell is a slot of the uint32 array argv[], e.g. i32/f32 argument
|
||||
* occupies one cell, i64/f64 argument occupies two cells, note that
|
||||
* it might be different from the parameter number of the function
|
||||
* @param argv the arguments. If the function has return value,
|
||||
* the first (or first two in case 64-bit return value) element of
|
||||
* argv stores the return value of the called WASM function after this
|
||||
|
|
|
@ -520,6 +520,8 @@ wasm_value_type_size(uint8 value_type)
|
|||
case VALUE_TYPE_V128:
|
||||
return sizeof(int64) * 2;
|
||||
#endif
|
||||
case VALUE_TYPE_VOID:
|
||||
return 0;
|
||||
default:
|
||||
bh_assert(0);
|
||||
}
|
||||
|
@ -529,25 +531,7 @@ wasm_value_type_size(uint8 value_type)
|
|||
inline static uint16
|
||||
wasm_value_type_cell_num(uint8 value_type)
|
||||
{
|
||||
if (value_type == VALUE_TYPE_VOID)
|
||||
return 0;
|
||||
else if (value_type == VALUE_TYPE_I32 || value_type == VALUE_TYPE_F32
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
|| value_type == VALUE_TYPE_FUNCREF
|
||||
|| value_type == VALUE_TYPE_EXTERNREF
|
||||
#endif
|
||||
)
|
||||
return 1;
|
||||
else if (value_type == VALUE_TYPE_I64 || value_type == VALUE_TYPE_F64)
|
||||
return 2;
|
||||
#if WASM_ENABLE_SIMD != 0
|
||||
else if (value_type == VALUE_TYPE_V128)
|
||||
return 4;
|
||||
#endif
|
||||
else {
|
||||
bh_assert(0);
|
||||
}
|
||||
return 0;
|
||||
return wasm_value_type_size(value_type) / 4;
|
||||
}
|
||||
|
||||
inline static uint32
|
||||
|
|
|
@ -256,18 +256,19 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
|||
--frame_csp; \
|
||||
} while (0)
|
||||
|
||||
#define POP_CSP_N(n) \
|
||||
do { \
|
||||
uint32 *frame_sp_old = frame_sp; \
|
||||
uint32 cell_num = 0; \
|
||||
POP_CSP_CHECK_OVERFLOW(n + 1); \
|
||||
frame_csp -= n; \
|
||||
frame_ip = (frame_csp - 1)->target_addr; \
|
||||
/* copy arity values of block */ \
|
||||
frame_sp = (frame_csp - 1)->frame_sp; \
|
||||
cell_num = (frame_csp - 1)->cell_num; \
|
||||
word_copy(frame_sp, frame_sp_old - cell_num, cell_num); \
|
||||
frame_sp += cell_num; \
|
||||
#define POP_CSP_N(n) \
|
||||
do { \
|
||||
uint32 *frame_sp_old = frame_sp; \
|
||||
uint32 cell_num_to_copy; \
|
||||
POP_CSP_CHECK_OVERFLOW(n + 1); \
|
||||
frame_csp -= n; \
|
||||
frame_ip = (frame_csp - 1)->target_addr; \
|
||||
/* copy arity values of block */ \
|
||||
frame_sp = (frame_csp - 1)->frame_sp; \
|
||||
cell_num_to_copy = (frame_csp - 1)->cell_num; \
|
||||
word_copy(frame_sp, frame_sp_old - cell_num_to_copy, \
|
||||
cell_num_to_copy); \
|
||||
frame_sp += cell_num_to_copy; \
|
||||
} while (0)
|
||||
|
||||
/* Pop the given number of elements from the given frame's stack. */
|
||||
|
@ -367,11 +368,11 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
|||
PUSH_##src_op_type(cval); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_EQZ(src_op_type) \
|
||||
do { \
|
||||
int32 val; \
|
||||
val = POP_##src_op_type() == 0; \
|
||||
PUSH_I32(val); \
|
||||
#define DEF_OP_EQZ(src_op_type) \
|
||||
do { \
|
||||
int32 pop_val; \
|
||||
pop_val = POP_##src_op_type() == 0; \
|
||||
PUSH_I32(pop_val); \
|
||||
} while (0)
|
||||
|
||||
#define DEF_OP_CMP(src_type, src_op_type, cond) \
|
||||
|
@ -434,9 +435,9 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
|
|||
|
||||
#define DEF_OP_MATH(src_type, src_op_type, method) \
|
||||
do { \
|
||||
src_type val; \
|
||||
val = POP_##src_op_type(); \
|
||||
PUSH_##src_op_type(method(val)); \
|
||||
src_type src_val; \
|
||||
src_val = POP_##src_op_type(); \
|
||||
PUSH_##src_op_type(method(src_val)); \
|
||||
} while (0)
|
||||
|
||||
#define TRUNC_FUNCTION(func_name, src_type, dst_type, signed_type) \
|
||||
|
@ -1384,7 +1385,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
|
||||
HANDLE_OP(WASM_OP_TABLE_SET)
|
||||
{
|
||||
uint32 tbl_idx, elem_idx, val;
|
||||
uint32 tbl_idx, elem_idx, elem_val;
|
||||
WASMTableInstance *tbl_inst;
|
||||
|
||||
read_leb_uint32(frame_ip, frame_ip_end, tbl_idx);
|
||||
|
@ -1392,14 +1393,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
|
||||
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
||||
|
||||
val = POP_I32();
|
||||
elem_val = POP_I32();
|
||||
elem_idx = POP_I32();
|
||||
if (elem_idx >= tbl_inst->cur_size) {
|
||||
wasm_set_exception(module, "out of bounds table access");
|
||||
goto got_exception;
|
||||
}
|
||||
|
||||
((uint32 *)(tbl_inst->base_addr))[elem_idx] = val;
|
||||
((uint32 *)(tbl_inst->base_addr))[elem_idx] = elem_val;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
|
||||
|
@ -1414,9 +1415,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
|
||||
HANDLE_OP(WASM_OP_REF_IS_NULL)
|
||||
{
|
||||
uint32 val;
|
||||
val = POP_I32();
|
||||
PUSH_I32(val == NULL_REF ? 1 : 0);
|
||||
uint32 ref_val;
|
||||
ref_val = POP_I32();
|
||||
PUSH_I32(ref_val == NULL_REF ? 1 : 0);
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
|
||||
|
@ -2955,16 +2956,16 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
case WASM_OP_MEMORY_FILL:
|
||||
{
|
||||
uint32 dst, len;
|
||||
uint8 val, *mdst;
|
||||
uint8 fill_val, *mdst;
|
||||
frame_ip++;
|
||||
|
||||
len = POP_I32();
|
||||
val = POP_I32();
|
||||
fill_val = POP_I32();
|
||||
dst = POP_I32();
|
||||
|
||||
CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);
|
||||
|
||||
memset(mdst, val, len);
|
||||
memset(mdst, fill_val, len);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -3119,7 +3120,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
}
|
||||
case WASM_OP_TABLE_FILL:
|
||||
{
|
||||
uint32 tbl_idx, n, val, i;
|
||||
uint32 tbl_idx, n, fill_val;
|
||||
WASMTableInstance *tbl_inst;
|
||||
|
||||
read_leb_uint32(frame_ip, frame_ip_end, tbl_idx);
|
||||
|
@ -3128,7 +3129,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
||||
|
||||
n = POP_I32();
|
||||
val = POP_I32();
|
||||
fill_val = POP_I32();
|
||||
i = POP_I32();
|
||||
|
||||
/* TODO: what if the element is not passive? */
|
||||
|
@ -3142,7 +3143,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
}
|
||||
|
||||
for (; n != 0; i++, n--) {
|
||||
((uint32 *)(tbl_inst->base_addr))[i] = val;
|
||||
((uint32 *)(tbl_inst->base_addr))[i] = fill_val;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -3167,15 +3168,16 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
switch (opcode) {
|
||||
case WASM_OP_ATOMIC_NOTIFY:
|
||||
{
|
||||
uint32 count, ret;
|
||||
uint32 notify_count, ret;
|
||||
|
||||
count = POP_I32();
|
||||
notify_count = POP_I32();
|
||||
addr = POP_I32();
|
||||
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
|
||||
CHECK_ATOMIC_MEMORY_ACCESS();
|
||||
|
||||
ret = wasm_runtime_atomic_notify(
|
||||
(WASMModuleInstanceCommon *)module, maddr, count);
|
||||
(WASMModuleInstanceCommon *)module, maddr,
|
||||
notify_count);
|
||||
bh_assert((int32)ret >= 0);
|
||||
|
||||
PUSH_I32(ret);
|
||||
|
@ -3184,7 +3186,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
case WASM_OP_ATOMIC_WAIT32:
|
||||
{
|
||||
uint64 timeout;
|
||||
uint32 expect, addr, ret;
|
||||
uint32 expect, ret;
|
||||
|
||||
timeout = POP_I64();
|
||||
expect = POP_I32();
|
||||
|
@ -3708,13 +3710,15 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
|||
frame here. */
|
||||
unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
|
||||
|
||||
if (argc != function->param_cell_num) {
|
||||
if (argc < function->param_cell_num) {
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "invalid argument count %d, expected %d",
|
||||
argc, function->param_cell_num);
|
||||
snprintf(buf, sizeof(buf),
|
||||
"invalid argument count %u, must be no smaller than %u", argc,
|
||||
function->param_cell_num);
|
||||
wasm_set_exception(module_inst, buf);
|
||||
return;
|
||||
}
|
||||
argc = function->param_cell_num;
|
||||
|
||||
if ((uint8 *)&prev_frame < exec_env->native_stack_boundary) {
|
||||
wasm_set_exception((WASMModuleInstance *)exec_env->module_inst,
|
||||
|
|
|
@ -1346,7 +1346,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
|
||||
HANDLE_OP(WASM_OP_TABLE_SET)
|
||||
{
|
||||
uint32 tbl_idx, elem_idx, val;
|
||||
uint32 tbl_idx, elem_idx, elem_val;
|
||||
WASMTableInstance *tbl_inst;
|
||||
|
||||
tbl_idx = read_uint32(frame_ip);
|
||||
|
@ -1354,14 +1354,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
|
||||
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
||||
|
||||
val = POP_I32();
|
||||
elem_val = POP_I32();
|
||||
elem_idx = POP_I32();
|
||||
if (elem_idx >= tbl_inst->cur_size) {
|
||||
wasm_set_exception(module, "out of bounds table access");
|
||||
goto got_exception;
|
||||
}
|
||||
|
||||
((uint32 *)tbl_inst->base_addr)[elem_idx] = val;
|
||||
((uint32 *)tbl_inst->base_addr)[elem_idx] = elem_val;
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
|
||||
|
@ -1373,9 +1373,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
|
||||
HANDLE_OP(WASM_OP_REF_IS_NULL)
|
||||
{
|
||||
uint32 val;
|
||||
val = POP_I32();
|
||||
PUSH_I32(val == NULL_REF ? 1 : 0);
|
||||
uint32 ref_val;
|
||||
ref_val = POP_I32();
|
||||
PUSH_I32(ref_val == NULL_REF ? 1 : 0);
|
||||
HANDLE_OP_END();
|
||||
}
|
||||
|
||||
|
@ -2885,15 +2885,15 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
case WASM_OP_MEMORY_FILL:
|
||||
{
|
||||
uint32 dst, len;
|
||||
uint8 val, *mdst;
|
||||
uint8 fill_val, *mdst;
|
||||
|
||||
len = POP_I32();
|
||||
val = POP_I32();
|
||||
fill_val = POP_I32();
|
||||
dst = POP_I32();
|
||||
|
||||
CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);
|
||||
|
||||
memset(mdst, val, len);
|
||||
memset(mdst, fill_val, len);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -3045,7 +3045,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
}
|
||||
case WASM_OP_TABLE_FILL:
|
||||
{
|
||||
uint32 tbl_idx, n, val, i;
|
||||
uint32 tbl_idx, n, fill_val, i;
|
||||
WASMTableInstance *tbl_inst;
|
||||
|
||||
tbl_idx = read_uint32(frame_ip);
|
||||
|
@ -3054,7 +3054,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
||||
|
||||
n = POP_I32();
|
||||
val = POP_I32();
|
||||
fill_val = POP_I32();
|
||||
i = POP_I32();
|
||||
|
||||
if (i + n > tbl_inst->cur_size) {
|
||||
|
@ -3064,7 +3064,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
}
|
||||
|
||||
for (; n != 0; i++, n--) {
|
||||
((uint32 *)(tbl_inst->base_addr))[i] = val;
|
||||
((uint32 *)(tbl_inst->base_addr))[i] = fill_val;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -3089,15 +3089,16 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
switch (opcode) {
|
||||
case WASM_OP_ATOMIC_NOTIFY:
|
||||
{
|
||||
uint32 count, ret;
|
||||
uint32 notify_count, ret;
|
||||
|
||||
count = POP_I32();
|
||||
notify_count = POP_I32();
|
||||
addr = POP_I32();
|
||||
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
|
||||
CHECK_ATOMIC_MEMORY_ACCESS(4);
|
||||
|
||||
ret = wasm_runtime_atomic_notify(
|
||||
(WASMModuleInstanceCommon *)module, maddr, count);
|
||||
(WASMModuleInstanceCommon *)module, maddr,
|
||||
notify_count);
|
||||
bh_assert((int32)ret >= 0);
|
||||
|
||||
PUSH_I32(ret);
|
||||
|
@ -3106,7 +3107,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
|||
case WASM_OP_ATOMIC_WAIT32:
|
||||
{
|
||||
uint64 timeout;
|
||||
uint32 expect, addr, ret;
|
||||
uint32 expect, ret;
|
||||
|
||||
timeout = POP_I64();
|
||||
expect = POP_I32();
|
||||
|
@ -3729,13 +3730,15 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
|||
frame here. */
|
||||
unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);
|
||||
|
||||
if (argc != function->param_cell_num) {
|
||||
if (argc < function->param_cell_num) {
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "invalid argument count %d, expected %d",
|
||||
argc, function->param_cell_num);
|
||||
snprintf(buf, sizeof(buf),
|
||||
"invalid argument count %u, must be no smaller than %u", argc,
|
||||
function->param_cell_num);
|
||||
wasm_set_exception(module_inst, buf);
|
||||
return;
|
||||
}
|
||||
argc = function->param_cell_num;
|
||||
|
||||
if ((uint8 *)&prev_frame < exec_env->native_stack_boundary) {
|
||||
wasm_set_exception((WASMModuleInstance *)exec_env->module_inst,
|
||||
|
|
|
@ -587,6 +587,13 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|||
CHECK_BUF(p, p_end, 1);
|
||||
type->types[param_count + j] = read_uint8(p);
|
||||
}
|
||||
for (j = 0; j < param_count + result_count; j++) {
|
||||
if (!is_value_type(type->types[j])) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"unknown value type");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
param_cell_num = wasm_get_cell_num(type->types, param_count);
|
||||
ret_cell_num =
|
||||
|
@ -891,7 +898,7 @@ register_sub_module(const WASMModule *parent_module,
|
|||
return true;
|
||||
}
|
||||
|
||||
node = wasm_runtime_malloc(sizeof(WASMRegisteredModule));
|
||||
node = loader_malloc(sizeof(WASMRegisteredModule), NULL, 0);
|
||||
if (!node) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1904,17 +1911,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|||
CHECK_BUF(p_code, buf_code_end, 1);
|
||||
/* 0x7F/0x7E/0x7D/0x7C */
|
||||
type = read_uint8(p_code);
|
||||
if ((type < VALUE_TYPE_F64 || type > VALUE_TYPE_I32)
|
||||
#if WASM_ENABLE_SIMD != 0
|
||||
#if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0)
|
||||
&& type != VALUE_TYPE_V128
|
||||
#endif
|
||||
#endif
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
&& type != VALUE_TYPE_FUNCREF
|
||||
&& type != VALUE_TYPE_EXTERNREF
|
||||
#endif
|
||||
) {
|
||||
if (!is_value_type(type)) {
|
||||
if (type == VALUE_TYPE_V128)
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"v128 value type requires simd feature");
|
||||
|
@ -3250,7 +3247,7 @@ static void
|
|||
record_fast_op(WASMModule *module, uint8 *pos, uint8 orig_op)
|
||||
{
|
||||
WASMFastOPCodeNode *fast_op =
|
||||
wasm_runtime_malloc(sizeof(WASMFastOPCodeNode));
|
||||
loader_malloc(sizeof(WASMFastOPCodeNode), NULL, 0);
|
||||
if (fast_op) {
|
||||
fast_op->offset = pos - module->load_addr;
|
||||
fast_op->orig_op = orig_op;
|
||||
|
@ -4449,40 +4446,34 @@ static WASMLoaderContext *
|
|||
wasm_loader_ctx_init(WASMFunction *func)
|
||||
{
|
||||
WASMLoaderContext *loader_ctx =
|
||||
wasm_runtime_malloc(sizeof(WASMLoaderContext));
|
||||
loader_malloc(sizeof(WASMLoaderContext), NULL, 0);
|
||||
if (!loader_ctx)
|
||||
return NULL;
|
||||
memset(loader_ctx, 0, sizeof(WASMLoaderContext));
|
||||
|
||||
loader_ctx->frame_ref_size = 32;
|
||||
if (!(loader_ctx->frame_ref_bottom = loader_ctx->frame_ref =
|
||||
wasm_runtime_malloc(loader_ctx->frame_ref_size)))
|
||||
loader_malloc(loader_ctx->frame_ref_size, NULL, 0)))
|
||||
goto fail;
|
||||
memset(loader_ctx->frame_ref_bottom, 0, loader_ctx->frame_ref_size);
|
||||
loader_ctx->frame_ref_boundary =
|
||||
loader_ctx->frame_ref_bottom + loader_ctx->frame_ref_size;
|
||||
loader_ctx->frame_ref_boundary = loader_ctx->frame_ref_bottom + 32;
|
||||
|
||||
loader_ctx->frame_csp_size = sizeof(BranchBlock) * 8;
|
||||
if (!(loader_ctx->frame_csp_bottom = loader_ctx->frame_csp =
|
||||
wasm_runtime_malloc(loader_ctx->frame_csp_size)))
|
||||
loader_malloc(loader_ctx->frame_csp_size, NULL, 0)))
|
||||
goto fail;
|
||||
memset(loader_ctx->frame_csp_bottom, 0, loader_ctx->frame_csp_size);
|
||||
loader_ctx->frame_csp_boundary = loader_ctx->frame_csp_bottom + 8;
|
||||
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
loader_ctx->frame_offset_size = sizeof(int16) * 32;
|
||||
if (!(loader_ctx->frame_offset_bottom = loader_ctx->frame_offset =
|
||||
wasm_runtime_malloc(loader_ctx->frame_offset_size)))
|
||||
loader_malloc(loader_ctx->frame_offset_size, NULL, 0)))
|
||||
goto fail;
|
||||
memset(loader_ctx->frame_offset_bottom, 0, loader_ctx->frame_offset_size);
|
||||
loader_ctx->frame_offset_boundary = loader_ctx->frame_offset_bottom + 32;
|
||||
|
||||
loader_ctx->num_const = 0;
|
||||
loader_ctx->const_buf_size = sizeof(Const) * 8;
|
||||
if (!(loader_ctx->const_buf =
|
||||
wasm_runtime_malloc(loader_ctx->const_buf_size)))
|
||||
loader_malloc(loader_ctx->const_buf_size, NULL, 0)))
|
||||
goto fail;
|
||||
memset(loader_ctx->const_buf, 0, loader_ctx->const_buf_size);
|
||||
|
||||
loader_ctx->start_dynamic_offset = loader_ctx->dynamic_offset =
|
||||
loader_ctx->max_dynamic_offset =
|
||||
|
@ -4766,9 +4757,9 @@ fail:
|
|||
static bool
|
||||
wasm_loader_ctx_reinit(WASMLoaderContext *ctx)
|
||||
{
|
||||
if (!(ctx->p_code_compiled = wasm_runtime_malloc(ctx->code_compiled_size)))
|
||||
if (!(ctx->p_code_compiled =
|
||||
loader_malloc(ctx->code_compiled_size, NULL, 0)))
|
||||
return false;
|
||||
memset(ctx->p_code_compiled, 0, ctx->code_compiled_size);
|
||||
ctx->p_code_compiled_end = ctx->p_code_compiled + ctx->code_compiled_size;
|
||||
|
||||
/* clean up frame ref */
|
||||
|
@ -5479,7 +5470,8 @@ reserve_block_ret(WASMLoaderContext *loader_ctx, uint8 opcode,
|
|||
* of EXT_OP_COPY_STACK_VALUES for interpreter performance. */
|
||||
if (return_count == 1) {
|
||||
uint8 cell = (uint8)wasm_value_type_cell_num(return_types[0]);
|
||||
if (block->dynamic_offset != *(loader_ctx->frame_offset - cell)) {
|
||||
if (cell <= 2 /* V128 isn't supported whose cell num is 4 */
|
||||
&& block->dynamic_offset != *(loader_ctx->frame_offset - cell)) {
|
||||
/* insert op_copy before else opcode */
|
||||
if (opcode == WASM_OP_ELSE)
|
||||
skip_label();
|
||||
|
@ -6121,10 +6113,10 @@ fail:
|
|||
#endif
|
||||
|
||||
/* set current block's stack polymorphic state */
|
||||
#define SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE(flag) \
|
||||
do { \
|
||||
BranchBlock *cur_block = loader_ctx->frame_csp - 1; \
|
||||
cur_block->is_stack_polymorphic = flag; \
|
||||
#define SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE(flag) \
|
||||
do { \
|
||||
BranchBlock *_cur_block = loader_ctx->frame_csp - 1; \
|
||||
_cur_block->is_stack_polymorphic = flag; \
|
||||
} while (0)
|
||||
|
||||
#define BLOCK_HAS_PARAM(block_type) \
|
||||
|
@ -6184,12 +6176,12 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|||
uint8 *p = func->code, *p_end = func->code + func->code_size, *p_org;
|
||||
uint32 param_count, local_count, global_count;
|
||||
uint8 *param_types, *local_types, local_type, global_type;
|
||||
BlockType func_type;
|
||||
BlockType func_block_type;
|
||||
uint16 *local_offsets, local_offset;
|
||||
uint32 type_idx, func_idx, local_idx, global_idx, table_idx;
|
||||
uint32 table_seg_idx, data_seg_idx, count, i, align, mem_offset;
|
||||
uint32 table_seg_idx, data_seg_idx, count, align, mem_offset, i;
|
||||
int32 i32_const = 0;
|
||||
int64 i64;
|
||||
int64 i64_const;
|
||||
uint8 opcode;
|
||||
bool return_value = false;
|
||||
WASMLoaderContext *loader_ctx;
|
||||
|
@ -6199,8 +6191,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|||
int16 operand_offset = 0;
|
||||
uint8 last_op = 0;
|
||||
bool disable_emit, preserve_local = false;
|
||||
float32 f32;
|
||||
float64 f64;
|
||||
float32 f32_const;
|
||||
float64 f64_const;
|
||||
|
||||
LOG_OP("\nProcessing func | [%d] params | [%d] locals | [%d] return\n",
|
||||
func->param_cell_num, func->local_cell_num, func->ret_cell_num);
|
||||
|
@ -6211,8 +6203,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|||
param_count = func->func_type->param_count;
|
||||
param_types = func->func_type->types;
|
||||
|
||||
func_type.is_value_type = false;
|
||||
func_type.u.type = func->func_type;
|
||||
func_block_type.is_value_type = false;
|
||||
func_block_type.u.type = func->func_type;
|
||||
|
||||
local_count = func->local_count;
|
||||
local_types = func->local_types;
|
||||
|
@ -6236,7 +6228,7 @@ re_scan:
|
|||
}
|
||||
#endif
|
||||
|
||||
PUSH_CSP(LABEL_TYPE_FUNCTION, func_type, p);
|
||||
PUSH_CSP(LABEL_TYPE_FUNCTION, func_block_type, p);
|
||||
|
||||
while (p < p_end) {
|
||||
opcode = *p++;
|
||||
|
@ -6461,24 +6453,26 @@ re_scan:
|
|||
* fail */
|
||||
if (cur_block->label_type == LABEL_TYPE_IF
|
||||
&& !cur_block->else_addr) {
|
||||
uint32 param_count = 0, ret_count = 0;
|
||||
uint8 *param_types = NULL, *ret_types = NULL;
|
||||
BlockType *block_type = &cur_block->block_type;
|
||||
if (block_type->is_value_type) {
|
||||
if (block_type->u.value_type != VALUE_TYPE_VOID) {
|
||||
ret_count = 1;
|
||||
ret_types = &block_type->u.value_type;
|
||||
uint32 block_param_count = 0, block_ret_count = 0;
|
||||
uint8 *block_param_types = NULL, *block_ret_types = NULL;
|
||||
BlockType *cur_block_type = &cur_block->block_type;
|
||||
if (cur_block_type->is_value_type) {
|
||||
if (cur_block_type->u.value_type != VALUE_TYPE_VOID) {
|
||||
block_ret_count = 1;
|
||||
block_ret_types = &cur_block_type->u.value_type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
param_count = block_type->u.type->param_count;
|
||||
ret_count = block_type->u.type->result_count;
|
||||
param_types = block_type->u.type->types;
|
||||
ret_types = block_type->u.type->types + param_count;
|
||||
block_param_count = cur_block_type->u.type->param_count;
|
||||
block_ret_count = cur_block_type->u.type->result_count;
|
||||
block_param_types = cur_block_type->u.type->types;
|
||||
block_ret_types =
|
||||
cur_block_type->u.type->types + block_param_count;
|
||||
}
|
||||
if (param_count != ret_count
|
||||
|| (param_count
|
||||
&& memcmp(param_types, ret_types, param_count))) {
|
||||
if (block_param_count != block_ret_count
|
||||
|| (block_param_count
|
||||
&& memcmp(block_param_types, block_ret_types,
|
||||
block_param_count))) {
|
||||
set_error_buf(error_buf, error_buf_size,
|
||||
"type mismatch: else branch missing");
|
||||
goto fail;
|
||||
|
@ -6810,13 +6804,7 @@ re_scan:
|
|||
}
|
||||
|
||||
if (available_stack_cell > 0) {
|
||||
if (*(loader_ctx->frame_ref - 1) == REF_I32
|
||||
|| *(loader_ctx->frame_ref - 1) == REF_F32
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
|| *(loader_ctx->frame_ref - 1) == REF_FUNCREF
|
||||
|| *(loader_ctx->frame_ref - 1) == REF_EXTERNREF
|
||||
#endif
|
||||
) {
|
||||
if (is_32bit_type(*(loader_ctx->frame_ref - 1))) {
|
||||
loader_ctx->frame_ref--;
|
||||
loader_ctx->stack_cell_num--;
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
|
@ -6827,8 +6815,7 @@ re_scan:
|
|||
loader_ctx->dynamic_offset--;
|
||||
#endif
|
||||
}
|
||||
else if (*(loader_ctx->frame_ref - 1) == REF_I64_1
|
||||
|| *(loader_ctx->frame_ref - 1) == REF_F64_1) {
|
||||
else if (is_64bit_type(*(loader_ctx->frame_ref - 1))) {
|
||||
loader_ctx->frame_ref -= 2;
|
||||
loader_ctx->stack_cell_num -= 2;
|
||||
#if (WASM_ENABLE_FAST_INTERP == 0) || (WASM_ENABLE_JIT != 0)
|
||||
|
@ -7604,11 +7591,11 @@ re_scan:
|
|||
break;
|
||||
|
||||
case WASM_OP_I64_CONST:
|
||||
read_leb_int64(p, p_end, i64);
|
||||
read_leb_int64(p, p_end, i64_const);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
skip_label();
|
||||
disable_emit = true;
|
||||
GET_CONST_OFFSET(VALUE_TYPE_I64, i64);
|
||||
GET_CONST_OFFSET(VALUE_TYPE_I64, i64_const);
|
||||
#endif
|
||||
PUSH_I64();
|
||||
break;
|
||||
|
@ -7618,9 +7605,9 @@ re_scan:
|
|||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
skip_label();
|
||||
disable_emit = true;
|
||||
bh_memcpy_s((uint8 *)&f32, sizeof(float32), p_org,
|
||||
bh_memcpy_s((uint8 *)&f32_const, sizeof(float32), p_org,
|
||||
sizeof(float32));
|
||||
GET_CONST_F32_OFFSET(VALUE_TYPE_F32, f32);
|
||||
GET_CONST_F32_OFFSET(VALUE_TYPE_F32, f32_const);
|
||||
#endif
|
||||
PUSH_F32();
|
||||
break;
|
||||
|
@ -7631,9 +7618,9 @@ re_scan:
|
|||
skip_label();
|
||||
disable_emit = true;
|
||||
/* Some MCU may require 8-byte align */
|
||||
bh_memcpy_s((uint8 *)&f64, sizeof(float64), p_org,
|
||||
bh_memcpy_s((uint8 *)&f64_const, sizeof(float64), p_org,
|
||||
sizeof(float64));
|
||||
GET_CONST_F64_OFFSET(VALUE_TYPE_F64, f64);
|
||||
GET_CONST_F64_OFFSET(VALUE_TYPE_F64, f64_const);
|
||||
#endif
|
||||
PUSH_F64();
|
||||
break;
|
||||
|
@ -8932,14 +8919,16 @@ re_scan:
|
|||
|
||||
func->const_cell_num = loader_ctx->const_cell_num;
|
||||
if (func->const_cell_num > 0) {
|
||||
int32 j;
|
||||
|
||||
if (!(func->consts = func_const = loader_malloc(
|
||||
func->const_cell_num * 4, error_buf, error_buf_size)))
|
||||
goto fail;
|
||||
|
||||
func_const_end = func->consts + func->const_cell_num * 4;
|
||||
/* reverse the const buf */
|
||||
for (int i = loader_ctx->num_const - 1; i >= 0; i--) {
|
||||
Const *c = (Const *)(loader_ctx->const_buf + i * sizeof(Const));
|
||||
for (j = loader_ctx->num_const - 1; j >= 0; j--) {
|
||||
Const *c = (Const *)(loader_ctx->const_buf + j * sizeof(Const));
|
||||
if (c->value_type == VALUE_TYPE_F64
|
||||
|| c->value_type == VALUE_TYPE_I64) {
|
||||
bh_memcpy_s(func_const, (uint32)(func_const_end - func_const),
|
||||
|
@ -8968,7 +8957,7 @@ fail:
|
|||
(void)table_idx;
|
||||
(void)table_seg_idx;
|
||||
(void)data_seg_idx;
|
||||
(void)i64;
|
||||
(void)i64_const;
|
||||
(void)local_offset;
|
||||
(void)p_org;
|
||||
(void)mem_offset;
|
||||
|
|
|
@ -60,6 +60,25 @@ is_64bit_type(uint8 type)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_value_type(uint8 type)
|
||||
{
|
||||
if (type == VALUE_TYPE_I32 || type == VALUE_TYPE_I64
|
||||
|| type == VALUE_TYPE_F32 || type == VALUE_TYPE_F64
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
|| type == VALUE_TYPE_FUNCREF || type == VALUE_TYPE_EXTERNREF
|
||||
#endif
|
||||
)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_byte_a_type(uint8 type)
|
||||
{
|
||||
return is_value_type(type) || (type == VALUE_TYPE_VOID);
|
||||
}
|
||||
|
||||
static void
|
||||
read_leb(uint8 **p_buf, const uint8 *buf_end, uint32 maxbits, bool sign,
|
||||
uint64 *p_result, char *error_buf, uint32 error_buf_size)
|
||||
|
@ -359,6 +378,9 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
|
|||
CHECK_BUF(p, p_end, 1);
|
||||
type->types[param_count + j] = read_uint8(p);
|
||||
}
|
||||
for (j = 0; j < param_count + result_count; j++) {
|
||||
bh_assert(is_value_type(type->types[j]));
|
||||
}
|
||||
|
||||
param_cell_num = wasm_get_cell_num(type->types, param_count);
|
||||
ret_cell_num =
|
||||
|
@ -971,12 +993,7 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
|
|||
CHECK_BUF(p_code, buf_code_end, 1);
|
||||
/* 0x7F/0x7E/0x7D/0x7C */
|
||||
type = read_uint8(p_code);
|
||||
bh_assert((type >= VALUE_TYPE_F64 && type <= VALUE_TYPE_I32)
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
|| type == VALUE_TYPE_FUNCREF
|
||||
|| type == VALUE_TYPE_EXTERNREF
|
||||
#endif
|
||||
);
|
||||
bh_assert(is_value_type(type));
|
||||
for (k = 0; k < sub_local_count; k++) {
|
||||
func->local_types[local_type_index++] = type;
|
||||
}
|
||||
|
@ -1228,7 +1245,6 @@ check_table_index(const WASMModule *module, uint32 table_index, char *error_buf,
|
|||
return true;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
static bool
|
||||
load_table_index(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
|
||||
uint32 *p_table_index, char *error_buf, uint32 error_buf_size)
|
||||
|
@ -1246,6 +1262,7 @@ load_table_index(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
|
|||
return true;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
static bool
|
||||
load_elem_type(const uint8 **p_buf, const uint8 *buf_end, uint32 *p_elem_type,
|
||||
bool elemkind_zero, char *error_buf, uint32 error_buf_size)
|
||||
|
@ -1416,34 +1433,26 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
|
|||
return false;
|
||||
}
|
||||
#else
|
||||
read_leb_uint32(p, p_end, table_index);
|
||||
bh_assert(table_index
|
||||
< module->import_table_count + module->table_count);
|
||||
|
||||
table_segment->table_index = table_index;
|
||||
|
||||
/* initialize expression */
|
||||
if (!load_init_expr(&p, p_end, &(table_segment->base_offset),
|
||||
/*
|
||||
* like: 00 41 05 0b 04 00 01 00 01
|
||||
* for: (elem 0 (offset (i32.const 5)) $f1 $f2 $f1 $f2)
|
||||
*/
|
||||
if (!load_table_index(&p, p_end, module,
|
||||
&table_segment->table_index, error_buf,
|
||||
error_buf_size))
|
||||
return false;
|
||||
if (!load_init_expr(&p, p_end, &table_segment->base_offset,
|
||||
VALUE_TYPE_I32, error_buf, error_buf_size))
|
||||
return false;
|
||||
|
||||
read_leb_uint32(p, p_end, function_count);
|
||||
table_segment->function_count = function_count;
|
||||
total_size = sizeof(uint32) * (uint64)function_count;
|
||||
if (total_size > 0
|
||||
&& !(table_segment->func_indexes = (uint32 *)loader_malloc(
|
||||
total_size, error_buf, error_buf_size))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!load_func_index_vec(&p, p_end, module, table_segment,
|
||||
table_segment->mode == 0 ? false : true,
|
||||
if (!load_func_index_vec(&p, p_end, module, table_segment, false,
|
||||
error_buf, error_buf_size))
|
||||
return false;
|
||||
#endif /* WASM_ENABLE_REF_TYPES != 0 */
|
||||
}
|
||||
}
|
||||
|
||||
(void)table_index;
|
||||
(void)function_count;
|
||||
bh_assert(p == p_end);
|
||||
LOG_VERBOSE("Load table segment section success.\n");
|
||||
return true;
|
||||
|
@ -3146,40 +3155,34 @@ static WASMLoaderContext *
|
|||
wasm_loader_ctx_init(WASMFunction *func)
|
||||
{
|
||||
WASMLoaderContext *loader_ctx =
|
||||
wasm_runtime_malloc(sizeof(WASMLoaderContext));
|
||||
loader_malloc(sizeof(WASMLoaderContext), NULL, 0);
|
||||
if (!loader_ctx)
|
||||
return false;
|
||||
memset(loader_ctx, 0, sizeof(WASMLoaderContext));
|
||||
|
||||
loader_ctx->frame_ref_size = 32;
|
||||
if (!(loader_ctx->frame_ref_bottom = loader_ctx->frame_ref =
|
||||
wasm_runtime_malloc(loader_ctx->frame_ref_size)))
|
||||
loader_malloc(loader_ctx->frame_ref_size, NULL, 0)))
|
||||
goto fail;
|
||||
memset(loader_ctx->frame_ref_bottom, 0, loader_ctx->frame_ref_size);
|
||||
loader_ctx->frame_ref_boundary =
|
||||
loader_ctx->frame_ref_bottom + loader_ctx->frame_ref_size;
|
||||
loader_ctx->frame_ref_boundary = loader_ctx->frame_ref_bottom + 32;
|
||||
|
||||
loader_ctx->frame_csp_size = sizeof(BranchBlock) * 8;
|
||||
if (!(loader_ctx->frame_csp_bottom = loader_ctx->frame_csp =
|
||||
wasm_runtime_malloc(loader_ctx->frame_csp_size)))
|
||||
loader_malloc(loader_ctx->frame_csp_size, NULL, 0)))
|
||||
goto fail;
|
||||
memset(loader_ctx->frame_csp_bottom, 0, loader_ctx->frame_csp_size);
|
||||
loader_ctx->frame_csp_boundary = loader_ctx->frame_csp_bottom + 8;
|
||||
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
loader_ctx->frame_offset_size = sizeof(int16) * 32;
|
||||
if (!(loader_ctx->frame_offset_bottom = loader_ctx->frame_offset =
|
||||
wasm_runtime_malloc(loader_ctx->frame_offset_size)))
|
||||
loader_malloc(loader_ctx->frame_offset_size, NULL, 0)))
|
||||
goto fail;
|
||||
memset(loader_ctx->frame_offset_bottom, 0, loader_ctx->frame_offset_size);
|
||||
loader_ctx->frame_offset_boundary = loader_ctx->frame_offset_bottom + 32;
|
||||
|
||||
loader_ctx->num_const = 0;
|
||||
loader_ctx->const_buf_size = sizeof(Const) * 8;
|
||||
if (!(loader_ctx->const_buf =
|
||||
wasm_runtime_malloc(loader_ctx->const_buf_size)))
|
||||
loader_malloc(loader_ctx->const_buf_size, NULL, 0)))
|
||||
goto fail;
|
||||
memset(loader_ctx->const_buf, 0, loader_ctx->const_buf_size);
|
||||
|
||||
loader_ctx->start_dynamic_offset = loader_ctx->dynamic_offset =
|
||||
loader_ctx->max_dynamic_offset =
|
||||
|
@ -3436,9 +3439,9 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx, char *error_buf,
|
|||
static bool
|
||||
wasm_loader_ctx_reinit(WASMLoaderContext *ctx)
|
||||
{
|
||||
if (!(ctx->p_code_compiled = wasm_runtime_malloc(ctx->code_compiled_size)))
|
||||
if (!(ctx->p_code_compiled =
|
||||
loader_malloc(ctx->code_compiled_size, NULL, 0)))
|
||||
return false;
|
||||
memset(ctx->p_code_compiled, 0, ctx->code_compiled_size);
|
||||
ctx->p_code_compiled_end = ctx->p_code_compiled + ctx->code_compiled_size;
|
||||
|
||||
/* clean up frame ref */
|
||||
|
@ -4240,7 +4243,8 @@ reserve_block_ret(WASMLoaderContext *loader_ctx, uint8 opcode,
|
|||
* of EXT_OP_COPY_STACK_VALUES for interpreter performance. */
|
||||
if (return_count == 1) {
|
||||
uint8 cell = (uint8)wasm_value_type_cell_num(return_types[0]);
|
||||
if (block->dynamic_offset != *(loader_ctx->frame_offset - cell)) {
|
||||
if (cell <= 2 /* V128 isn't supported whose cell num is 4 */
|
||||
&& block->dynamic_offset != *(loader_ctx->frame_offset - cell)) {
|
||||
/* insert op_copy before else opcode */
|
||||
if (opcode == WASM_OP_ELSE)
|
||||
skip_label();
|
||||
|
@ -4425,25 +4429,6 @@ fail:
|
|||
bh_assert(module->import_memory_count + module->memory_count > 0); \
|
||||
} while (0)
|
||||
|
||||
static bool
|
||||
is_value_type(uint8 type)
|
||||
{
|
||||
if (type == VALUE_TYPE_I32 || type == VALUE_TYPE_I64
|
||||
|| type == VALUE_TYPE_F32 || type == VALUE_TYPE_F64
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
|| type == VALUE_TYPE_FUNCREF || type == VALUE_TYPE_EXTERNREF
|
||||
#endif
|
||||
)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_byte_a_type(uint8 type)
|
||||
{
|
||||
return is_value_type(type) || (type == VALUE_TYPE_VOID);
|
||||
}
|
||||
|
||||
static bool
|
||||
wasm_loader_check_br(WASMLoaderContext *loader_ctx, uint32 depth,
|
||||
char *error_buf, uint32 error_buf_size)
|
||||
|
@ -4715,10 +4700,10 @@ fail:
|
|||
#endif
|
||||
|
||||
/* set current block's stack polymorphic state */
|
||||
#define SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE(flag) \
|
||||
do { \
|
||||
BranchBlock *cur_block = loader_ctx->frame_csp - 1; \
|
||||
cur_block->is_stack_polymorphic = flag; \
|
||||
#define SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE(flag) \
|
||||
do { \
|
||||
BranchBlock *_cur_block = loader_ctx->frame_csp - 1; \
|
||||
_cur_block->is_stack_polymorphic = flag; \
|
||||
} while (0)
|
||||
|
||||
#define BLOCK_HAS_PARAM(block_type) \
|
||||
|
@ -4740,11 +4725,11 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|||
uint8 *p = func->code, *p_end = func->code + func->code_size, *p_org;
|
||||
uint32 param_count, local_count, global_count;
|
||||
uint8 *param_types, *local_types, local_type, global_type;
|
||||
BlockType func_type;
|
||||
BlockType func_block_type;
|
||||
uint16 *local_offsets, local_offset;
|
||||
uint32 count, i, local_idx, global_idx, u32, align, mem_offset;
|
||||
uint32 count, local_idx, global_idx, u32, align, mem_offset, i;
|
||||
int32 i32, i32_const = 0;
|
||||
int64 i64;
|
||||
int64 i64_const;
|
||||
uint8 opcode, u8;
|
||||
bool return_value = false;
|
||||
WASMLoaderContext *loader_ctx;
|
||||
|
@ -4757,8 +4742,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|||
int16 operand_offset = 0;
|
||||
uint8 last_op = 0;
|
||||
bool disable_emit, preserve_local = false;
|
||||
float32 f32;
|
||||
float64 f64;
|
||||
float32 f32_const;
|
||||
float64 f64_const;
|
||||
|
||||
LOG_OP("\nProcessing func | [%d] params | [%d] locals | [%d] return\n",
|
||||
func->param_cell_num, func->local_cell_num, func->ret_cell_num);
|
||||
|
@ -4769,8 +4754,8 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
|
|||
param_count = func->func_type->param_count;
|
||||
param_types = func->func_type->types;
|
||||
|
||||
func_type.is_value_type = false;
|
||||
func_type.u.type = func->func_type;
|
||||
func_block_type.is_value_type = false;
|
||||
func_block_type.u.type = func->func_type;
|
||||
|
||||
local_count = func->local_count;
|
||||
local_types = func->local_types;
|
||||
|
@ -4794,7 +4779,7 @@ re_scan:
|
|||
}
|
||||
#endif
|
||||
|
||||
PUSH_CSP(LABEL_TYPE_FUNCTION, func_type, p);
|
||||
PUSH_CSP(LABEL_TYPE_FUNCTION, func_block_type, p);
|
||||
|
||||
while (p < p_end) {
|
||||
opcode = *p++;
|
||||
|
@ -5006,28 +4991,29 @@ re_scan:
|
|||
* fail */
|
||||
if (cur_block->label_type == LABEL_TYPE_IF
|
||||
&& !cur_block->else_addr) {
|
||||
uint32 param_count = 0, ret_count = 0;
|
||||
uint8 *param_types = NULL, *ret_types = NULL;
|
||||
BlockType *block_type = &cur_block->block_type;
|
||||
if (block_type->is_value_type) {
|
||||
if (block_type->u.value_type != VALUE_TYPE_VOID) {
|
||||
ret_count = 1;
|
||||
ret_types = &block_type->u.value_type;
|
||||
uint32 block_param_count = 0, block_ret_count = 0;
|
||||
uint8 *block_param_types = NULL, *block_ret_types = NULL;
|
||||
BlockType *cur_block_type = &cur_block->block_type;
|
||||
if (cur_block_type->is_value_type) {
|
||||
if (cur_block_type->u.value_type != VALUE_TYPE_VOID) {
|
||||
block_ret_count = 1;
|
||||
block_ret_types = &cur_block_type->u.value_type;
|
||||
}
|
||||
}
|
||||
else {
|
||||
param_count = block_type->u.type->param_count;
|
||||
ret_count = block_type->u.type->result_count;
|
||||
param_types = block_type->u.type->types;
|
||||
ret_types = block_type->u.type->types + param_count;
|
||||
block_param_count = cur_block_type->u.type->param_count;
|
||||
block_ret_count = cur_block_type->u.type->result_count;
|
||||
block_param_types = cur_block_type->u.type->types;
|
||||
block_ret_types =
|
||||
cur_block_type->u.type->types + block_param_count;
|
||||
}
|
||||
bh_assert(
|
||||
param_count == ret_count
|
||||
&& (!param_count
|
||||
|| !memcmp(param_types, ret_types, param_count)));
|
||||
(void)ret_types;
|
||||
(void)ret_count;
|
||||
(void)param_types;
|
||||
bh_assert(block_param_count == block_ret_count
|
||||
&& (!block_param_count
|
||||
|| !memcmp(block_param_types, block_ret_types,
|
||||
block_param_count)));
|
||||
(void)block_ret_types;
|
||||
(void)block_ret_count;
|
||||
(void)block_param_types;
|
||||
}
|
||||
|
||||
POP_CSP();
|
||||
|
@ -5291,8 +5277,7 @@ re_scan:
|
|||
&& !cur_block->is_stack_polymorphic));
|
||||
|
||||
if (available_stack_cell > 0) {
|
||||
if (*(loader_ctx->frame_ref - 1) == REF_I32
|
||||
|| *(loader_ctx->frame_ref - 1) == REF_F32) {
|
||||
if (is_32bit_type(*(loader_ctx->frame_ref - 1))) {
|
||||
loader_ctx->frame_ref--;
|
||||
loader_ctx->stack_cell_num--;
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
|
@ -5303,7 +5288,7 @@ re_scan:
|
|||
loader_ctx->dynamic_offset--;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
else if (is_64bit_type(*(loader_ctx->frame_ref - 1))) {
|
||||
loader_ctx->frame_ref -= 2;
|
||||
loader_ctx->stack_cell_num -= 2;
|
||||
#if (WASM_ENABLE_FAST_INTERP == 0) || (WASM_ENABLE_JIT != 0)
|
||||
|
@ -5317,6 +5302,9 @@ re_scan:
|
|||
loader_ctx->dynamic_offset -= 2;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
bh_assert(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
|
@ -5969,11 +5957,11 @@ re_scan:
|
|||
break;
|
||||
|
||||
case WASM_OP_I64_CONST:
|
||||
read_leb_int64(p, p_end, i64);
|
||||
read_leb_int64(p, p_end, i64_const);
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
skip_label();
|
||||
disable_emit = true;
|
||||
GET_CONST_OFFSET(VALUE_TYPE_I64, i64);
|
||||
GET_CONST_OFFSET(VALUE_TYPE_I64, i64_const);
|
||||
#endif
|
||||
PUSH_I64();
|
||||
break;
|
||||
|
@ -5983,9 +5971,9 @@ re_scan:
|
|||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
skip_label();
|
||||
disable_emit = true;
|
||||
bh_memcpy_s((uint8 *)&f32, sizeof(float32), p_org,
|
||||
bh_memcpy_s((uint8 *)&f32_const, sizeof(float32), p_org,
|
||||
sizeof(float32));
|
||||
GET_CONST_F32_OFFSET(VALUE_TYPE_F32, f32);
|
||||
GET_CONST_F32_OFFSET(VALUE_TYPE_F32, f32_const);
|
||||
#endif
|
||||
PUSH_F32();
|
||||
break;
|
||||
|
@ -5996,9 +5984,9 @@ re_scan:
|
|||
skip_label();
|
||||
disable_emit = true;
|
||||
/* Some MCU may require 8-byte align */
|
||||
bh_memcpy_s((uint8 *)&f64, sizeof(float64), p_org,
|
||||
bh_memcpy_s((uint8 *)&f64_const, sizeof(float64), p_org,
|
||||
sizeof(float64));
|
||||
GET_CONST_F64_OFFSET(VALUE_TYPE_F64, f64);
|
||||
GET_CONST_F64_OFFSET(VALUE_TYPE_F64, f64_const);
|
||||
#endif
|
||||
PUSH_F64();
|
||||
break;
|
||||
|
@ -6605,25 +6593,28 @@ re_scan:
|
|||
goto re_scan;
|
||||
|
||||
func->const_cell_num = loader_ctx->const_cell_num;
|
||||
if (func->const_cell_num > 0
|
||||
&& !(func->consts = func_const = loader_malloc(
|
||||
func->const_cell_num * 4, error_buf, error_buf_size))) {
|
||||
goto fail;
|
||||
}
|
||||
func_const_end = func->consts + func->const_cell_num * 4;
|
||||
/* reverse the const buf */
|
||||
for (int i = loader_ctx->num_const - 1; i >= 0; i--) {
|
||||
Const *c = (Const *)(loader_ctx->const_buf + i * sizeof(Const));
|
||||
if (c->value_type == VALUE_TYPE_F64
|
||||
|| c->value_type == VALUE_TYPE_I64) {
|
||||
bh_memcpy_s(func_const, (uint32)(func_const_end - func_const),
|
||||
&(c->value.f64), (uint32)sizeof(int64));
|
||||
func_const += sizeof(int64);
|
||||
}
|
||||
else {
|
||||
bh_memcpy_s(func_const, (uint32)(func_const_end - func_const),
|
||||
&(c->value.f32), (uint32)sizeof(int32));
|
||||
func_const += sizeof(int32);
|
||||
if (func->const_cell_num > 0) {
|
||||
int32 j;
|
||||
|
||||
if (!(func->consts = func_const = loader_malloc(
|
||||
func->const_cell_num * 4, error_buf, error_buf_size)))
|
||||
goto fail;
|
||||
|
||||
func_const_end = func->consts + func->const_cell_num * 4;
|
||||
/* reverse the const buf */
|
||||
for (j = loader_ctx->num_const - 1; j >= 0; j--) {
|
||||
Const *c = (Const *)(loader_ctx->const_buf + j * sizeof(Const));
|
||||
if (c->value_type == VALUE_TYPE_F64
|
||||
|| c->value_type == VALUE_TYPE_I64) {
|
||||
bh_memcpy_s(func_const, (uint32)(func_const_end - func_const),
|
||||
&(c->value.f64), (uint32)sizeof(int64));
|
||||
func_const += sizeof(int64);
|
||||
}
|
||||
else {
|
||||
bh_memcpy_s(func_const, (uint32)(func_const_end - func_const),
|
||||
&(c->value.f32), (uint32)sizeof(int32));
|
||||
func_const += sizeof(int32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6641,7 +6632,7 @@ fail:
|
|||
(void)u8;
|
||||
(void)u32;
|
||||
(void)i32;
|
||||
(void)i64;
|
||||
(void)i64_const;
|
||||
(void)global_count;
|
||||
(void)local_count;
|
||||
(void)local_offset;
|
||||
|
|
|
@ -222,11 +222,11 @@ handle_generay_query(WASMGDBServer *server, char *payload)
|
|||
WASMDebugMemoryInfo *mem_info = wasm_debug_instance_get_memregion(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, addr);
|
||||
if (mem_info) {
|
||||
char name[256];
|
||||
mem2hex(mem_info->name, name, strlen(mem_info->name));
|
||||
char name_buf[256];
|
||||
mem2hex(mem_info->name, name_buf, strlen(mem_info->name));
|
||||
sprintf(tmpbuf, "start:%lx;size:%lx;permissions:%s;name:%s;",
|
||||
(uint64)mem_info->start, mem_info->size,
|
||||
mem_info->permisson, name);
|
||||
mem_info->permisson, name_buf);
|
||||
write_packet(server, tmpbuf);
|
||||
wasm_debug_instance_destroy_memregion(
|
||||
(WASMDebugInstance *)server->thread->debug_instance, mem_info);
|
||||
|
|
|
@ -112,7 +112,7 @@ add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
|
|||
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")
|
||||
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow")
|
||||
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
|
||||
|
||||
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
|
||||
|
|
Loading…
Reference in New Issue
Block a user