Implement __wasi_fd_fdstat_get for Windows.#557
Implement __wasi_fd_fdstat_get for Windows.#557kubkon merged 1 commit intobytecodealliance:masterfrom
__wasi_fd_fdstat_get for Windows.#557Conversation
|
Primarily the Apparently |
|
I'm also working on The idea will be to utilize these changes along with ReOpenFile to reopen the file from the existing descriptor, but with the new access / flags while preserving the current file pointer. |
kubkon
left a comment
There was a problem hiding this comment.
LGTM! Amazing work, thanks so much! :-)
Go Windows... |
|
Oh, and while we're here, if you could rebase to the latest |
|
Will do! |
8d38e2e to
3bc87c5
Compare
|
I'm expecting CI to fail on Windows until there's clarification on how we expect the |
b39a182 to
62c08b9
Compare
62c08b9 to
d2be013
Compare
|
This is ready for a review as it should now pass CI.
|
d2be013 to
0a98681
Compare
This commit fully implements `__wasi_fd_fdstat_get` on Windows so that the descriptor flags can be determined. It does this by calling into `NtQueryInformationFile` (safe to call from user mode) to get the open mode and access of the underlying OS handle. `NtQueryInformationFile` isn't included in the `winapi` crate, so it is manually being linked against. This commit also fixes several bugs on Windows: * Ignore `__WASI_FDFLAG_NONBLOCK` by not setting `FILE_FLAG_OVERLAPPED` on file handles (the POSIX behavior for `O_NONBLOCK` on files). * Use `FILE_FLAG_WRITE_THROUGH` for the `__WASI_FDFLAG_?SYNC` flags. * `__WASI_FDFLAG_APPEND` should disallow `FILE_WRITE_DATA` access to force append-only on write operations. * Use `GENERIC_READ` and `GENERIC_WRITE` access flags. The latter is required when opening a file for truncation.
0a98681 to
45f71e5
Compare
kubkon
left a comment
There was a problem hiding this comment.
LGTM! I'm gonna go ahead and merge this in so that we can progress with other work, leaving the problem of truncation rights for a subsequent PR. Please feel free to file an issue if you find anything amiss though!
|
I think it was a very good decision to just leave |
This PR fully implements
__wasi_fd_fdstat_geton Windows so thatthe descriptor flags can be determined.
It does this by calling into
NtQueryInformationFile(safe to call fromuser mode) to get the open mode and access of the underlying OS handle.
NtQueryInformationFileisn't included in thewinapicrate, so it ismanually being linked against.
This PR also fixes several bugs on Windows:
__WASI_FDFLAG_NONBLOCKby not settingFILE_FLAG_OVERLAPPEDon file handles (the POSIX behavior for
O_NONBLOCKon files).FILE_FLAG_WRITE_THROUGHfor the__WASI_FDFLAG_?SYNCflags.__WASI_FDFLAG_APPENDshould disallowFILE_WRITE_DATAaccess toforce append-only on write operations.
GENERIC_READandGENERIC_WRITEaccess flags. Thelatter is required when opening a file for truncation.