Synchronous IRP clean up question.

Hello,

IoBuildDeviceIoControlRequest is synchronous IRP and according DDK and
Walter Oney’s book I/O manager automaticaly cleans up it following a call to
IoCompleteRequest. It also deletes this IRP after completion routine
returns.
I remember that in Art Baker book “The Windows 2000 Device Driver Book” I/O
manager frees IRP on return STATUS_SUCCESS from competion routine.
I am using STATUS_MORE_PROCESSING_REQUIRED to return from completion routine
and it looks like I/O Manager still frees my IRP.
How I/O Manager decides that it can free IRP after completion routine
returns?

Thank you
Leonid

> I am using STATUS_MORE_PROCESSING_REQUIRED to return from completion routine

and it looks like I/O Manager still frees my IRP.

Are you re-submitting the IRP back from this completion routine?

The requirement for “fully built” IRPs is only that the last of the completion
routine invocations must return STATUS_SUCCESS. Some intermediate invocations
can return STATUS_MORE_PROCESSING_REQUIRED. These invocations must either send
the IRP down again via IoCallDriver or put the IRP to some context from where
it will be completed using IoCompleteRequest.

Note that it is valid to do the following:

CompletionRoutine()
{
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_MORE_PROCESSING_REQUIRED;
}

and this is the same as returning STATUS_SUCCESS.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Thank you for response, but it is still not quite clear - what is exact
logic I/O Manager uses to managed IRP after competion routine returns?
If completion routine returns STATUS_MORE_PROCESSING_REQUIRED will or will
not I/O Manager free synchronous IRP?

My scenario is:

  1. I build synchronous IRP (IoBuildDeviceIoControlRequest), set completion
    routine and send it down.
  2. In completion routine (this is the last of the completion routine
    invocation)
    CompletionRoutine()
    {


    return STATUS_MORE_PROCESSING_REQUIRED;
    }

Should I delete the IRP incompletion routine or I/O Manager will do it after
completion routine return?
Or should I return STATUS_SUCCESS? In this case will I/O Manager try to
process IRP further?

Thank you
Leonid

----- Original Message -----
From: “Maxim S. Shatskih”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, October 08, 2003 10:18 AM
Subject: [ntdev] Re: Synchronous IRP clean up question.

> > I am using STATUS_MORE_PROCESSING_REQUIRED to return from completion
routine
> > and it looks like I/O Manager still frees my IRP.
>
> Are you re-submitting the IRP back from this completion routine?
>
> The requirement for “fully built” IRPs is only that the last of the
completion
> routine invocations must return STATUS_SUCCESS. Some intermediate
invocations
> can return STATUS_MORE_PROCESSING_REQUIRED. These invocations must either
send
> the IRP down again via IoCallDriver or put the IRP to some context from
where
> it will be completed using IoCompleteRequest.
>
> Note that it is valid to do the following:
>
> CompletionRoutine()
> {
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
> return STATUS_MORE_PROCESSING_REQUIRED;
> }
>
> and this is the same as returning STATUS_SUCCESS.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@v-one.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

> logic I/O Manager uses to managed IRP after competion routine returns?

If completion routine returns STATUS_MORE_PROCESSING_REQUIRED will or will
not I/O Manager free synchronous IRP?

Not, it will immediately return from IoCompleteRequest.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

You must let IoManager complete processing of an IRP that is build by
IoBuildDeviceIoControlRequest.
If you have returned STATUS_MORE_PROCESSING_REQUIRED you need to complete
the IRP later using IoCompleteRequest. Alternatively you may return
STATUS_SUCCESS from completion routine or just do not set any completion
routine.
You should never deallocate such IRP yourself.

Alexei.

