Skip to content

Commit

Permalink
fix(driver,iocp): check NTSTATUS correctly (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft authored Dec 9, 2024
1 parent a351f8b commit 24b971a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions compio-driver/src/iocp/cp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compio-driver/src/iocp/wait/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 24b971a

Please sign in to comment.