Skip to content

Commit cf8b932

Browse files
committed
initialize WASI stdio handles to invalid for better error handling
1 parent ff10b86 commit cf8b932

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,16 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
41204120
}
41214121
#endif
41224122

4123+
#if WASM_ENABLE_LIBC_WASI != 0
4124+
/*
4125+
* learned from all implementations of `os_get_invalid_handle()`
4126+
* that invalid handles across all platforms are represented by -1.
4127+
*/
4128+
module->wasi_args.stdio[0] = -1;
4129+
module->wasi_args.stdio[1] = -1;
4130+
module->wasi_args.stdio[2] = -1;
4131+
#endif
4132+
41234133
return module;
41244134
#if WASM_ENABLE_GC != 0
41254135
fail2:

core/iwasm/interpreter/wasm_loader.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6368,6 +6368,16 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
63686368
}
63696369
#endif
63706370

6371+
#if WASM_ENABLE_LIBC_WASI != 0
6372+
/*
6373+
* learned from all implementations of `os_get_invalid_handle()`
6374+
* that invalid handles across all platforms are represented by -1.
6375+
*/
6376+
module->wasi_args.stdio[0] = -1;
6377+
module->wasi_args.stdio[1] = -1;
6378+
module->wasi_args.stdio[2] = -1;
6379+
#endif
6380+
63716381
(void)ret;
63726382
return module;
63736383

0 commit comments

Comments
 (0)