Implement fd_fdstat_set_flags for Windows.

This commit implements `fd_fdstat_set_flags` for Windows.

Additionally, it fixes a problem where `O_APPEND` was not working correctly
because `GENERIC_WRITE` was always being set; as a result, `FILE_WRITE_DATA`
could not be removed from the permission set to properly enable append-only
mode.

It also treats `O_TRUNC` with `O_APPEND` as an invalid argument error.  This is
because Windows cannot support these two flags together. To support `O_TRUNC`,
the `GENERIC_WRITE` bit must be set for the file access flags.  Setting this
bit will cause `FILE_WRITE_DATA` to be set, which will not properly treat the
file as append-only (it requires `FILE_APPEND_DATA` without `FILE_WRITE_DATA`).
This commit is contained in:
Peter Huene
2019-12-10 14:38:38 -08:00
committed by Dan Gohman
parent 4197cc562e
commit 8fdd776f81
6 changed files with 245 additions and 16 deletions

View File

@@ -298,19 +298,24 @@ pub(crate) unsafe fn fd_fdstat_get(
}
pub(crate) unsafe fn fd_fdstat_set_flags(
wasi_ctx: &WasiCtx,
wasi_ctx: &mut WasiCtx,
_memory: &mut [u8],
fd: wasi::__wasi_fd_t,
fdflags: wasi::__wasi_fdflags_t,
) -> Result<()> {
trace!("fd_fdstat_set_flags(fd={:?}, fdflags={:#x?})", fd, fdflags);
let fd = wasi_ctx
.get_fd_entry(fd)?
.as_descriptor(wasi::__WASI_RIGHTS_FD_FDSTAT_SET_FLAGS, 0)?
.as_os_handle();
let descriptor = wasi_ctx
.get_fd_entry_mut(fd)?
.as_descriptor_mut(wasi::__WASI_RIGHTS_FD_FDSTAT_SET_FLAGS, 0)?;
hostcalls_impl::fd_fdstat_set_flags(&fd, fdflags)
if let Some(new_handle) =
hostcalls_impl::fd_fdstat_set_flags(&descriptor.as_os_handle(), fdflags)?
{
*descriptor = Descriptor::OsHandle(new_handle);
}
Ok(())
}
pub(crate) unsafe fn fd_fdstat_set_rights(