Skip to content

Commit

Permalink
fix(driver): use InternalHigh as op result
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Feb 19, 2024
1 parent 3e04836 commit 709b86b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
12 changes: 10 additions & 2 deletions compio-driver/src/iocp/cp/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl GlobalPort {
) -> io::Result<()> {
self.port.post(res, optr)
}

pub fn post_raw<T: ?Sized>(&self, optr: *const Overlapped<T>) -> io::Result<()> {
self.port.post_raw(optr)
}
}

impl AsRawHandle for GlobalPort {
Expand All @@ -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 _,
Expand All @@ -75,7 +79,7 @@ fn iocp_start() -> io::Result<()> {
entry.lpCompletionKey,
entry.lpOverlapped,
overlapped.driver,
e
_e
);
}
}
Expand Down Expand Up @@ -138,4 +142,8 @@ impl PortHandle {
) -> io::Result<()> {
self.port.post(res, optr)
}

pub fn post_raw<T: ?Sized>(&self, optr: *const Overlapped<T>) -> io::Result<()> {
self.port.post_raw(optr)
}
}
37 changes: 19 additions & 18 deletions compio-driver/src/iocp/cp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,25 @@ impl CompletionPort {
res: io::Result<usize>,
optr: *mut Overlapped<T>,
) -> 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<T: ?Sized>(&self, optr: *const Overlapped<T>) -> 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(())
}
Expand Down Expand Up @@ -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 _,
Expand All @@ -158,7 +163,7 @@ impl CompletionPort {
entry.lpCompletionKey,
entry.lpOverlapped,
overlapped.driver,
e
_e
);
}
}
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions compio-driver/src/iocp/cp/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ impl PortHandle {
) -> io::Result<()> {
self.port.post(res, optr)
}

pub fn post_raw<T: ?Sized>(&self, optr: *const Overlapped<T>) -> io::Result<()> {
self.port.post_raw(optr)
}
}
5 changes: 1 addition & 4 deletions compio-driver/src/iocp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 709b86b

Please sign in to comment.