Fix libc-wasi not working in spawned exec_env (#1053)

In thread_manager.c, `wasm_cluster_spawn_exec_env` creates a new module
instance but not sets wasi_ctx, so when the new exec_env calls wasm function
which uses WASI API, the WASI API functions in `libc_wasi_wrapper.c` will get
null result in calling `get_wasi_ctx`  and then return `wasi_errno`.

Signed-off-by: HangedFish <bravohangedman@outlook.com>
This commit is contained in:
Hanged Fish 2022-03-22 12:17:14 +08:00 committed by GitHub
parent 310b9ca0d8
commit a02cc6626d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -362,6 +362,9 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasm_module_t module;
wasm_module_inst_t new_module_inst;
#if WASM_ENABLE_LIBC_WASI != 0
WASIContext *wasi_ctx;
#endif
WASMExecEnv *new_exec_env;
uint32 aux_stack_start, aux_stack_size;
uint32 stack_size = 8192;
@ -393,6 +396,11 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
wasm_runtime_set_custom_data_internal(
new_module_inst, wasm_runtime_get_custom_data(module_inst));
#if WASM_ENABLE_LIBC_WASI != 0
wasi_ctx = wasm_runtime_get_wasi_ctx(module_inst);
wasm_runtime_set_wasi_ctx(new_module_inst, wasi_ctx);
#endif
new_exec_env = wasm_exec_env_create_internal(new_module_inst,
exec_env->wasm_stack_size);
if (!new_exec_env)