Skip to content
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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lum1n0us
Copy link
Collaborator

fix #4081

@lxbxl
Copy link

lxbxl commented Feb 18, 2025

我开始也是用 os_get_invalid_handle 函数,后面发现它返回的是 os_file_handle 类型,而 stdio 是 os_raw_file_handle 类型。

所以我改成下面这样的。

#if WASM_ENABLE_LIBC_WASI != 0 && defined(BH_PLATFORM_WINDOWS)
module->wasi_args.stdio[0] = INVALID_HANDLE_VALUE;
module->wasi_args.stdio[1] = INVALID_HANDLE_VALUE;
module->wasi_args.stdio[2] = INVALID_HANDLE_VALUE;
#endif

@lum1n0us lum1n0us force-pushed the fix/invalid_wasi_fds branch from c8053b1 to 32e10b9 Compare February 18, 2025 05:53
@lum1n0us lum1n0us force-pushed the fix/invalid_wasi_fds branch from 32e10b9 to cf8b932 Compare February 18, 2025 07:38
Copy link
Collaborator

@TianlongLiang TianlongLiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

*/
module->wasi_args.stdio[0] = -1;
module->wasi_args.stdio[1] = -1;
module->wasi_args.stdio[2] = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In windows platform, the os_raw_file_handle type is defined as HANDLE type, and the invalid value is INVALID_HANDLE_VALUE, refer to:

typedef HANDLE os_raw_file_handle;

HANDLE raw_dir_handle = INVALID_HANDLE_VALUE;

So here it seems we had better add macro to control the code? Some what like:

#ifndef BH_PLATFORM_WINDOWS
    module->wasi_args.stdio[0] = -1;
    module->wasi_args.stdio[1] = -1;
    module->wasi_args.stdio[2] = -1;
#else
    module->wasi_args.stdio[0] = INVALID_HANDLE_VALUE;
    module->wasi_args.stdio[1] = INVALID_HANDLE_VALUE;
    module->wasi_args.stdio[2] = INVALID_HANDLE_VALUE;
#endif

@lum1n0us lum1n0us force-pushed the fix/invalid_wasi_fds branch from f93f222 to e82bd0b Compare February 24, 2025 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wasm_runtime_load 未初始化 WASIArguments 的 stdio 内容
4 participants