diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index c36da6bcf..96fec8d77 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -4121,13 +4121,9 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) #endif #if WASM_ENABLE_LIBC_WASI != 0 - /* - * learned from all implementations of `os_get_invalid_handle()` - * that invalid handles across all platforms are represented by -1. - */ - module->wasi_args.stdio[0] = -1; - module->wasi_args.stdio[1] = -1; - module->wasi_args.stdio[2] = -1; + 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(); #endif return module; diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 3cce5543c..c096270bd 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -6369,13 +6369,9 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) #endif #if WASM_ENABLE_LIBC_WASI != 0 - /* - * learned from all implementations of `os_get_invalid_handle()` - * that invalid handles across all platforms are represented by -1. - */ - module->wasi_args.stdio[0] = -1; - module->wasi_args.stdio[1] = -1; - module->wasi_args.stdio[2] = -1; + 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(); #endif (void)ret; diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index d20c28d7d..df765065f 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -3122,6 +3122,12 @@ create_module(char *name, char *error_buf, uint32 error_buf_size) } #endif +#if WASM_ENABLE_LIBC_WASI != 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(); +#endif + (void)ret; return module; } diff --git a/core/shared/platform/alios/alios_platform.c b/core/shared/platform/alios/alios_platform.c index b5663e3a2..a3752b439 100644 --- a/core/shared/platform/alios/alios_platform.c +++ b/core/shared/platform/alios/alios_platform.c @@ -79,3 +79,9 @@ os_dcache_flush() void os_icache_flush(void *start, size_t len) {} + +os_raw_file_handle +os_invalid_raw_handle(void) +{ + return -1; +} diff --git a/core/shared/platform/common/posix/posix_file.c b/core/shared/platform/common/posix/posix_file.c index 9ae0a03a2..d90f38ec5 100644 --- a/core/shared/platform/common/posix/posix_file.c +++ b/core/shared/platform/common/posix/posix_file.c @@ -1032,4 +1032,10 @@ char * os_realpath(const char *path, char *resolved_path) { return realpath(path, resolved_path); -} \ No newline at end of file +} + +os_raw_file_handle +os_invalid_raw_handle(void) +{ + return -1; +} diff --git a/core/shared/platform/esp-idf/espidf_file.c b/core/shared/platform/esp-idf/espidf_file.c index be50a2900..4d78df38a 100644 --- a/core/shared/platform/esp-idf/espidf_file.c +++ b/core/shared/platform/esp-idf/espidf_file.c @@ -1032,4 +1032,10 @@ char * os_realpath(const char *path, char *resolved_path) { return realpath(path, resolved_path); -} \ No newline at end of file +} + +os_raw_file_handle +os_invalid_raw_handle(void) +{ + return -1; +} diff --git a/core/shared/platform/include/platform_api_extension.h b/core/shared/platform/include/platform_api_extension.h index 37b8399b8..3834fe772 100644 --- a/core/shared/platform/include/platform_api_extension.h +++ b/core/shared/platform/include/platform_api_extension.h @@ -1607,6 +1607,15 @@ os_is_dir_stream_valid(os_dir_stream *dir_stream); os_file_handle os_get_invalid_handle(void); +/** + * Returns an invalid raw file handle that is guaranteed to cause failure when + * called with any filesystem operation. + * + * @return the invalid raw file handle + */ +os_raw_file_handle +os_invalid_raw_handle(void); + /** * Checks whether the given file handle is valid. An invalid handle is * guaranteed to cause failure when called with any filesystem operation. diff --git a/core/shared/platform/riot/riot_platform.c b/core/shared/platform/riot/riot_platform.c index 9accc5eb8..b48033247 100644 --- a/core/shared/platform/riot/riot_platform.c +++ b/core/shared/platform/riot/riot_platform.c @@ -95,3 +95,9 @@ os_dcache_flush(void) void os_icache_flush(void *start, size_t len) {} + +os_raw_file_handle +os_invalid_raw_handle(void) +{ + return -1; +} diff --git a/core/shared/platform/rt-thread/rtt_file.c b/core/shared/platform/rt-thread/rtt_file.c index b9fd1f9fa..f858f7eae 100644 --- a/core/shared/platform/rt-thread/rtt_file.c +++ b/core/shared/platform/rt-thread/rtt_file.c @@ -192,3 +192,9 @@ posix_fallocate(int __fd, off_t __offset, off_t __length) errno = ENOSYS; return -1; } + +os_raw_file_handle +os_invalid_raw_handle(void) +{ + return -1; +} diff --git a/core/shared/platform/windows/win_file.c b/core/shared/platform/windows/win_file.c index 770c5c741..55ea77ac7 100644 --- a/core/shared/platform/windows/win_file.c +++ b/core/shared/platform/windows/win_file.c @@ -1810,3 +1810,9 @@ os_realpath(const char *path, char *resolved_path) return resolved_path; } + +os_raw_file_handle +os_invalid_raw_handle(void) +{ + return INVALID_HANDLE_VALUE; +} diff --git a/core/shared/platform/zephyr/zephyr_platform.c b/core/shared/platform/zephyr/zephyr_platform.c index b383def67..3280e542f 100644 --- a/core/shared/platform/zephyr/zephyr_platform.c +++ b/core/shared/platform/zephyr/zephyr_platform.c @@ -255,3 +255,9 @@ set_exec_mem_alloc_func(exec_mem_alloc_func_t alloc_func, exec_mem_alloc_func = alloc_func; exec_mem_free_func = free_func; } + +os_raw_file_handle +os_invalid_raw_handle(void) +{ + return -1; +}