diff --git a/core/app-mgr/app-manager/module_wasm_app.c b/core/app-mgr/app-manager/module_wasm_app.c index 5e2b2efc..7b826d6d 100644 --- a/core/app-mgr/app-manager/module_wasm_app.c +++ b/core/app-mgr/app-manager/module_wasm_app.c @@ -492,9 +492,16 @@ wasm_app_routine(void *arg) fail2: /* Call WASM app onDestroy() method if there is */ func_onDestroy = app_manager_lookup_function(inst, "_on_destroy", "()"); - if (func_onDestroy) - wasm_runtime_call_wasm(wasm_app_data->exec_env, func_onDestroy, 0, - NULL); + if (func_onDestroy) { + if (!wasm_runtime_call_wasm(wasm_app_data->exec_env, func_onDestroy, 0, + NULL)) { + const char *exception = wasm_runtime_get_exception(inst); + bh_assert(exception); + app_manager_printf("Got exception running WASM code: %s\n", + exception); + wasm_runtime_clear_exception(inst); + } + } fail1: diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index ac3c7f9a..bab053fc 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -654,6 +654,10 @@ memories_instantiate(AOTModuleInstance *module_inst, AOTModule *module, /* Get default memory instance */ memory_inst = aot_get_default_memory(module_inst); + if (!memory_inst) { + /* Ignore setting memory init data if no memory inst is created */ + return true; + } for (i = 0; i < module->mem_init_data_count; i++) { data_seg = module->mem_init_data_list[i]; @@ -1794,9 +1798,9 @@ aot_module_malloc(AOTModuleInstance *module_inst, uint32 size, malloc_func = aot_lookup_function(module_inst, malloc_func_name, malloc_func_sig); - bh_assert(malloc_func); - if (!execute_malloc_function(module_inst, malloc_func, retain_func, - size, &offset)) { + if (!malloc_func + || !execute_malloc_function(module_inst, malloc_func, retain_func, + size, &offset)) { return 0; } addr = offset ? (uint8 *)memory_inst->memory_data.ptr + offset : NULL; @@ -1889,8 +1893,8 @@ aot_module_free(AOTModuleInstance *module_inst, uint32 ptr) if (!free_func && module->retain_func_index != (uint32)-1) free_func = aot_lookup_function(module_inst, "__unpin", "(i)i"); - bh_assert(free_func); - execute_free_function(module_inst, free_func, ptr); + if (free_func) + execute_free_function(module_inst, free_func, ptr); } } } diff --git a/core/iwasm/common/wasm_exec_env.c b/core/iwasm/common/wasm_exec_env.c index 1d5da534..e98fdaa6 100644 --- a/core/iwasm/common/wasm_exec_env.c +++ b/core/iwasm/common/wasm_exec_env.c @@ -54,7 +54,6 @@ wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst, if (!(exec_env->current_status = wasm_cluster_create_exenv_status())) goto fail4; #endif - #endif exec_env->module_inst = module_inst; diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index bc25df1f..858263a9 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -827,26 +827,28 @@ wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot, { WASMModuleCommon *module_common; -#if WASM_ENABLE_INTERP != 0 if (!is_aot) { +#if WASM_ENABLE_INTERP != 0 module_common = (WASMModuleCommon *)wasm_load_from_sections( section_list, error_buf, error_buf_size); return register_module_with_null_name(module_common, error_buf, error_buf_size); - } #endif + } + else { #if WASM_ENABLE_AOT != 0 - if (is_aot) { module_common = (WASMModuleCommon *)aot_load_from_sections( section_list, error_buf, error_buf_size); return register_module_with_null_name(module_common, error_buf, error_buf_size); - } #endif + } +#if WASM_ENABLE_INTERP == 0 || WASM_ENABLE_AOT == 0 set_error_buf(error_buf, error_buf_size, "WASM module load failed: invalid section list type"); return NULL; +#endif } void diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index f1c62fd5..7bba057d 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -141,7 +141,7 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, comp_ctx->comp_data->memories[0].num_bytes_per_page; uint32 init_page_count = comp_ctx->comp_data->memories[0].mem_init_page_count; - uint64 mem_data_size = num_bytes_per_page * init_page_count; + uint64 mem_data_size = (uint64)num_bytes_per_page * init_page_count; if (mem_offset + bytes <= mem_data_size) { /* inside memory space */ diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index dc68fcc5..870a5695 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -222,6 +222,8 @@ memory_instantiate(WASMModuleInstance *module_inst, uint32 num_bytes_per_page, /* Adjust __heap_base global value */ global_idx = module->aux_heap_base_global_index; + bh_assert(module_inst->globals + && global_idx < module_inst->global_count); global_addr = module_inst->global_data + module_inst->globals[global_idx].data_offset; *(uint32 *)global_addr = aux_heap_base; @@ -403,19 +405,6 @@ memories_instantiate(const WASMModule *module, WASMModuleInstance *module_inst, } } - if (mem_index == 0) { - /** - * no import memory and define memory, but still need heap - * for wasm code - */ - if (!(memory = memories[mem_index++] = - memory_instantiate(module_inst, 0, 0, 0, heap_size, 0, - error_buf, error_buf_size))) { - memories_deinstantiate(module_inst, memories, memory_count); - return NULL; - } - } - bh_assert(mem_index == memory_count); (void)module_inst; return memories; diff --git a/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c b/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c index cee24770..418d0ca2 100644 --- a/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c +++ b/samples/gui/wasm-runtime-wgl/src/platform/linux/iwasm_main.c @@ -175,9 +175,11 @@ func_server_mode(void *arg) struct sockaddr_in serv_addr, cli_addr; int n; char buff[MAX]; - struct sigaction sa; + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); sigaction(SIGPIPE, &sa, 0); /* First call to socket() function */ diff --git a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c b/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c index a116e98f..9fb63c83 100644 --- a/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c +++ b/samples/littlevgl/vgl-wasm-runtime/src/platform/linux/iwasm_main.c @@ -169,9 +169,11 @@ func_server_mode(void *arg) struct sockaddr_in serv_addr, cli_addr; int n; char buff[MAX]; - struct sigaction sa; + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); sigaction(SIGPIPE, &sa, 0); /* First call to socket() function */ diff --git a/samples/simple/src/iwasm_main.c b/samples/simple/src/iwasm_main.c index 0bb33b37..d6315f3a 100644 --- a/samples/simple/src/iwasm_main.c +++ b/samples/simple/src/iwasm_main.c @@ -178,9 +178,11 @@ func_server_mode(void *arg) struct sockaddr_in serv_addr, cli_addr; int n; char buff[MAX]; - struct sigaction sa; + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); sigaction(SIGPIPE, &sa, 0); /* First call to socket() function */ diff --git a/test-tools/host-tool/src/transport.c b/test-tools/host-tool/src/transport.c index edadde25..d4edf4f1 100644 --- a/test-tools/host-tool/src/transport.c +++ b/test-tools/host-tool/src/transport.c @@ -125,6 +125,7 @@ bool udp_send(const char *address, int port, const char *buf, int len) { int sockfd; + ssize_t size_sent; struct sockaddr_in servaddr; if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) @@ -136,11 +137,11 @@ udp_send(const char *address, int port, const char *buf, int len) servaddr.sin_port = htons(port); servaddr.sin_addr.s_addr = INADDR_ANY; - sendto(sockfd, buf, len, MSG_CONFIRM, (const struct sockaddr *)&servaddr, - sizeof(servaddr)); + size_sent = sendto(sockfd, buf, len, MSG_CONFIRM, + (const struct sockaddr *)&servaddr, sizeof(servaddr)); close(sockfd); - return true; + return (size_sent != -1) ? true : false; } bool