Merge branch main into dev/wasi-libc-windows

This commit is contained in:
Wenyong Huang
2023-08-23 17:05:19 +08:00
77 changed files with 1903 additions and 588 deletions

View File

@ -202,7 +202,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
if (num_bytes_per_page < heap_size) {
set_error_buf(error_buf, error_buf_size,
"failed to insert app heap into linear memory, "
"try using `--heap_size=0` option");
"try using `--heap-size=0` option");
return NULL;
}
}
@ -261,7 +261,7 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
if (init_page_count > DEFAULT_MAX_PAGES) {
set_error_buf(error_buf, error_buf_size,
"failed to insert app heap into linear memory, "
"try using `--heap_size=0` option");
"try using `--heap-size=0` option");
return NULL;
}
else if (init_page_count == DEFAULT_MAX_PAGES) {
@ -1840,7 +1840,7 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
for (i = 0; i < module->data_seg_count; i++) {
WASMMemoryInstance *memory = NULL;
uint8 *memory_data = NULL;
uint32 memory_size = 0;
uint64 memory_size = 0;
WASMDataSeg *data_seg = module->data_segments[i];
#if WASM_ENABLE_BULK_MEMORY != 0
@ -1853,7 +1853,8 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
bh_assert(memory);
memory_data = memory->memory_data;
memory_size = memory->num_bytes_per_page * memory->cur_page_count;
memory_size =
(uint64)memory->num_bytes_per_page * memory->cur_page_count;
bh_assert(memory_data || memory_size == 0);
bh_assert(data_seg->base_offset.init_expr_type
@ -1899,7 +1900,7 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
/* check offset + length(could be zero) */
length = data_seg->data_length;
if (base_offset + length > memory_size) {
if ((uint64)base_offset + length > memory_size) {
LOG_DEBUG("base_offset(%d) + length(%d) > memory_size(%d)",
base_offset, length, memory_size);
#if WASM_ENABLE_REF_TYPES != 0
@ -1913,8 +1914,9 @@ wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
}
if (memory_data) {
bh_memcpy_s(memory_data + base_offset, memory_size - base_offset,
data_seg->data, length);
bh_memcpy_s(memory_data + base_offset,
(uint32)memory_size - base_offset, data_seg->data,
length);
}
}
@ -2228,8 +2230,8 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
}
#endif
if (module_inst->e->c_api_func_imports)
wasm_runtime_free(module_inst->e->c_api_func_imports);
if (module_inst->e->common.c_api_func_imports)
wasm_runtime_free(module_inst->e->common.c_api_func_imports);
if (!is_sub_inst) {
#if WASM_ENABLE_LIBC_WASI != 0
@ -3094,11 +3096,7 @@ llvm_jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
{
bool ret;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == exec_env->module_inst->module_type) {
return aot_call_indirect(exec_env, tbl_idx, elem_idx, argc, argv);
}
#endif
bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode);
ret = call_indirect(exec_env, tbl_idx, elem_idx, argc, argv, false, 0);
#ifdef OS_ENABLE_HW_BOUND_CHECK
@ -3125,11 +3123,7 @@ llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
char buf[96];
bool ret = false;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == exec_env->module_inst->module_type) {
return aot_invoke_native(exec_env, func_idx, argc, argv);
}
#endif
bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode);
module_inst = (WASMModuleInstance *)wasm_runtime_get_module_inst(exec_env);
module = module_inst->module;
@ -3142,8 +3136,9 @@ llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
import_func = &module->import_functions[func_idx].u.function;
if (import_func->call_conv_wasm_c_api) {
if (module_inst->e->c_api_func_imports) {
c_api_func_import = module_inst->e->c_api_func_imports + func_idx;
if (module_inst->e->common.c_api_func_imports) {
c_api_func_import =
module_inst->e->common.c_api_func_imports + func_idx;
func_ptr = c_api_func_import->func_ptr_linked;
}
else {
@ -3198,11 +3193,7 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
uint8 *maddr;
uint64 seg_len = 0;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == module_inst->module_type) {
return aot_memory_init(module_inst, seg_index, offset, len, dst);
}
#endif
bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
memory_inst = wasm_get_default_memory(module_inst);
module = module_inst->module;
@ -3228,11 +3219,7 @@ llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
bool
llvm_jit_data_drop(WASMModuleInstance *module_inst, uint32 seg_index)
{
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == module_inst->module_type) {
return aot_data_drop(module_inst, seg_index);
}
#endif
bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
module_inst->module->data_segments[seg_index]->data_length = 0;
/* Currently we can't free the dropped data segment
@ -3247,11 +3234,7 @@ llvm_jit_drop_table_seg(WASMModuleInstance *module_inst, uint32 tbl_seg_idx)
{
WASMTableSeg *tbl_segs;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == module_inst->module_type) {
return aot_drop_table_seg(module_inst, tbl_seg_idx);
}
#endif
bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
tbl_segs = module_inst->module->table_segments;
tbl_segs[tbl_seg_idx].is_dropped = true;
@ -3265,12 +3248,7 @@ llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx,
WASMTableInstance *tbl_inst;
WASMTableSeg *tbl_seg;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == module_inst->module_type) {
return aot_table_init(module_inst, tbl_idx, tbl_seg_idx, length,
src_offset, dst_offset);
}
#endif
bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
tbl_inst = wasm_get_table_inst(module_inst, tbl_idx);
tbl_seg = module_inst->module->table_segments + tbl_seg_idx;
@ -3313,13 +3291,7 @@ llvm_jit_table_copy(WASMModuleInstance *module_inst, uint32 src_tbl_idx,
WASMTableInstance *src_tbl_inst;
WASMTableInstance *dst_tbl_inst;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == module_inst->module_type) {
aot_table_copy(module_inst, src_tbl_idx, dst_tbl_idx, length,
src_offset, dst_offset);
return;
}
#endif
bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
src_tbl_inst = wasm_get_table_inst(module_inst, src_tbl_idx);
dst_tbl_inst = wasm_get_table_inst(module_inst, dst_tbl_idx);
@ -3350,12 +3322,7 @@ llvm_jit_table_fill(WASMModuleInstance *module_inst, uint32 tbl_idx,
{
WASMTableInstance *tbl_inst;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == module_inst->module_type) {
aot_table_fill(module_inst, tbl_idx, length, val, data_offset);
return;
}
#endif
bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
tbl_inst = wasm_get_table_inst(module_inst, tbl_idx);
bh_assert(tbl_inst);
@ -3377,11 +3344,7 @@ llvm_jit_table_grow(WASMModuleInstance *module_inst, uint32 tbl_idx,
WASMTableInstance *tbl_inst;
uint32 i, orig_size, total_size;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == module_inst->module_type) {
return aot_table_grow(module_inst, tbl_idx, inc_size, init_val);
}
#endif
bh_assert(module_inst->module_type == Wasm_Module_Bytecode);
tbl_inst = wasm_get_table_inst(module_inst, tbl_idx);
if (!tbl_inst) {
@ -3421,11 +3384,7 @@ llvm_jit_alloc_frame(WASMExecEnv *exec_env, uint32 func_index)
WASMInterpFrame *frame;
uint32 size;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == exec_env->module_inst->module_type) {
return aot_alloc_frame(exec_env, func_index);
}
#endif
bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode);
module_inst = (WASMModuleInstance *)exec_env->module_inst;
size = wasm_interp_interp_frame_size(0);
@ -3454,12 +3413,7 @@ llvm_jit_free_frame(WASMExecEnv *exec_env)
WASMInterpFrame *frame;
WASMInterpFrame *prev_frame;
#if WASM_ENABLE_JIT != 0
if (Wasm_Module_AoT == exec_env->module_inst->module_type) {
aot_free_frame(exec_env);
return;
}
#endif
bh_assert(exec_env->module_inst->module_type == Wasm_Module_Bytecode);
frame = wasm_exec_env_get_cur_frame(exec_env);
prev_frame = frame->prev_frame;