Quellcode durchsuchen

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>
Hanged Fish vor 4 Jahren
Ursprung
Commit
a02cc6626d
1 geänderte Dateien mit 8 neuen und 0 gelöschten Zeilen
  1. 8 0
      core/iwasm/libraries/thread-mgr/thread_manager.c

+ 8 - 0
core/iwasm/libraries/thread-mgr/thread_manager.c

@@ -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)