diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-01-28 17:50:10 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-07-02 09:54:19 +0200 |
| commit | f9f928b146fca041fc4dcb410d3a4621f5b0863e (patch) | |
| tree | 9b6275f860a7badf997a8ed04ec563d7d5a0bd9f | |
| parent | fb7e9b1efdad28502e8afae3352d60256368d4dc (diff) | |
| download | mullvadvpn-f9f928b146fca041fc4dcb410d3a4621f5b0863e.tar.xz mullvadvpn-f9f928b146fca041fc4dcb410d3a4621f5b0863e.zip | |
Replace GetOverlappedResultEx (which is not supported on Windows 7)
| -rw-r--r-- | talpid-core/src/split_tunnel/windows/driver.rs | 34 | ||||
| -rw-r--r-- | talpid-core/src/split_tunnel/windows/mod.rs | 9 |
2 files changed, 23 insertions, 20 deletions
diff --git a/talpid-core/src/split_tunnel/windows/driver.rs b/talpid-core/src/split_tunnel/windows/driver.rs index 47c576cf72..89b2e70429 100644 --- a/talpid-core/src/split_tunnel/windows/driver.rs +++ b/talpid-core/src/split_tunnel/windows/driver.rs @@ -27,11 +27,11 @@ use winapi::{ }, um::{ handleapi::CloseHandle, - ioapiset::{DeviceIoControl, GetOverlappedResultEx}, + ioapiset::{DeviceIoControl, GetOverlappedResult}, minwinbase::OVERLAPPED, - synchapi::CreateEventW, + synchapi::{CreateEventW, WaitForSingleObject}, tlhelp32::TH32CS_SNAPPROCESS, - winbase::{FILE_FLAG_OVERLAPPED, INFINITE}, + winbase::{FILE_FLAG_OVERLAPPED, INFINITE, WAIT_ABANDONED, WAIT_FAILED, WAIT_OBJECT_0}, winioctl::{FILE_ANY_ACCESS, METHOD_BUFFERED, METHOD_NEITHER}, }, }; @@ -679,6 +679,8 @@ pub fn device_io_control_buffer( 0 }; + let event = overlapped.hEvent; + let mut returned_bytes = 0u32; let overlapped = overlapped as *const _ as *mut _; @@ -707,17 +709,19 @@ pub fn device_io_control_buffer( return Err(last_error); } - let result = unsafe { - GetOverlappedResultEx( - device as *mut _, - overlapped, - &mut returned_bytes, - timeout - .map(|timeout| timeout.as_millis() as u32) - .unwrap_or(INFINITE), - FALSE, - ) - }; + let timeout = timeout + .map(|timeout| timeout.as_millis() as u32) + .unwrap_or(INFINITE); + let result = unsafe { WaitForSingleObject(event, timeout) }; + match result { + WAIT_FAILED => return Err(io::Error::last_os_error()), + WAIT_ABANDONED => return Err(io::Error::new(io::ErrorKind::Other, "abandoned mutex")), + WAIT_OBJECT_0 => (), + error => return Err(io::Error::from_raw_os_error(error as i32)), + } + + let result = + unsafe { GetOverlappedResult(device as *mut _, overlapped, &mut returned_bytes, FALSE) }; if result == 0 { return Err(io::Error::last_os_error()); @@ -732,7 +736,7 @@ pub fn device_io_control_buffer( /// Send an IOCTL code to the given device handle. /// `input` specifies an optional buffer to send. -/// The result must be obtained using `GetOverlappedResultEx`. +/// The result must be obtained using `GetOverlappedResult[Ex]`. pub unsafe fn device_io_control_buffer_async( device: RawHandle, ioctl_code: u32, diff --git a/talpid-core/src/split_tunnel/windows/mod.rs b/talpid-core/src/split_tunnel/windows/mod.rs index c7220ce0ba..a5ad4d5923 100644 --- a/talpid-core/src/split_tunnel/windows/mod.rs +++ b/talpid-core/src/split_tunnel/windows/mod.rs @@ -13,7 +13,7 @@ use winapi::{ shared::minwindef::{FALSE, TRUE}, um::{ handleapi::CloseHandle, - ioapiset::GetOverlappedResultEx, + ioapiset::GetOverlappedResult, minwinbase::OVERLAPPED, synchapi::{CreateEventW, SetEvent, WaitForMultipleObjects, WaitForSingleObject}, winbase::{INFINITE, WAIT_ABANDONED_0, WAIT_OBJECT_0}, @@ -143,12 +143,11 @@ impl SplitTunnel { } let result = unsafe { - GetOverlappedResultEx( + GetOverlappedResult( event_context.handle, &event_context.event_overlapped as *const _ as *mut _, &mut returned_bytes, - INFINITE, - FALSE, + TRUE, ) }; @@ -156,7 +155,7 @@ impl SplitTunnel { let error = io::Error::last_os_error(); log::error!( "{}", - error.display_chain_with_msg("GetOverlappedResultEx failed") + error.display_chain_with_msg("GetOverlappedResult failed") ); continue; |