“Leonid Meyerovich” wrote in message
news:xxxxx@ntdev…
>
>
> Thank you for response, but it is still not quite clear - what is exact
> logic I/O Manager uses to managed IRP after competion routine returns?
> If completion routine returns STATUS_MORE_PROCESSING_REQUIRED will or will
> not I/O Manager free synchronous IRP?
>
> My scenario is:
> 1. I build synchronous IRP (IoBuildDeviceIoControlRequest), set completion
> routine and send it down.
> 2. In completion routine (this is the last of the completion routine
> invocation)
> CompletionRoutine()
> {
> …
> …
> return STATUS_MORE_PROCESSING_REQUIRED;
> }
>
> Should I delete the IRP incompletion routine or I/O Manager will do it
after
> completion routine return?
> Or should I return STATUS_SUCCESS? In this case will I/O Manager try to
> process IRP further?
>
> Thank you
> Leonid
>
>
> ----- Original Message -----
> From: “Maxim S. Shatskih”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, October 08, 2003 10:18 AM
> Subject: [ntdev] Re: Synchronous IRP clean up question.
>
>
> > > I am using STATUS_MORE_PROCESSING_REQUIRED to return from completion
> routine
> > > and it looks like I/O Manager still frees my IRP.
> >
> > Are you re-submitting the IRP back from this completion routine?
> >
> > The requirement for “fully built” IRPs is only that the last of the
> completion
> > routine invocations must return STATUS_SUCCESS. Some intermediate
> invocations
> > can return STATUS_MORE_PROCESSING_REQUIRED. These invocations must
either
> send
> > the IRP down again via IoCallDriver or put the IRP to some context from
> where
> > it will be completed using IoCompleteRequest.
> >
> > Note that it is valid to do the following:
> >
> > CompletionRoutine()
> > {
> > IoCompleteRequest(Irp, IO_NO_INCREMENT);
> > return STATUS_MORE_PROCESSING_REQUIRED;
> > }
> >
> > and this is the same as returning STATUS_SUCCESS.
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@v-one.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
>
>

My best quess is that you might have an error in how you set up your
completion routine and it’s not getting called. If you are sure that it is,
then tell me how you know that “I/O manager” frees the IRP.

Everyone is sure that you are not telling the whole story about what you are
doing with the IRP, because there is no way the “I/O manager” will free it
when it sees MORE_PROCESSING_REQUIRED as the return code from a completion
routine, because “I/O manager” is pretty sure in this case that the IRP
might have already been freed in the completion routine itself!

“Leonid Meyerovich” wrote in message
news:xxxxx@ntdev…
>
> Hello,
>
> IoBuildDeviceIoControlRequest is synchronous IRP and according DDK and
> Walter Oney’s book I/O manager automaticaly cleans up it following a call
to
> IoCompleteRequest. It also deletes this IRP after completion routine
> returns.
> I remember that in Art Baker book “The Windows 2000 Device Driver Book”
I/O
> manager frees IRP on return STATUS_SUCCESS from competion routine.
> I am using STATUS_MORE_PROCESSING_REQUIRED to return from completion
routine
> and it looks like I/O Manager still frees my IRP.
> How I/O Manager decides that it can free IRP after completion routine
> returns?
>
> Thank you
> Leonid
>
>
>
>

Thanks everybody for answering,
I am certainly telling the whole story, my completion routine works fine and
this is the last completion routine for the IRP I have created.

I think my I/O Manager doesn’t free my IRPs when completion routine returns
MORE_PROCESSING_REQUIRED (BTW, how can I check it?), even driver keep
working .

So, return from completion routine STATUS_SUCCESS is the only sign for I/O
Manager to free synchronous IRP. Please correct me if I am wrong.

Thank you
Leonid

----- Original Message -----
From: “Ivan Bublikov”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Wednesday, October 08, 2003 11:44 PM
Subject: [ntdev] Re: Synchronous IRP clean up question.

> My best quess is that you might have an error in how you set up your
> completion routine and it’s not getting called. If you are sure that it
is,
> then tell me how you know that “I/O manager” frees the IRP.
>
> Everyone is sure that you are not telling the whole story about what you
are
> doing with the IRP, because there is no way the “I/O manager” will free it
> when it sees MORE_PROCESSING_REQUIRED as the return code from a completion
> routine, because “I/O manager” is pretty sure in this case that the IRP
> might have already been freed in the completion routine itself!
>
> “Leonid Meyerovich” wrote in message
> news:xxxxx@ntdev…
> >
> > Hello,
> >
> > IoBuildDeviceIoControlRequest is synchronous IRP and according DDK and
> > Walter Oney’s book I/O manager automaticaly cleans up it following a
call
> to
> > IoCompleteRequest. It also deletes this IRP after completion routine
> > returns.
> > I remember that in Art Baker book “The Windows 2000 Device Driver Book”
> I/O
> > manager frees IRP on return STATUS_SUCCESS from competion routine.
> > I am using STATUS_MORE_PROCESSING_REQUIRED to return from completion
> routine
> > and it looks like I/O Manager still frees my IRP.
> > How I/O Manager decides that it can free IRP after completion routine
> > returns?
> >
> > Thank you
> > Leonid
> >
> >
> >
> >
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@v-one.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

