Overlapped object not detecting requrests with failed statut

I am sending a DeviceIoControl request from an user application with overlapped object.

DeviceIoControl(hScsiDriver, IOCTL_SCSI_MINIPORT, ScsiRequestBuffer, InputLength, ScsiReplyBuffer, OutputLength, &ReturnLength, pOverlappedObject);

Later I am checking status of the Ioctl using GetOverlappedResult.

status = GetOverlappedResult(pVMstruct->hScsiDriver[pVMstruct->activatedDrive],
pOverlappedObject , &returnLength, TRUE);

The request is completed by a storport miniport driver. The problem is if I set srbStatus in SRB as SRB_STATUS_SUCCESS or SRB_STATUS_BUSY, everything works fine. But if I set the status as anything else(like SRB_STATUS_ERROR), GetOverlappedResult never returns. This causes my application to hang. Where am I going wrong ?

In this case, what does the DeviceIoControl call return? Are you checking the return value?

Bent from my phone


From: 30231624400n behalf of
Sent: Thursday, September 13, 2018 10:23 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Overlapped object not detecting requrests with failed statut

I am sending a DeviceIoControl request from an user application with overlapped object.

DeviceIoControl(hScsiDriver, IOCTL_SCSI_MINIPORT, ScsiRequestBuffer, InputLength, ScsiReplyBuffer, OutputLength, &ReturnLength, pOverlappedObject);

Later I am checking status of the Ioctl using GetOverlappedResult.

status = GetOverlappedResult(pVMstruct->hScsiDriver[pVMstruct->activatedDrive],
pOverlappedObject , &returnLength, TRUE);

The request is completed by a storport miniport driver. The problem is if I set srbStatus in SRB as SRB_STATUS_SUCCESS or SRB_STATUS_BUSY, everything works fine. But if I set the status as anything else(like SRB_STATUS_ERROR), GetOverlappedResult never returns. This causes my application to hang. Where am I going wrong ?


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

xxxxx@gmail.com wrote:

I am sending a DeviceIoControl request from an user application with overlapped object.

DeviceIoControl(hScsiDriver, IOCTL_SCSI_MINIPORT, ScsiRequestBuffer, InputLength, ScsiReplyBuffer, OutputLength, &ReturnLength, pOverlappedObject);

Later I am checking status of the Ioctl using GetOverlappedResult.

status = GetOverlappedResult(pVMstruct->hScsiDriver[pVMstruct->activatedDrive],
pOverlappedObject , &returnLength, TRUE);

The request is completed by a storport miniport driver. The problem is if I set srbStatus in SRB as SRB_STATUS_SUCCESS or SRB_STATUS_BUSY, everything works fine. But if I set the status as anything else(like SRB_STATUS_ERROR), GetOverlappedResult never returns. This causes my application to hang. Where am I going wrong ?

There is a subtlety to overlapped I/O that many programmers miss. If the
driver completes the request with a non-success status during the first
contact, then DeviceIoControl will return an error immediately.  In that
case, you do NOT call GetOverlappedResult.

There are three possible result paths for overlapped I/O:

    result = DeviceIoControl( );
    if result is non-zero
        request is complete, no further checking needed
    else if GetLastError is not ERROR_IO_PENDING
        request failed already, no further checking needed
    else
       GetOverlappedResult

Many people skip that second outcome.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Also remember SetFileCompletionNotificationModes. This only applies to overlapped IO with handles associated with IO completion ports, but except for IO during some initialization phase, that should be all of your overlapped IO.

New development should probably use the thread pool APIs (IIRC available since Vista?) but there are many applications that use the raw ICOP APIs and manage the threads directly.

Sent from Mailhttps: for Windows 10

________________________________
From: xxxxx@lists.osr.com on behalf of xxxxx@probo.com
Sent: Friday, September 14, 2018 12:55:46 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Overlapped object not detecting requrests with failed statut

xxxxx@gmail.com wrote:
> I am sending a DeviceIoControl request from an user application with overlapped object.
>
> DeviceIoControl(hScsiDriver, IOCTL_SCSI_MINIPORT, ScsiRequestBuffer, InputLength, ScsiReplyBuffer, OutputLength, &ReturnLength, pOverlappedObject);
>
> Later I am checking status of the Ioctl using GetOverlappedResult.
>
> status = GetOverlappedResult(pVMstruct->hScsiDriver[pVMstruct->activatedDrive],
> pOverlappedObject , &returnLength, TRUE);
>
> The request is completed by a storport miniport driver. The problem is if I set srbStatus in SRB as SRB_STATUS_SUCCESS or SRB_STATUS_BUSY, everything works fine. But if I set the status as anything else(like SRB_STATUS_ERROR), GetOverlappedResult never returns. This causes my application to hang. Where am I going wrong ?

There is a subtlety to overlapped I/O that many programmers miss. If the
driver completes the request with a non-success status during the first
contact, then DeviceIoControl will return an error immediately. In that
case, you do NOT call GetOverlappedResult.

There are three possible result paths for overlapped I/O:

result = DeviceIoControl( );
if result is non-zero
request is complete, no further checking needed
else if GetLastError is not ERROR_IO_PENDING
request failed already, no further checking needed
else
GetOverlappedResult

Many people skip that second outcome.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></https:>