Implement __wasi_fd_fdstat_get for Windows.

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.
This commit is contained in:
Peter Huene
2019-11-12 16:41:54 -08:00
committed by Jakub Konka
parent 3e7bc745a2
commit 0cf54ffeba
11 changed files with 245 additions and 172 deletions

View File

@@ -35,7 +35,8 @@ unsafe fn test_path_filestat(dir_fd: wasi_unstable::Fd) {
| wasi_unstable::RIGHT_FD_WRITE
| wasi_unstable::RIGHT_PATH_FILESTAT_GET,
0,
0,
// Pass some flags for later retrieval
wasi_unstable::FDFLAG_APPEND | wasi_unstable::FDFLAG_SYNC,
&mut file_fd,
);
assert_eq!(
@@ -62,6 +63,11 @@ unsafe fn test_path_filestat(dir_fd: wasi_unstable::Fd) {
0,
"files shouldn't have rights for path_* syscalls even if manually given",
);
assert_ne!(
fdstat.fs_flags & (wasi_unstable::FDFLAG_APPEND | wasi_unstable::FDFLAG_SYNC),
0,
"file should have the same flags used to create the file"
);
// Check file size
let mut stat = wasi_unstable::FileStat {