In your initial posting you said that the I/O manager frees your IRP when
you return MORE_PROCESSING_REQUIRED, that’s where “not telling the whole
story” came from. Now you are not saying that anymore.

The IRP completion is done by IoCompleteRequest. To answer your question,
it’s natural to turn attention to IoCompleteRequest. Let me tell you what I
think IoCompleteRequest is doing, and you can try to verify that. This is a
very crude description, but I believe it is correct in its major features.

Generally, the function walks IRP stack locations, from the current to the
oldest one, calling completion routines. At the same time, it moves the
current location’s pointer in the IRP by one position, before it calls the
completion routine. If a completion routine returns
MORE_PROCESSING_REQUIRED, IoCompleteRequest immediately exits. If you
immediately call IoCompleteRequest again on this IRP, it will continue
walking and calling completion routines, from the place it stopped the last
time. Because the current location’s pointer was moved before calling that
last completion routine (which returned MORE_PROCESSING_REQUIRED), this time
it will call the next older completion routine and proceed from that to
older ones.

(Of course, all the above is done with paying proper attention to whether
the completion routine at hand is even specified (not NULL), and whether it
needs to be called given the IRP completion status (success, failure or
cancel) which is determined by IoStatus.Status and Cancel fields in the
IRP).

When IoCompleteRequest reaches the point where there are no more locations
to walk (when the current location’s pointer is beyond the oldest one), it
will do whatever other processing needs to be done on the IRP to dispose of
it, including freeing the IRP.

(It looks like IoCompleteRequest has a notion of one “immaterial” location
that corresponds to this final processing, because it accounts for this
processing by moving the current location’s pointer by one more position,
before doing the final processing (of course, there is no valid memory where
it points now, that’s why I call it “immaterial”). This is used to make sure
that IoCompleteRequest can’t be hoaxed into doing the final processing more
than once).

To summarize, it looks to me that you can return MORE_PROCESSING_REQUIRED
and then later call IoCompleteRequest to do the final processing. Or you can
return SUCCESS and then IoCompleteRequest will continue and do the final
processing immediately after that.

“Leonid Meyerovich” wrote in message
news:xxxxx@ntdev…
>
>
> Thanks everybody for answering,
> I am certainly telling the whole story, my completion routine works fine
and
> this is the last completion routine for the IRP I have created.
>
> I think my I/O Manager doesn’t free my IRPs when completion routine
returns
> MORE_PROCESSING_REQUIRED (BTW, how can I check it?), even driver keep
> working .
>
> So, return from completion routine STATUS_SUCCESS is the only sign for I/O
> Manager to free synchronous IRP. Please correct me if I am wrong.
>
> Thank you
> Leonid
>
>
> ----- Original Message -----
> From: “Ivan Bublikov”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, October 08, 2003 11:44 PM
> Subject: [ntdev] Re: Synchronous IRP clean up question.
>
>
> > My best quess is that you might have an error in how you set up your
> > completion routine and it’s not getting called. If you are sure that it
> is,
> > then tell me how you know that “I/O manager” frees the IRP.
> >
> > Everyone is sure that you are not telling the whole story about what you
> are
> > doing with the IRP, because there is no way the “I/O manager” will free
it
> > when it sees MORE_PROCESSING_REQUIRED as the return code from a
completion
> > routine, because “I/O manager” is pretty sure in this case that the IRP
> > might have already been freed in the completion routine itself!
> >
> > “Leonid Meyerovich” wrote in message
> > news:xxxxx@ntdev…
> > >
> > > Hello,
> > >
> > > IoBuildDeviceIoControlRequest is synchronous IRP and according DDK and
> > > Walter Oney’s book I/O manager automaticaly cleans up it following a
> call
> > to
> > > IoCompleteRequest. It also deletes this IRP after completion routine
> > > returns.
> > > I remember that in Art Baker book “The Windows 2000 Device Driver
Book”
> > I/O
> > > manager frees IRP on return STATUS_SUCCESS from competion routine.
> > > I am using STATUS_MORE_PROCESSING_REQUIRED to return from completion
> > routine
> > > and it looks like I/O Manager still frees my IRP.
> > > How I/O Manager decides that it can free IRP after completion routine
> > > returns?
> > >
> > > Thank you
> > > Leonid
> > >
> > >
> > >
> > >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@v-one.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
>
>

