Skip to content

Commit 207da7b

Browse files
authored
updating WASI stdio handle initialization and build options for UVWASI (#4260)
1 parent 3580d1a commit 207da7b

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4128,10 +4128,16 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
41284128
#endif
41294129

41304130
#if WASM_ENABLE_LIBC_WASI != 0
4131+
#if WASM_ENABLE_UVWASI == 0
41314132
module->wasi_args.stdio[0] = os_invalid_raw_handle();
41324133
module->wasi_args.stdio[1] = os_invalid_raw_handle();
41334134
module->wasi_args.stdio[2] = os_invalid_raw_handle();
4134-
#endif
4135+
#else
4136+
module->wasi_args.stdio[0] = os_get_invalid_handle();
4137+
module->wasi_args.stdio[1] = os_get_invalid_handle();
4138+
module->wasi_args.stdio[2] = os_get_invalid_handle();
4139+
#endif /* WASM_ENABLE_UVWASI == 0 */
4140+
#endif /* WASM_ENABLE_LIBC_WASI != 0 */
41354141

41364142
return module;
41374143
#if WASM_ENABLE_GC != 0

core/iwasm/common/wasm_runtime_common.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,11 +3886,15 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
38863886
init_options.allocator = &uvwasi_allocator;
38873887
init_options.argc = argc;
38883888
init_options.argv = (const char **)argv;
3889-
init_options.in = (stdinfd != -1) ? (uvwasi_fd_t)stdinfd : init_options.in;
3890-
init_options.out =
3891-
(stdoutfd != -1) ? (uvwasi_fd_t)stdoutfd : init_options.out;
3892-
init_options.err =
3893-
(stderrfd != -1) ? (uvwasi_fd_t)stderrfd : init_options.err;
3889+
init_options.in = (stdinfd != os_get_invalid_handle())
3890+
? (uvwasi_fd_t)stdinfd
3891+
: init_options.in;
3892+
init_options.out = (stdoutfd != os_get_invalid_handle())
3893+
? (uvwasi_fd_t)stdoutfd
3894+
: init_options.out;
3895+
init_options.err = (stderrfd != os_get_invalid_handle())
3896+
? (uvwasi_fd_t)stderrfd
3897+
: init_options.err;
38943898

38953899
if (dir_count > 0) {
38963900
init_options.preopenc = dir_count;

core/iwasm/interpreter/wasm_loader.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6404,10 +6404,16 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
64046404
#endif
64056405

64066406
#if WASM_ENABLE_LIBC_WASI != 0
6407+
#if WASM_ENABLE_UVWASI == 0
64076408
module->wasi_args.stdio[0] = os_invalid_raw_handle();
64086409
module->wasi_args.stdio[1] = os_invalid_raw_handle();
64096410
module->wasi_args.stdio[2] = os_invalid_raw_handle();
6410-
#endif
6411+
#else
6412+
module->wasi_args.stdio[0] = os_get_invalid_handle();
6413+
module->wasi_args.stdio[1] = os_get_invalid_handle();
6414+
module->wasi_args.stdio[2] = os_get_invalid_handle();
6415+
#endif /* WASM_ENABLE_UVWASI == 0 */
6416+
#endif /* WASM_ENABLE_LIBC_WASI != 0 */
64116417

64126418
(void)ret;
64136419
return module;

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3140,10 +3140,16 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
31403140
#endif
31413141

31423142
#if WASM_ENABLE_LIBC_WASI != 0
3143+
#if WASM_ENABLE_LIBC_UVWASI == 0
31433144
module->wasi_args.stdio[0] = os_invalid_raw_handle();
31443145
module->wasi_args.stdio[1] = os_invalid_raw_handle();
31453146
module->wasi_args.stdio[2] = os_invalid_raw_handle();
3146-
#endif
3147+
#else
3148+
module->wasi_args.stdio[0] = os_get_invalid_handle();
3149+
module->wasi_args.stdio[1] = os_get_invalid_handle();
3150+
module->wasi_args.stdio[2] = os_get_invalid_handle();
3151+
#endif /* WASM_ENABLE_UVWASI == 0 */
3152+
#endif /* WASM_ENABLE_LIBC_WASI != 0 */
31473153

31483154
(void)ret;
31493155
return module;

0 commit comments

Comments
 (0)