Re: [ntdev]why must driver call IoMarkIrpPending?

If you return STATUS_PENDING, then you MUST call IoMarkIrpPending() before the IRP gots into the context where it can be completed by DpcForIsr or such.
Also - if you called IoMarkIrpPending(), then you MUST return STATUS_PENDING.
Otherwise, you will have either a hung IRP or MULTIPLE_IRP_COMPLETE_REQUESTS BSOD.
Note that this:

IoMarkIrpPending(Irp);
IoCallDriver(DeviceObject, Irp);
return STATUS_PENDING;

is valid code, but:

IoMarkIrpPending(Irp);
return IoCallDriver(DeviceObject, Irp);

is NOT, though the CLASS2 assembly does exactly this. They are saved by the fact SCSIPORT always returns STATUS_PENDING.

Max

----- Original Message -----
From: Assaf Wodeslavsky
To: NT Developers Interest List
Sent: Thursday, December 06, 2001 8:43 PM
Subject: [ntdev] [ntdev]why must driver call IoMarkIrpPending?

hi all

in osr’s book page:332
it says that a driver must call IoMarkIrpPending
as well as return STATUS_PENDING

“failure of a driver to do both of these things causes improper system behaviour”

what improper system behaviour?
and why?

assaf

You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

hi all

skiming thru all the discussions,
it seems that they are all dealing with layered drivers

my question is about a very simple (non layered)
serialized driver
in the dispatch routine
before calling IoStartPacket
lets say it does not call IoMarkIrpPending
but it decides to return STATUS_PENDING

here is the code:

NTSTATUS
XxDispatchWrite(
IN PDEVICE_OBJECT pDO,
IN PIRP Irp
)
{
////////////////IoMarkIrpPending( Irp );////////////////// driver does
not call IoMarkIrpPending
IoStartPacket( pDO, Irp, 0, NULL );
return STATUS_PENDING;
}

would it harm anything by not calling IoMarkIrpPending?
osr’s book says that it would
my question is how and why
assaf

----- Original Message -----
From: “Peter Viscarola”
Newsgroups: ntdev
To: “NT Developers Interest List”
Sent: Thursday, December 06, 2001 11:25 PM
Subject: [ntdev] Re: [ntdev]why must driver call IoMarkIrpPending?

> > “Assaf Wodeslavsky” wrote in message
> news:xxxxx@ntdev…
>
> Tony’s landmark article:
http://www.osr.com/ntinsider/1997/iocomp/iocomp.htm
> More recent article on pending IRPs, focusing precisely on STATUS_PENDING
> and completion routines
> http://www.osr.com/ntinsider/2001/pending/pending.htm
>
> Peter
> OSR
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@hotmail.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> would it harm anything by not calling IoMarkIrpPending?

osr’s book says that it would
my question is how and why

Yes it would.

This will lead IopCompleteRequest to be NEVER called - neither from IopSynchrohousServiceTail who sent the IRP to your driver (since
you returned STATUS_PENDING) nor from IoCompleteRequest as an APC (since you did NOT call IoMarkIrpPending).
So, you will have a hung IRP, which usually lead to a hung user app without ANY possibility to kill it.

Max


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

“Assaf Wodeslavsky” wrote in message
news:xxxxx@ntdev…
>
> my question is about a very simple (non layered)
> serialized driver
> in the dispatch routine
> before calling IoStartPacket
> lets say it does not call IoMarkIrpPending
> but it decides to return STATUS_PENDING
>
Dude, please read the papers folks on this forum cited. I have you the
URLs. All should then be clear.

You can’t return STATUS_PENDING without marking the IRP pending, cuz when
the IRP is eventually completed, it won’t be marked as having pended, so the
I/O Manager won’t know to call perform I/O Completion Processing Stage 2
(IopCompleteRequest), by queuing the special kernel APC for I/O completion.
QED.

It’s a simple rule. To pend an IRP you MUST call IoMarkIrpPending, AND
return STATUS_PENDING. You must do both of these things, or it will not
work.

Peter
OSR


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

ok
got it
[without reading the papers]
thanks
assaf

----- Original Message -----
From: “PeterGV”
Newsgroups: ntdev
To: “NT Developers Interest List”
Sent: Friday, December 07, 2001 11:10 PM
Subject: [ntdev] Re: why must driver call IoMarkIrpPending?

> “Assaf Wodeslavsky” wrote in message
> news:xxxxx@ntdev…
> >
> > my question is about a very simple (non layered)
> > serialized driver
> > in the dispatch routine
> > before calling IoStartPacket
> > lets say it does not call IoMarkIrpPending
> > but it decides to return STATUS_PENDING
> >
> Dude, please read the papers folks on this forum cited. I have you the
> URLs. All should then be clear.
>
> You can’t return STATUS_PENDING without marking the IRP pending, cuz when
> the IRP is eventually completed, it won’t be marked as having pended, so
the
> I/O Manager won’t know to call perform I/O Completion Processing Stage 2
> (IopCompleteRequest), by queuing the special kernel APC for I/O
completion.
> QED.
>
> It’s a simple rule. To pend an IRP you MUST call IoMarkIrpPending, AND
> return STATUS_PENDING. You must do both of these things, or it will not
> work.
>
> Peter
> OSR
>
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@hotmail.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Amen!

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of PeterGV
Sent: Friday, December 07, 2001 1:10 PM
To: NT Developers Interest List
Subject: [ntdev] Re: why must driver call IoMarkIrpPending?

“Assaf Wodeslavsky” wrote in message
news:xxxxx@ntdev…
>
> my question is about a very simple (non layered)
> serialized driver
> in the dispatch routine
> before calling IoStartPacket
> lets say it does not call IoMarkIrpPending
> but it decides to return STATUS_PENDING
>
Dude, please read the papers folks on this forum cited. I have you the
URLs. All should then be clear.

You can’t return STATUS_PENDING without marking the IRP pending, cuz
when the IRP is eventually completed, it won’t be marked as having
pended, so the I/O Manager won’t know to call perform I/O Completion
Processing Stage 2 (IopCompleteRequest), by queuing the special kernel
APC for I/O completion. QED.

It’s a simple rule. To pend an IRP you MUST call IoMarkIrpPending, AND
return STATUS_PENDING. You must do both of these things, or it will not
work.

Peter
OSR


You are currently subscribed to ntdev as: xxxxx@storagecraft.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com