diff options
| author | Chris Denton <christophersdenton@gmail.com> | 2022-07-06 16:38:35 +0100 |
|---|---|---|
| committer | Chris Denton <christophersdenton@gmail.com> | 2022-07-06 17:06:33 +0100 |
| commit | 3ae47e76a84baaa4d35f641c237649944fa8fb58 (patch) | |
| tree | 2545be0feb0db5f73d17d9a153bd33865b00574c /library/std/src/sys/windows | |
| parent | ae60dbdcac2c4c94293980cdb6872228fc4d8aa9 (diff) | |
| download | rust-3ae47e76a84baaa4d35f641c237649944fa8fb58.tar.gz rust-3ae47e76a84baaa4d35f641c237649944fa8fb58.zip | |
Windows: Fallback for overlapped I/O
Try waiting on the file handle once. If that fails then give up.
Diffstat (limited to 'library/std/src/sys/windows')
| -rw-r--r-- | library/std/src/sys/windows/c.rs | 14 | ||||
| -rw-r--r-- | library/std/src/sys/windows/handle.rs | 13 |
2 files changed, 26 insertions, 1 deletions
diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 5469487df1e..c7a42ef9a93 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -326,7 +326,9 @@ union IO_STATUS_BLOCK_union { } impl Default for IO_STATUS_BLOCK_union { fn default() -> Self { - Self { Pointer: ptr::null_mut() } + let mut this = Self { Pointer: ptr::null_mut() }; + this.Status = STATUS_PENDING; + this } } #[repr(C)] @@ -335,6 +337,16 @@ pub struct IO_STATUS_BLOCK { u: IO_STATUS_BLOCK_union, pub Information: usize, } +impl IO_STATUS_BLOCK { + pub fn status(&self) -> NTSTATUS { + // SAFETY: If `self.u.Status` was set then this is obviously safe. + // If `self.u.Pointer` was set then this is the equivalent to converting + // the pointer to an integer, which is also safe. + // Currently the only safe way to construct `IO_STATUS_BLOCK` outside of + // this module is to call the `default` method, which sets the `Status`. + unsafe { self.u.Status } + } +} pub type LPOVERLAPPED_COMPLETION_ROUTINE = unsafe extern "system" fn( dwErrorCode: DWORD, diff --git a/library/std/src/sys/windows/handle.rs b/library/std/src/sys/windows/handle.rs index cea04549d3d..6dd022b0806 100644 --- a/library/std/src/sys/windows/handle.rs +++ b/library/std/src/sys/windows/handle.rs @@ -248,6 +248,13 @@ impl Handle { offset.map(|n| n as _).as_ref(), None, ); + + let status = if status == c::STATUS_PENDING { + c::WaitForSingleObject(self.as_raw_handle(), c::INFINITE); + io_status.status() + } else { + status + }; match status { // If the operation has not completed then abort the process. // Doing otherwise means that the buffer and stack may be written to @@ -291,6 +298,12 @@ impl Handle { None, ) }; + let status = if status == c::STATUS_PENDING { + unsafe { c::WaitForSingleObject(self.as_raw_handle(), c::INFINITE) }; + io_status.status() + } else { + status + }; match status { // If the operation has not completed then abort the process. // Doing otherwise means that the buffer may be read and the stack |
