Re: IRP_MJ_READ Problem

Tech-Archive recommends: Speed Up your PC by fixing your registry



If you have any IRP queue, which can be handled asynchronously, you MUST
call IoMarkIrpPending BEFORE the IRP is queued. After the IRP is queued, you
should NOT touch it.
If design of your Insert function doesn't actually queue the IRP if it
returns STATUS_SUCCESS, then it should not call IoMarkIrpPending for it. You
should not blindly assign Insert return code to Status, becaus the IRP may
not exist at that point (may be asynchronously completed).
By the way, you return STATUS_SUCCESS even if your IRP is unsuccessful, this
is what causes DV bugcheck. And NT_SUCCESS(STATUS_PENDING) is TRUE.
You should change your code to the following:

NTSTATUS OnDeviceRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
NTSTATUS status;
if(0 == m_lConnected)
{
status=STATUS_DEVICE_NOT_CONNECTED;
}
else
{
NTSTATUS status =m_pIrpQ->Insert(Irp);
if (STAUS_PENDING == status)
{
// IoMarkIrpPending should be done in Insert()
return status;
}
}
Irp->IoStatus.Status=status;

IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}


"Nadav" <Nadav@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F47A77BD-4C5B-49B6-A3B3-5D14D7D2BE4F@xxxxxxxxxxxxxxxx
> Hi,
>
> I have an upper-layer function driver, I am using DriverVerifier with this
> driver.
> DriverVerifier indicate a 224 BugCheck on my IRP_MJ_READ handler, BugCheck
> 224 reads: " (Fatal error) An IRP dispatch handler has returned a status
> that
> is inconsistent with the IRP's IoStatus.Status field. (Dispatch handler
> routine, IRP, IRP's IoStatus.Status, and returned Status specified.) ".
>
> Following is a code snippet of the IRP_MJ_READ handler, what is wrong with
> it? What am I missing here?
>
> NTSTATUS OnDeviceRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
> {
> if(0 == m_lConnected)
> Irp->IoStatus.Status=STATUS_DEVICE_NOT_CONNECTED;
> else
> Irp->IoStatus.Status=m_pIrpQ->Insert(Irp);//always return SUCCESS
> if(FALSE == NT_SUCCESS(Irp->IoStatus.Status))
> {
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return STATUS_SUCCESS;
> }
> IoMarkIrpPending(Irp);
> return STATUS_PENDING;
> }
>
> Nadav
> http://www.sophin.com


.



Relevant Pages

  • Re: IoMarkIrpPending issue
    ... complete the logical Irp with error status. ... is there a way to 'undo' IoMarkIrpPending? ... Driver receives a 'logical' I/O request. ...
    (microsoft.public.development.device.drivers)
  • Re: IoMarkIrpPending issue
    ... Always call IoMarkIrpPending before the IRP gets to the context it can be ... Driver receives a 'logical' I/O request. ...
    (microsoft.public.development.device.drivers)
  • Re: Propagating the Pending Bit
    ... Here is the quotation from IoMarkIrpPending documentation in WDK ... If a driver sets an IoCompletion routine for an IRP and then passes the ...
    (microsoft.public.development.device.drivers)
  • IRP_MJ_READ Problem
    ... I have an upper-layer function driver, I am using DriverVerifier with this ... DriverVerifier indicate a 224 BugCheck on my IRP_MJ_READ handler, ... routine, IRP, IRP's IoStatus.Status, and returned Status specified.) ...
    (microsoft.public.development.device.drivers)
  • Re: How to set up IoRequestPacket in ClientEventReceiveDatagram?
    ... Yes, I have already done all of these steps, but it still cuases blue ... I think that the reason is probably *IoRequestPacket not built correctly, ... When your handler is called ... > *IoRequestPacket to the address of your irp. ...
    (microsoft.public.development.device.drivers)