diff --git a/.github/workflows/coding_guidelines.yml b/.github/workflows/coding_guidelines.yml index 259e84fe51..17d60ac43d 100644 --- a/.github/workflows/coding_guidelines.yml +++ b/.github/workflows/coding_guidelines.yml @@ -16,7 +16,7 @@ concurrency: jobs: compliance_job: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: checkout uses: actions/checkout@v3 diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index abd4539be0..0799d625f5 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -2807,6 +2807,7 @@ aot_create_call_stack(struct WASMExecEnv *exec_env) total_len += \ wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \ if ((!print) && buf && (len == 0)) { \ + exception_unlock(module_inst); \ return total_len; \ } \ } while (0) @@ -2829,6 +2830,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len) return 0; } + exception_lock(module_inst); snprintf(line_buf, sizeof(line_buf), "\n"); PRINT_OR_DUMP(); @@ -2837,6 +2839,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len) uint32 line_length, i; if (!bh_vector_get(module_inst->frames, n, &frame)) { + exception_unlock(module_inst); return 0; } @@ -2867,6 +2870,7 @@ aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len) } snprintf(line_buf, sizeof(line_buf), "\n"); PRINT_OR_DUMP(); + exception_unlock(module_inst); return total_len + 1; } diff --git a/core/iwasm/common/wasm_application.c b/core/iwasm/common/wasm_application.c index 795d65c8c5..02999584f6 100644 --- a/core/iwasm/common/wasm_application.c +++ b/core/iwasm/common/wasm_application.c @@ -231,7 +231,7 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[]) { bool ret; -#if (WASM_ENABLE_MEMORY_PROFILING != 0) || (WASM_ENABLE_DUMP_CALL_STACK != 0) +#if (WASM_ENABLE_MEMORY_PROFILING != 0) WASMExecEnv *exec_env; #endif @@ -251,14 +251,6 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, if (ret) ret = wasm_runtime_get_exception(module_inst) == NULL; -#if WASM_ENABLE_DUMP_CALL_STACK != 0 - if (!ret) { - exec_env = wasm_runtime_get_exec_env_singleton(module_inst); - if (exec_env) - wasm_runtime_dump_call_stack(exec_env); - } -#endif - return ret; } diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 2a48c1bde9..ce090d1f00 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -4209,7 +4209,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num); unsigned i; bool copy_argv_from_frame = true; - char exception[EXCEPTION_BUF_LEN]; if (argc < function->param_cell_num) { char buf[128]; @@ -4342,8 +4341,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, wasm_interp_dump_call_stack(exec_env, true, NULL, 0); } #endif - wasm_copy_exception(module_inst, exception); - LOG_DEBUG("meet an exception %s", exception); } wasm_exec_env_set_cur_frame(exec_env, prev_frame); diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 229a2151dc..e565c2c89c 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -3945,7 +3945,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, /* This frame won't be used by JITed code, so only allocate interp frame here. */ unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num); - char exception[EXCEPTION_BUF_LEN]; if (argc < function->param_cell_num) { char buf[128]; @@ -4030,8 +4029,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env, wasm_interp_dump_call_stack(exec_env, true, NULL, 0); } #endif - wasm_copy_exception(module_inst, exception); - LOG_DEBUG("meet an exception %s", exception); } wasm_exec_env_set_cur_frame(exec_env, prev_frame); diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index af2a61c88c..8fb19d52e8 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -2915,6 +2915,7 @@ wasm_interp_create_call_stack(struct WASMExecEnv *exec_env) total_len += \ wasm_runtime_dump_line_buf_impl(line_buf, print, &buf, &len); \ if ((!print) && buf && (len == 0)) { \ + exception_unlock(module_inst); \ return total_len; \ } \ } while (0) @@ -2939,6 +2940,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf, return 0; } + exception_lock(module_inst); snprintf(line_buf, sizeof(line_buf), "\n"); PRINT_OR_DUMP(); @@ -2947,6 +2949,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf, uint32 line_length, i; if (!bh_vector_get(module_inst->frames, n, &frame)) { + exception_unlock(module_inst); return 0; } @@ -2977,6 +2980,7 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf, } snprintf(line_buf, sizeof(line_buf), "\n"); PRINT_OR_DUMP(); + exception_unlock(module_inst); return total_len + 1; } diff --git a/product-mini/platforms/posix/main.c b/product-mini/platforms/posix/main.c index 0051e628cc..b7d755410f 100644 --- a/product-mini/platforms/posix/main.c +++ b/product-mini/platforms/posix/main.c @@ -120,8 +120,7 @@ app_instance_main(wasm_module_inst_t module_inst) const char *exception; wasm_application_execute_main(module_inst, app_argc, app_argv); - if ((exception = wasm_runtime_get_exception(module_inst))) - printf("%s\n", exception); + exception = wasm_runtime_get_exception(module_inst); return exception; } @@ -977,17 +976,20 @@ main(int argc, char *argv[]) #endif ret = 0; + const char *exception = NULL; if (is_repl_mode) { app_instance_repl(wasm_module_inst); } else if (func_name) { - if (app_instance_func(wasm_module_inst, func_name)) { + exception = app_instance_func(wasm_module_inst, func_name); + if (exception) { /* got an exception */ ret = 1; } } else { - if (app_instance_main(wasm_module_inst)) { + exception = app_instance_main(wasm_module_inst); + if (exception) { /* got an exception */ ret = 1; } @@ -1000,6 +1002,9 @@ main(int argc, char *argv[]) } #endif + if (exception) + printf("%s\n", exception); + #if WASM_ENABLE_STATIC_PGO != 0 && WASM_ENABLE_AOT != 0 if (get_package_type(wasm_file_buf, wasm_file_size) == Wasm_Module_AoT && gen_prof_file) diff --git a/product-mini/platforms/windows/main.c b/product-mini/platforms/windows/main.c index 121be41951..985c9e6c78 100644 --- a/product-mini/platforms/windows/main.c +++ b/product-mini/platforms/windows/main.c @@ -77,8 +77,7 @@ app_instance_main(wasm_module_inst_t module_inst) const char *exception; wasm_application_execute_main(module_inst, app_argc, app_argv); - if ((exception = wasm_runtime_get_exception(module_inst))) - printf("%s\n", exception); + exception = wasm_runtime_get_exception(module_inst); return exception; } @@ -545,17 +544,20 @@ main(int argc, char *argv[]) #endif ret = 0; + const char *exception = NULL; if (is_repl_mode) { app_instance_repl(wasm_module_inst); } else if (func_name) { - if (app_instance_func(wasm_module_inst, func_name)) { + exception = app_instance_func(wasm_module_inst, func_name); + if (exception) { /* got an exception */ ret = 1; } } else { - if (app_instance_main(wasm_module_inst)) { + exception = app_instance_main(wasm_module_inst); + if (exception) { /* got an exception */ ret = 1; } @@ -568,6 +570,9 @@ main(int argc, char *argv[]) } #endif + if (exception) + printf("%s\n", exception); + #if WASM_ENABLE_DEBUG_INTERP != 0 fail4: #endif