mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-15 08:48:33 +00:00
Backup module inst in aot_create_exec_env_and_call_function
This commit is contained in:
parent
653efecd02
commit
3cd0254564
|
@ -1590,6 +1590,7 @@ aot_create_exec_env_and_call_function(AOTModuleInstance *module_inst,
|
||||||
uint32 argv[])
|
uint32 argv[])
|
||||||
{
|
{
|
||||||
WASMExecEnv *exec_env = NULL, *existing_exec_env = NULL;
|
WASMExecEnv *exec_env = NULL, *existing_exec_env = NULL;
|
||||||
|
WASMModuleInstanceCommon *prev_module_inst;
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
#if defined(OS_ENABLE_HW_BOUND_CHECK)
|
#if defined(OS_ENABLE_HW_BOUND_CHECK)
|
||||||
|
@ -1608,8 +1609,21 @@ aot_create_exec_env_and_call_function(AOTModuleInstance *module_inst,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backup the exec_env's module instance and then set it to current module
|
||||||
|
* instance, since in some cases, a wasm instance might call another with
|
||||||
|
* the help of host functions, which leads to recursive callings between
|
||||||
|
* host embedder and aot functions, and all the instances in the recursive
|
||||||
|
* call chain share the same exec_env.
|
||||||
|
*/
|
||||||
|
prev_module_inst = exec_env->module_inst;
|
||||||
|
exec_env->module_inst = (WASMModuleInstanceCommon *)module_inst;
|
||||||
|
|
||||||
ret = aot_call_function(exec_env, func, argc, argv);
|
ret = aot_call_function(exec_env, func, argc, argv);
|
||||||
|
|
||||||
|
/* Restore the module instance */
|
||||||
|
exec_env->module_inst = prev_module_inst;
|
||||||
|
|
||||||
/* don't destroy the exec_env if it's searched from the cluster */
|
/* don't destroy the exec_env if it's searched from the cluster */
|
||||||
if (!existing_exec_env)
|
if (!existing_exec_env)
|
||||||
wasm_exec_env_destroy(exec_env);
|
wasm_exec_env_destroy(exec_env);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user