From 709b86bdaa6d900f6e429eeee787b8d3cf8f2e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Fri, 16 Feb 2024 19:03:03 +0800 Subject: [PATCH] fix(driver): use InternalHigh as op result --- compio-driver/src/iocp/cp/global.rs | 12 ++++++++-- compio-driver/src/iocp/cp/mod.rs | 37 +++++++++++++++-------------- compio-driver/src/iocp/cp/multi.rs | 4 ++++ compio-driver/src/iocp/mod.rs | 5 +--- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/compio-driver/src/iocp/cp/global.rs b/compio-driver/src/iocp/cp/global.rs index cc76dbf0..fd093215 100644 --- a/compio-driver/src/iocp/cp/global.rs +++ b/compio-driver/src/iocp/cp/global.rs @@ -36,6 +36,10 @@ impl GlobalPort { ) -> io::Result<()> { self.port.post(res, optr) } + + pub fn post_raw(&self, optr: *const Overlapped) -> io::Result<()> { + self.port.post_raw(optr) + } } impl AsRawHandle for GlobalPort { @@ -60,7 +64,7 @@ fn iocp_start() -> io::Result<()> { // Any thin pointer is OK because we don't use the type of opcode. let overlapped_ptr: *mut Overlapped<()> = entry.lpOverlapped.cast(); let overlapped = unsafe { &*overlapped_ptr }; - if let Err(e) = syscall!( + if let Err(_e) = syscall!( BOOL, PostQueuedCompletionStatus( overlapped.driver as _, @@ -75,7 +79,7 @@ fn iocp_start() -> io::Result<()> { entry.lpCompletionKey, entry.lpOverlapped, overlapped.driver, - e + _e ); } } @@ -138,4 +142,8 @@ impl PortHandle { ) -> io::Result<()> { self.port.post(res, optr) } + + pub fn post_raw(&self, optr: *const Overlapped) -> io::Result<()> { + self.port.post_raw(optr) + } } diff --git a/compio-driver/src/iocp/cp/mod.rs b/compio-driver/src/iocp/cp/mod.rs index 814b35cb..f78972f0 100644 --- a/compio-driver/src/iocp/cp/mod.rs +++ b/compio-driver/src/iocp/cp/mod.rs @@ -82,20 +82,25 @@ impl CompletionPort { res: io::Result, optr: *mut Overlapped, ) -> io::Result<()> { - if let Err(e) = &res { - let code = e.raw_os_error().unwrap_or(ERROR_BAD_COMMAND as _); - unsafe { &mut *optr }.base.Internal = ntstatus_from_win32(code) as _; + if let Some(overlapped) = unsafe { optr.as_mut() } { + match &res { + Ok(transferred) => { + overlapped.base.Internal = STATUS_SUCCESS as _; + overlapped.base.InternalHigh = *transferred; + } + Err(e) => { + let code = e.raw_os_error().unwrap_or(ERROR_BAD_COMMAND as _); + overlapped.base.Internal = ntstatus_from_win32(code) as _; + } + } } - // We have to use CompletionKey to transfer the result because it is large - // enough. It is OK because we set it to zero when attaching handles to IOCP. + self.post_raw(optr) + } + + pub fn post_raw(&self, optr: *const Overlapped) -> io::Result<()> { syscall!( BOOL, - PostQueuedCompletionStatus( - self.port.as_raw_handle() as _, - 0, - res.unwrap_or_default(), - optr.cast() - ) + PostQueuedCompletionStatus(self.port.as_raw_handle() as _, 0, 0, optr.cast()) )?; Ok(()) } @@ -143,7 +148,7 @@ impl CompletionPort { if let Some(current_driver) = current_driver { if overlapped.driver != current_driver { // Repose the entry to correct port. - if let Err(e) = syscall!( + if let Err(_e) = syscall!( BOOL, PostQueuedCompletionStatus( overlapped.driver as _, @@ -158,7 +163,7 @@ impl CompletionPort { entry.lpCompletionKey, entry.lpOverlapped, overlapped.driver, - e + _e ); } } @@ -167,11 +172,7 @@ impl CompletionPort { overlapped.base.Internal as NTSTATUS, STATUS_SUCCESS | STATUS_PENDING ) { - if entry.lpCompletionKey != 0 { - Ok(entry.lpCompletionKey) - } else { - Ok(entry.dwNumberOfBytesTransferred as _) - } + Ok(overlapped.base.InternalHigh) } else { let error = unsafe { RtlNtStatusToDosError(overlapped.base.Internal as _) }; match error { diff --git a/compio-driver/src/iocp/cp/multi.rs b/compio-driver/src/iocp/cp/multi.rs index 07a820f8..5f99956c 100644 --- a/compio-driver/src/iocp/cp/multi.rs +++ b/compio-driver/src/iocp/cp/multi.rs @@ -55,4 +55,8 @@ impl PortHandle { ) -> io::Result<()> { self.port.post(res, optr) } + + pub fn post_raw(&self, optr: *const Overlapped) -> io::Result<()> { + self.port.post_raw(optr) + } } diff --git a/compio-driver/src/iocp/mod.rs b/compio-driver/src/iocp/mod.rs index ab3218a7..f1cb9cf1 100644 --- a/compio-driver/src/iocp/mod.rs +++ b/compio-driver/src/iocp/mod.rs @@ -281,10 +281,7 @@ impl NotifyHandle { /// Notify the inner driver. pub fn notify(&self) -> io::Result<()> { - self.port.post( - Ok(0), - self.overlapped.as_ref() as *const _ as *mut Overlapped<()> as _, - ) + self.port.post_raw(self.overlapped.as_ref()) } }