Skip to content

initialize WASI stdio handles to invalid for better error handling #4092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4120,6 +4120,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

return module;
#if WASM_ENABLE_GC != 0
fail2:
Expand Down
6 changes: 6 additions & 0 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -6368,6 +6368,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;

Expand Down
6 changes: 6 additions & 0 deletions core/iwasm/interpreter/wasm_mini_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions core/shared/platform/alios/alios_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 7 additions & 1 deletion core/shared/platform/common/posix/posix_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,4 +1032,10 @@ char *
os_realpath(const char *path, char *resolved_path)
{
return realpath(path, resolved_path);
}
}

os_raw_file_handle
os_invalid_raw_handle(void)
{
return -1;
}
8 changes: 7 additions & 1 deletion core/shared/platform/esp-idf/espidf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,4 +1032,10 @@ char *
os_realpath(const char *path, char *resolved_path)
{
return realpath(path, resolved_path);
}
}

os_raw_file_handle
os_invalid_raw_handle(void)
{
return -1;
}
9 changes: 9 additions & 0 deletions core/shared/platform/include/platform_api_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions core/shared/platform/riot/riot_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions core/shared/platform/rt-thread/rtt_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions core/shared/platform/windows/win_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions core/shared/platform/zephyr/zephyr_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading