wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

move stdio fd handle checking in fd_determine_type_rights to ensure type is properly set before return

Open SneezingCactus opened this issue 6 months ago • 4 comments

Before this change, fd_determine_type_rights would return early upon dealing with a stdio file handle without giving it any type (therefore being left as a __WASI_FILETYPE_UNKNOWN). This would end up having repercussions on wasi-sdk's implementation of vfprintf, which doesn't register line breaks properly if the file it's writing to (stdout in the case of printf) isn't a tty, which is mainly checked by seeing if the file is a CHARACTER_DEVICE.

SneezingCactus avatar Jun 20 '25 04:06 SneezingCactus

This would end up having repercussions on wasi-sdk's implementation of vfprintf, which doesn't register line breaks properly if the file it's writing to (stdout in the case of printf) isn't a tty, which is mainly checked by seeing if the file is a CHARACTER_DEVICE.

Would you mind pointing out the source code in wasi-libc related to that?

fd_determine_type_rights would return early upon dealing with a stdio file handle without giving it any type

IIUC, *type = buf.st_filetype; is the key to ⬆️ problem. So how about moving L527~L540 to L469 and return directly.

lum1n0us avatar Jun 24 '25 04:06 lum1n0us

This would end up having repercussions on wasi-sdk's implementation of vfprintf, which doesn't register line breaks properly if the file it's writing to (stdout in the case of printf) isn't a tty, which is mainly checked by seeing if the file is a CHARACTER_DEVICE.

Would you mind pointing out the source code in wasi-libc related to that?

https://github.com/WebAssembly/wasi-libc/blob/1377a93acea031acd9b6e77a830360d88477319c/libc-bottom-half/sources/isatty.c

fd_determine_type_rights would return early upon dealing with a stdio file handle without giving it any type

IIUC, *type = buf.st_filetype; is the key to ⬆️ problem. So how about moving L527~L540 to L469 and return directly.

i feel it's better to revert https://github.com/bytecodealliance/wasm-micro-runtime/pull/3694 and investigate the original issue because it was based on a broken experiment: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3686#issuecomment-2998903186

yamt avatar Jun 24 '25 05:06 yamt

I feel this PR is primarily about ensuring *type is assigned as an output parameter, which the original code missed. We might want to reopen the discussion on 3686.

lum1n0us avatar Jun 26 '25 02:06 lum1n0us

restarting SGX 143 https://github.com/bytecodealliance/wasm-micro-runtime/actions/runs/15771043456/job/44455986874?pr=4395

yamt avatar Jul 02 '25 03:07 yamt