> it’s natural to turn attention to IoCompleteRequest. Let me tell you what I

think IoCompleteRequest is doing, and you can try to verify that. This is a
very crude description, but I believe it is correct in its major features.

Must I publish the reverse-engineered code from NT4’s IoCompleteRequest?

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Of course. It’s been so painful over the years to watch simple IRP flow
questions always answered with something that looks like a charm: “Just call
MarkPending and return PENDING and you are going to be fine, unless there
was a full moon yesterday, but don’t ask me why I won’t tell you, just do
what I say and it will work” :slight_smile: How many of those endless discussions could
be avoided if you published your code!

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>
> > it’s natural to turn attention to IoCompleteRequest. Let me tell you
what I
> > think IoCompleteRequest is doing, and you can try to verify that. This
is a
> > very crude description, but I believe it is correct in its major
features.
>
> Must I publish the reverse-engineered code from NT4’s IoCompleteRequest?
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>

Ivan Bublikov wrote:

Of course. It’s been so painful over the years to watch simple IRP flow
questions always answered with something that looks like a charm: “Just call
MarkPending and return PENDING and you are going to be fine, unless there
was a full moon yesterday, but don’t ask me why I won’t tell you, just do
what I say and it will work” :slight_smile: How many of those endless discussions could
be avoided if you published your code!

PMFJI, but I think ch. 5 in my book would answer all of your questions,
including why and when to call IoMarkIrpPending. The $2 I’ll earn
against my royalty advance is, of course, my financial motive in
plugging my book…


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Check out our schedule at http://www.oneysoft.com

http://support.microsoft.com/default.aspx?scid=kb;en-us;320275

-Eliyas
This posting is provided “AS IS” with no warranties, and confers no rights.

“Ivan Bublikov” wrote in message
news:xxxxx@ntdev…
>
> Of course. It’s been so painful over the years to watch simple IRP flow
> questions always answered with something that looks like a charm: “Just
call
> MarkPending and return PENDING and you are going to be fine, unless there
> was a full moon yesterday, but don’t ask me why I won’t tell you, just do
> what I say and it will work” :slight_smile: How many of those endless discussions
could
> be avoided if you published your code!
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntdev…
> >
> > > it’s natural to turn attention to IoCompleteRequest. Let me tell you
> what I
> > > think IoCompleteRequest is doing, and you can try to verify that. This
> is a
> > > very crude description, but I believe it is correct in its major
> features.
> >
> > Must I publish the reverse-engineered code from NT4’s IoCompleteRequest?
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> >
> >
>
>
>

Thank you for detailed explanation.
Leonid

----- Original Message -----
From: “Ivan Bublikov”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Thursday, October 09, 2003 4:38 PM
Subject: [ntdev] Re: Synchronous IRP clean up question.

