From 24b971a765fb31cc10b9e331f970684275f49a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Tue, 10 Dec 2024 04:23:00 +0900 Subject: [PATCH] fix(driver,iocp): check NTSTATUS correctly (#367) --- compio-driver/src/iocp/cp/mod.rs | 13 +++++++------ compio-driver/src/iocp/wait/packet.rs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/compio-driver/src/iocp/cp/mod.rs b/compio-driver/src/iocp/cp/mod.rs index a7f442eb..25228104 100644 --- a/compio-driver/src/iocp/cp/mod.rs +++ b/compio-driver/src/iocp/cp/mod.rs @@ -24,7 +24,7 @@ use windows_sys::Win32::{ Foundation::{ ERROR_BAD_COMMAND, ERROR_BROKEN_PIPE, ERROR_HANDLE_EOF, ERROR_IO_INCOMPLETE, ERROR_NO_DATA, ERROR_PIPE_CONNECTED, ERROR_PIPE_NOT_CONNECTED, FACILITY_NTWIN32, INVALID_HANDLE_VALUE, - NTSTATUS, RtlNtStatusToDosError, STATUS_PENDING, STATUS_SUCCESS, + NTSTATUS, RtlNtStatusToDosError, STATUS_SUCCESS, }, Storage::FileSystem::SetFileCompletionNotificationModes, System::{ @@ -167,13 +167,14 @@ impl CompletionPort { return None; } } - let res = if matches!( - overlapped.base.Internal as NTSTATUS, - STATUS_SUCCESS | STATUS_PENDING - ) { + // TODO: *mut OVERLAPPED is *mut IO_STATUS_BLOCK internally, but + // OVERLAPPED::Internal is not the same size as + // IO_STATUS_BLOCK::Status. + let status = overlapped.base.Internal as NTSTATUS; + let res = if status >= 0 { Ok(overlapped.base.InternalHigh) } else { - let error = unsafe { RtlNtStatusToDosError(overlapped.base.Internal as _) }; + let error = unsafe { RtlNtStatusToDosError(status) }; match error { ERROR_IO_INCOMPLETE | ERROR_HANDLE_EOF diff --git a/compio-driver/src/iocp/wait/packet.rs b/compio-driver/src/iocp/wait/packet.rs index d890e4d3..b967dd33 100644 --- a/compio-driver/src/iocp/wait/packet.rs +++ b/compio-driver/src/iocp/wait/packet.rs @@ -42,7 +42,7 @@ pub struct Wait { } fn check_status(status: NTSTATUS) -> io::Result<()> { - if status == STATUS_SUCCESS { + if status >= 0 { Ok(()) } else { Err(io::Error::from_raw_os_error(unsafe {