Grab cluster->lock when modifying exec_env->module_inst (#2685)

Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2680

And when switching back to the original module_inst, propagate exception if any.

cf. https://github.com/bytecodealliance/wasm-micro-runtime/issues/2512
This commit is contained in:
YAMAMOTO Takashi
2023-11-09 19:56:02 +09:00
committed by GitHub
parent 797e534cec
commit 24c4d256b3
8 changed files with 103 additions and 36 deletions

View File

@ -1013,7 +1013,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
}
/* - module_inst */
exec_env->module_inst = (WASMModuleInstanceCommon *)sub_module_inst;
wasm_exec_env_set_module_inst(exec_env,
(WASMModuleInstanceCommon *)sub_module_inst);
/* - aux_stack_boundary */
aux_stack_origin_boundary = exec_env->aux_stack_boundary.boundary;
exec_env->aux_stack_boundary.boundary =
@ -1035,15 +1036,8 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
prev_frame->ip = ip;
exec_env->aux_stack_boundary.boundary = aux_stack_origin_boundary;
exec_env->aux_stack_bottom.bottom = aux_stack_origin_bottom;
exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
/* transfer exception if it is thrown */
if (wasm_copy_exception(sub_module_inst, NULL)) {
bh_memcpy_s(module_inst->cur_exception,
sizeof(module_inst->cur_exception),
sub_module_inst->cur_exception,
sizeof(sub_module_inst->cur_exception));
}
wasm_exec_env_restore_module_inst(exec_env,
(WASMModuleInstanceCommon *)module_inst);
}
#endif