> In your initial posting you said that the I/O manager frees your IRP when
> you return MORE_PROCESSING_REQUIRED, that’s where “not telling the whole
> story” came from. Now you are not saying that anymore.
>
> The IRP completion is done by IoCompleteRequest. To answer your question,
> it’s natural to turn attention to IoCompleteRequest. Let me tell you what
I
> think IoCompleteRequest is doing, and you can try to verify that. This is
a
> very crude description, but I believe it is correct in its major features.
>
> Generally, the function walks IRP stack locations, from the current to the
> oldest one, calling completion routines. At the same time, it moves the
> current location’s pointer in the IRP by one position, before it calls the
> completion routine. If a completion routine returns
> MORE_PROCESSING_REQUIRED, IoCompleteRequest immediately exits. If you
> immediately call IoCompleteRequest again on this IRP, it will continue
> walking and calling completion routines, from the place it stopped the
last
> time. Because the current location’s pointer was moved before calling that
> last completion routine (which returned MORE_PROCESSING_REQUIRED), this
time
> it will call the next older completion routine and proceed from that to
> older ones.
>
> (Of course, all the above is done with paying proper attention to whether
> the completion routine at hand is even specified (not NULL), and whether
it
> needs to be called given the IRP completion status (success, failure or
> cancel) which is determined by IoStatus.Status and Cancel fields in the
> IRP).
>
> When IoCompleteRequest reaches the point where there are no more locations
> to walk (when the current location’s pointer is beyond the oldest one), it
> will do whatever other processing needs to be done on the IRP to dispose
of
> it, including freeing the IRP.
>
> (It looks like IoCompleteRequest has a notion of one “immaterial” location
> that corresponds to this final processing, because it accounts for this
> processing by moving the current location’s pointer by one more position,
> before doing the final processing (of course, there is no valid memory
where
> it points now, that’s why I call it “immaterial”). This is used to make
sure
> that IoCompleteRequest can’t be hoaxed into doing the final processing
more
> than once).
>
> To summarize, it looks to me that you can return MORE_PROCESSING_REQUIRED
> and then later call IoCompleteRequest to do the final processing. Or you
can
> return SUCCESS and then IoCompleteRequest will continue and do the final
> processing immediately after that.
>
> “Leonid Meyerovich” wrote in message
> news:xxxxx@ntdev…
> >
> >
> > Thanks everybody for answering,
> > I am certainly telling the whole story, my completion routine works fine
> and
> > this is the last completion routine for the IRP I have created.
> >
> > I think my I/O Manager doesn’t free my IRPs when completion routine
> returns
> > MORE_PROCESSING_REQUIRED (BTW, how can I check it?), even driver keep
> > working .
> >
> > So, return from completion routine STATUS_SUCCESS is the only sign for
I/O
> > Manager to free synchronous IRP. Please correct me if I am wrong.
> >
> > Thank you
> > Leonid
> >
> >
> > ----- Original Message -----
> > From: “Ivan Bublikov”
> > Newsgroups: ntdev
> > To: “Windows System Software Devs Interest List”
> > Sent: Wednesday, October 08, 2003 11:44 PM
> > Subject: [ntdev] Re: Synchronous IRP clean up question.
> >
> >
> > > My best quess is that you might have an error in how you set up your
> > > completion routine and it’s not getting called. If you are sure that i
t
> > is,
> > > then tell me how you know that “I/O manager” frees the IRP.
> > >
> > > Everyone is sure that you are not telling the whole story about what
you
> > are
> > > doing with the IRP, because there is no way the “I/O manager” will
free
> it
> > > when it sees MORE_PROCESSING_REQUIRED as the return code from a
> completion
> > > routine, because “I/O manager” is pretty sure in this case that the
IRP
> > > might have already been freed in the completion routine itself!
> > >
> > > “Leonid Meyerovich” wrote in message
> > > news:xxxxx@ntdev…
> > > >
> > > > Hello,
> > > >
> > > > IoBuildDeviceIoControlRequest is synchronous IRP and according DDK
and
> > > > Walter Oney’s book I/O manager automaticaly cleans up it following a
> > call
> > > to
> > > > IoCompleteRequest. It also deletes this IRP after completion routine
> > > > returns.
> > > > I remember that in Art Baker book “The Windows 2000 Device Driver
> Book”
> > > I/O
> > > > manager frees IRP on return STATUS_SUCCESS from competion routine.
> > > > I am using STATUS_MORE_PROCESSING_REQUIRED to return from completion
> > > routine
> > > > and it looks like I/O Manager still frees my IRP.
> > > > How I/O Manager decides that it can free IRP after completion
routine
> > > > returns?
> > > >
> > > > Thank you
> > > > Leonid
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@v-one.com
> > > To unsubscribe send a blank email to xxxxx@lists.osr.com
> > >
> >
> >
> >
> >
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@v-one.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>