Question on IRP lifetime ...

Hi,

I am telling the I/O manager to build an IRP using IoBuildDeviceIoControlRequest() for IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO. Now I wonder how long I can access the IO_STATUS_BLOCK which can be accessed through the respective IRP member.

On one hand the documentation states “IRPs that are created by IoBuildDeviceIoControlRequest must be completed by some driver’s call to IoCompleteRequest.” on the other hand “A driver that calls IoBuildDeviceIoControlRequest must not call IoFreeIrp, because the I/O manager frees these synchronous IRPs after IoCompleteRequest has been called.”

I am not calling IoCompleteRequest() for the IRP currently, do I have to? Once the IRP was completed it says it is being freed, so how do I access the IO_STATUS_BLOCK? Is this still safe? Currently I am doing it without any problems, but I have my doubts whether this is “politically correct” :wink:

Thanks for any help,

Oliver


May the source be with you, stranger :wink:

ICQ: #281645
URL: http://assarbad.net

You pass your own IO_STATUS_BLOCK to this call. It will contain the
results of the IRP after it has been completed. The lower driver to
which you sent the irp will have called IoCompleteRequest. When that
lower driver completes the request, it will be subsequently freed by the
io manager. Typically the code which uses this api looks like

Irp = IoBuildDeviceIoControlRequest();
Status = IoCallDriver(target, irp);

If (status == STATUS_PENDING) {
wait on the event passed to IoBuildDeviceIoControlRequest()
}

Look at local Iosb.Status & Information

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Oliver Schneider
Sent: Thursday, June 15, 2006 8:44 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Question on IRP lifetime …

Hi,

I am telling the I/O manager to build an IRP using
IoBuildDeviceIoControlRequest() for
IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO. Now I wonder how long I can
access the IO_STATUS_BLOCK which can be accessed through the respective
IRP member.

On one hand the documentation states “IRPs that are created by
IoBuildDeviceIoControlRequest must be completed by some driver’s call to
IoCompleteRequest.” on the other hand “A driver that calls
IoBuildDeviceIoControlRequest must not call IoFreeIrp, because the I/O
manager frees these synchronous IRPs after IoCompleteRequest has been
called.”

I am not calling IoCompleteRequest() for the IRP currently, do I have
to? Once the IRP was completed it says it is being freed, so how do I
access the IO_STATUS_BLOCK? Is this still safe? Currently I am doing it
without any problems, but I have my doubts whether this is “politically
correct” :wink:

Thanks for any help,

Oliver


May the source be with you, stranger :wink:

ICQ: #281645
URL: http://assarbad.net


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

You may touch the status information during completion processing in your
driver. You then return from that routine with STATUS_SUCCESS or it
equivalent and never touch the IRP again. Look at some of the samples.

“Oliver Schneider” wrote in message
news:xxxxx@ntdev…
> Hi,
>
> I am telling the I/O manager to build an IRP using
> IoBuildDeviceIoControlRequest() for IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO.
> Now I wonder how long I can access the IO_STATUS_BLOCK which can be
> accessed through the respective IRP member.
>
> On one hand the documentation states “IRPs that are created by
> IoBuildDeviceIoControlRequest must be completed by some driver’s call to
> IoCompleteRequest.” on the other hand “A driver that calls
> IoBuildDeviceIoControlRequest must not call IoFreeIrp, because the I/O
> manager frees these synchronous IRPs after IoCompleteRequest has been
> called.”
>
> I am not calling IoCompleteRequest() for the IRP currently, do I have to?
> Once the IRP was completed it says it is being freed, so how do I access
> the IO_STATUS_BLOCK? Is this still safe? Currently I am doing it without
> any problems, but I have my doubts whether this is “politically correct”
> :wink:
>
> Thanks for any help,
>
> Oliver
> –
> ---------------------------------------------------
> May the source be with you, stranger :wink:
>
> ICQ: #281645
> URL: http://assarbad.net
>

Thanks. I am a little embarassed now, since I should have noticed that connection myself. It was that missing link between my status block on the stack and the one inside the IRP %-)

Actually the sample code I saw referenced the status block directly from the (potentially freed) IRP 8-o

Thanks again,

Oliver


May the source be with you, stranger :wink:

ICQ: #281645
URL: http://assarbad.net

>IOCTL_INTERNAL_GET_PARALLEL_PORT_INFO. Now I wonder how long I

can access the IO_STATUS_BLOCK which can be accessed through the
respective IRP member.

You lose the right to touch the IRP after IoCallDriver is called, and till your
completion routine will be called by the OS.

If you have no completion routine - then you lose this right forever after
IoCallDriver.

If you have the completion routine - then you can queue the IRP somewhere
there, or re-submit it to the lower driver by IoCallDriver (again the above
rule applies), but in the very end you must sooner or later return
STATUS_SUCCESS from the completion routine, or call IoCallDriver without the
completion routine.

If you return STATUS_SUCCESS - then this is the last point you can touch this
IRP. This operation handles the IRP to the code in the IO manager which will
destroy it. You cannot destroy such IRPs yourself.

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