diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index a87aee0a7..2f7e6c9f2 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -4226,15 +4226,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) #endif #if WASM_ENABLE_LIBC_WASI != 0 -#if WASM_ENABLE_UVWASI == 0 - module->wasi_args.stdio[0] = os_invalid_raw_handle(); - module->wasi_args.stdio[1] = os_invalid_raw_handle(); - module->wasi_args.stdio[2] = os_invalid_raw_handle(); -#else - module->wasi_args.stdio[0] = os_get_invalid_handle(); - module->wasi_args.stdio[1] = os_get_invalid_handle(); - module->wasi_args.stdio[2] = os_get_invalid_handle(); -#endif /* WASM_ENABLE_UVWASI == 0 */ + wasi_args_set_defaults(&module->wasi_args); #endif /* WASM_ENABLE_LIBC_WASI != 0 */ return module; diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 943b46fc4..26283b3f8 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3438,6 +3438,21 @@ wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst, #if WASM_ENABLE_LIBC_WASI != 0 +void +wasi_args_set_defaults(WASIArguments *args) +{ + memset(args, 0, sizeof(*args)); +#if WASM_ENABLE_UVWASI == 0 + args->stdio[0] = os_invalid_raw_handle(); + args->stdio[1] = os_invalid_raw_handle(); + args->stdio[2] = os_invalid_raw_handle(); +#else + args->stdio[0] = os_get_invalid_handle(); + args->stdio[1] = os_get_invalid_handle(); + args->stdio[2] = os_get_invalid_handle(); +#endif /* WASM_ENABLE_UVWASI == 0 */ +} + static WASIArguments * get_wasi_args_from_module(wasm_module_t module) { diff --git a/core/iwasm/common/wasm_runtime_common.h b/core/iwasm/common/wasm_runtime_common.h index 324620bef..a315c75da 100644 --- a/core/iwasm/common/wasm_runtime_common.h +++ b/core/iwasm/common/wasm_runtime_common.h @@ -1118,6 +1118,9 @@ wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst); WASM_RUNTIME_API_EXTERN uint32_t wasm_runtime_get_wasi_exit_code(WASMModuleInstanceCommon *module_inst); +void +wasi_args_set_defaults(WASIArguments *args); + bool wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, const char *dir_list[], uint32 dir_count, diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index e89e91e0d..55128795c 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -6712,15 +6712,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) #endif #if WASM_ENABLE_LIBC_WASI != 0 -#if WASM_ENABLE_UVWASI == 0 - module->wasi_args.stdio[0] = os_invalid_raw_handle(); - module->wasi_args.stdio[1] = os_invalid_raw_handle(); - module->wasi_args.stdio[2] = os_invalid_raw_handle(); -#else - module->wasi_args.stdio[0] = os_get_invalid_handle(); - module->wasi_args.stdio[1] = os_get_invalid_handle(); - module->wasi_args.stdio[2] = os_get_invalid_handle(); -#endif /* WASM_ENABLE_UVWASI == 0 */ + wasi_args_set_defaults(&module->wasi_args); #endif /* WASM_ENABLE_LIBC_WASI != 0 */ (void)ret; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 771538a14..6fff2fa17 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -3316,15 +3316,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) #endif #if WASM_ENABLE_LIBC_WASI != 0 -#if WASM_ENABLE_LIBC_UVWASI == 0 - module->wasi_args.stdio[0] = os_invalid_raw_handle(); - module->wasi_args.stdio[1] = os_invalid_raw_handle(); - module->wasi_args.stdio[2] = os_invalid_raw_handle(); -#else - module->wasi_args.stdio[0] = os_get_invalid_handle(); - module->wasi_args.stdio[1] = os_get_invalid_handle(); - module->wasi_args.stdio[2] = os_get_invalid_handle(); -#endif /* WASM_ENABLE_UVWASI == 0 */ + wasi_args_set_defaults(&module->wasi_args); #endif /* WASM_ENABLE_LIBC_WASI != 0 */ (void)ret;