In IoComplete routine, sometimes it check Irp->PendingReturned
and call IoMarkIrpPending if the flag is set.

Is there any rule for this?

According to DDK document, it says....
=================================================================
Any driver that sets an IoCompletion routine in an IRP and then passes
the IRP down to a lower driver should check the IRP->PendingReturned
flag in the IoCompletion routine. If the flag is set, the IoCompletion
routine
must call IoMarkIrpPending with the IRP. Note, however, that a driver that
passes down the IRP and then waits on an event should not mark the IRP
pending.
=================================================================

However, bulk usb sample code in DDK.

In IoComplete routine of set device power up, FinishDevPoUpIrp, it checks
Irp->PendingReturned and call IoMarkIrpPending if flag is set.
In IoComplete routine of set device power down, FinishDevPoDnIrp, it doesn't
check this flag. Why???
Does it have something to do with IoCompete's return value?

Best Regards

Jackal Huang

Re: Check Irp->PendingReturned in IoComplete routine by Bill

Bill
Mon Jan 12 09:29:04 CST 2004

You really need to understand how IRP completion is handled by the driver
and I/O manager to understand what is happening here. I highly highly
recommend you get Walter Oney's 2nd edition and read up on this topic. You
will very likely be lost until you do.

That said, what is happening here is on power up, the completion routine
always returns STATUS_SUCCESS thus the IRP is never reclaimed from the
completion routine. So, the driver returns from the dispatch routine
whatever status was returned from the IoCallDriver call. This may be
STATUS_PENDING or it may be some other non-pending status. The pending flag
must be properly propagated up the IRP stack from the completion routine.
The only way that can be done is by checking the PendingReturned flag in the
IRP and calling IoMarkIrpPending if the IRP's flag was set.

For the power down case, the driver may reclaim the IRP from the completion
routine and return STATUS_MORE_PROCESSING_REQUIRED from the completion
routine. In that case the driver can only return the proper status from the
dispatch routine by always assuming the IRP will pend. So, the driver must
call IoMarkIrpPending from the dispatch routine, and return STATUS_PENDING
from the dispatch routine. Because of this, there is no need to check the
PendingReturned flag from the completion routine. The pending flag has
already been properly propagated due to the IoMarkIrpPending call in the
dispatch routine.

--
Bill McKenzie
Compuware Corporation
Watch your IRPs/IRBs/URBs/SRBs/NDIS pkts with our free WDMSniffer tool:
http://frontline.compuware.com/nashua/patches/utility.htm


"Jackal Huang" <huangjj@hotmail.com> wrote in message
news:#V7B7UO2DHA.2680@TK2MSFTNGP11.phx.gbl...
> In IoComplete routine, sometimes it check Irp->PendingReturned
> and call IoMarkIrpPending if the flag is set.
>
> Is there any rule for this?
>
> According to DDK document, it says....
> =================================================================
> Any driver that sets an IoCompletion routine in an IRP and then passes
> the IRP down to a lower driver should check the IRP->PendingReturned
> flag in the IoCompletion routine. If the flag is set, the IoCompletion
> routine
> must call IoMarkIrpPending with the IRP. Note, however, that a driver that
> passes down the IRP and then waits on an event should not mark the IRP
> pending.
> =================================================================
>
> However, bulk usb sample code in DDK.
>
> In IoComplete routine of set device power up, FinishDevPoUpIrp, it checks
> Irp->PendingReturned and call IoMarkIrpPending if flag is set.
> In IoComplete routine of set device power down, FinishDevPoDnIrp, it
doesn't
> check this flag. Why???
> Does it have something to do with IoCompete's return value?
>
> Best Regards
>
> Jackal Huang
>
>
>



Re: Check Irp->PendingReturned in IoComplete routine by Calvin

Calvin
Wed Jan 14 14:58:27 CST 2004

"Jackal Huang" <huangjj@hotmail.com> wrote in message
news:#V7B7UO2DHA.2680@TK2MSFTNGP11.phx.gbl...
> In IoComplete routine, sometimes it check Irp->PendingReturned
> and call IoMarkIrpPending if the flag is set.
>
> Is there any rule for this?
>

In short, always execute the code:

if (Irp->PendingReturned)
{
IoMarkIrpPending(Irp);
}
IF and ONLY IF your CompletionRoutine returns anything OTHER THAN
STATUS_MORE_PROCESSING_REQUIRED unless the following 2 conditions I can
think of,

1. No need to mark pending if the Irp has been marked pending when it was
being queued in the dispatch routine.
2. Never mark Irp pending in the completion routine of the IRP orginator
(the one who created the Irp) since there's no IRP stack at that point.

To add what Bill said, Walter's 2nd WDM book gives a very decent description
on Irp handling, so does the "IRP cheat sheet" published by MSFT. Still,
many of my speculations, suspicions are not solved until I reverse engineer
the IoCompleteRequest and IopSynchronousServiceTail.

--
Calvin Guan Software Engineer cguan@pleasenospam.ati.com
ATI Technologies Inc. Markham ON. Canada (905) 882-2600x8654




Re: Check Irp->PendingReturned in IoComplete routine by Jackal

Jackal
Wed Jan 14 19:56:05 CST 2004

Thanks for your reply.
I also have Walter's WDM book.
But I didn't understand the relative topics well for this.

Best Regards

Jackal Huang

"Calvin Guan" <ndisnewREMOVE_THE_CAPITALS@yahoo.com> ...
> "Jackal Huang" <huangjj@hotmail.com> wrote in message
> news:#V7B7UO2DHA.2680@TK2MSFTNGP11.phx.gbl...
> > In IoComplete routine, sometimes it check Irp->PendingReturned
> > and call IoMarkIrpPending if the flag is set.
> >
> > Is there any rule for this?
> >
>
> In short, always execute the code:
>
> if (Irp->PendingReturned)
> {
> IoMarkIrpPending(Irp);
> }
> IF and ONLY IF your CompletionRoutine returns anything OTHER THAN
> STATUS_MORE_PROCESSING_REQUIRED unless the following 2 conditions I can
> think of,
>
> 1. No need to mark pending if the Irp has been marked pending when it was
> being queued in the dispatch routine.
> 2. Never mark Irp pending in the completion routine of the IRP orginator
> (the one who created the Irp) since there's no IRP stack at that point.
>
> To add what Bill said, Walter's 2nd WDM book gives a very decent
description
> on Irp handling, so does the "IRP cheat sheet" published by MSFT. Still,
> many of my speculations, suspicions are not solved until I reverse
engineer
> the IoCompleteRequest and IopSynchronousServiceTail.
>
> --
> Calvin Guan Software Engineer cguan@pleasenospam.ati.com
> ATI Technologies Inc. Markham ON. Canada (905) 882-2600x8654
>
>
>