Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the stack. I wait on an event for the completion of the IRP. This is called in the context of a driver allocated thread that comes into existance when the driver is loaded and terminates when the driver is unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the IRP 's created by IoBuildDeviceIoControlRequest must be completed by a driver’s call to IoCompleteRequest, this is when the I/O manager frees the IRP. It also states that when the thread exits the I/O manager cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest. So in these cases the driver writer is deffering the freeing of the IRP to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded so there could be 1000’s of IRP’s hanging around that are not getting freed. Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden

What return value does your driver return from IoCompleteRequest? As long as it is != STATUS_MORE_PROCESSING_REQUIRED, this will complete the irp

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@lasercard.com
Sent: Thursday, August 9, 2012 1:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the stack. I wait on an event for the completion of the IRP. This is called in the context of a driver allocated thread that comes into existance when the driver is loaded and terminates when the driver is unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the IRP 's created by IoBuildDeviceIoControlRequest must be completed by a driver’s call to IoCompleteRequest, this is when the I/O manager frees the IRP. It also states that when the thread exits the I/O manager cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest. So in these cases the driver writer is deffering the freeing of the IRP to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded so there could be 1000’s of IRP’s hanging around that are not getting freed. Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and
IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the
stack. I wait on an event for the completion of the IRP. This is called in
the context of a driver allocated thread that comes into existance when the
driver is loaded and terminates when the driver is unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the IRP
's created by IoBuildDeviceIoControlRequest must be completed by a driver’s
call to IoCompleteRequest, this is when the I/O manager frees the IRP. It
also states that when the thread exits the I/O manager cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest. So
in these cases the driver writer is deffering the freeing of the IRP to the
time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded so
there could be 1000’s of IRP’s hanging around that are not getting freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

Correct, but for IoBuildXxx generated irps, you need to complete the request back to the io manager so the irp can be freed. This is unlike IoAllocateIrp created IRPs which must never be completed back to the io manager to be freed, your driver must free them with IoFreeIrp

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Bill Wandel
Sent: Thursday, August 9, 2012 1:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the stack. I wait on an event for the completion of the IRP. This is called in the context of a driver allocated thread that comes into existance when the driver is loaded and terminates when the driver is unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the IRP 's created by IoBuildDeviceIoControlRequest must be completed by a driver’s call to IoCompleteRequest, this is when the I/O manager frees the IRP. It also states that when the thread exits the I/O manager cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest. So in these cases the driver writer is deffering the freeing of the IRP to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded so there could be 1000’s of IRP’s hanging around that are not getting freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

Sorry, not sure I understand your question. I do not call IoCompleteRequest for this irp. How I complete the original irp that is passed to my driver is not relevant to the irp that I allocated inside my driver allocated thread, right?
H

So I do need to complete the request, and according to the documentation
for IoBuildDeviceIoControlRequest IoCompleteRequest is the way to do it
as this will free the irp.
Thanks,
Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 1:34 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Correct, but for IoBuildXxx generated irps, you need to complete the
request back to the io manager so the irp can be freed. This is unlike
IoAllocateIrp created IRPs which must never be completed back to the io
manager to be freed, your driver must free them with IoFreeIrp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bill Wandel
Sent: Thursday, August 9, 2012 1:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest
and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the
stack. I wait on an event for the completion of the IRP. This is
called in the context of a driver allocated thread that comes into
existance when the driver is loaded and terminates when the driver is
unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the
IRP 's created by IoBuildDeviceIoControlRequest must be completed by a
driver’s call to IoCompleteRequest, this is when the I/O manager frees
the IRP. It also states that when the thread exits the I/O manager
cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest.
So in these cases the driver writer is deffering the freeing of the IRP
to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded
so there could be 1000’s of IRP’s hanging around that are not getting
freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

Hi,

Thanks for your answer Doron.

So, on further inspection I found that my function SendAwaitUrb that
calls IoBuildDev… can be called directly from my PNP dispatch
function. In this case the irp from IoBuildDev… is created in the
context of the PNP request and so will be freed when IoCompleteRequest
is called for the original irp as long as this is not completed with
STATUS_MORE_PROCESSING_REQUIRED.

However when this function is called from my driver allocated thread I
need to explicitly complete the allocated irp with IoCompleteRequest
which will then free the irp.

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 09, 2012 1:51 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

So I do need to complete the request, and according to the documentation
for IoBuildDeviceIoControlRequest IoCompleteRequest is the way to do it
as this will free the irp.
Thanks,
Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 1:34 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Correct, but for IoBuildXxx generated irps, you need to complete the
request back to the io manager so the irp can be freed. This is unlike
IoAllocateIrp created IRPs which must never be completed back to the io
manager to be freed, your driver must free them with IoFreeIrp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bill Wandel
Sent: Thursday, August 9, 2012 1:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest
and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the
stack. I wait on an event for the completion of the IRP. This is
called in the context of a driver allocated thread that comes into
existance when the driver is loaded and terminates when the driver is
unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the
IRP 's created by IoBuildDeviceIoControlRequest must be completed by a
driver’s call to IoCompleteRequest, this is when the I/O manager frees
the IRP. It also states that when the thread exits the I/O manager
cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest.
So in these cases the driver writer is deffering the freeing of the IRP
to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded
so there could be 1000’s of IRP’s hanging around that are not getting
freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

You are confusing yourself. When you build an irp with IoBuildXxx, you can complete it in three ways

  1. return something != STATUS_MORE_PROCESSING_REQUIRED in your completion routine
  2. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and explicitly call IoCompleteRequest in the completion routine
  3. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and explicitly call IoCompleteRequest somewhere outside of the completion routine

Don’t rely on thread termination to clean up the irp on your behalf, especially when you are in an arbitrary thread context like the pnp start irp

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 9, 2012 2:52 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

Thanks for your answer Doron.

So, on further inspection I found that my function SendAwaitUrb that calls IoBuildDev… can be called directly from my PNP dispatch function. In this case the irp from IoBuildDev… is created in the context of the PNP request and so will be freed when IoCompleteRequest is called for the original irp as long as this is not completed with STATUS_MORE_PROCESSING_REQUIRED.

However when this function is called from my driver allocated thread I need to explicitly complete the allocated irp with IoCompleteRequest which will then free the irp.

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 09, 2012 1:51 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

So I do need to complete the request, and according to the documentation for IoBuildDeviceIoControlRequest IoCompleteRequest is the way to do it as this will free the irp.
Thanks,
Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 1:34 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

Correct, but for IoBuildXxx generated irps, you need to complete the request back to the io manager so the irp can be freed. This is unlike IoAllocateIrp created IRPs which must never be completed back to the io manager to be freed, your driver must free them with IoFreeIrp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bill Wandel
Sent: Thursday, August 9, 2012 1:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the stack. I wait on an event for the completion of the IRP. This is called in the context of a driver allocated thread that comes into existance when the driver is loaded and terminates when the driver is unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the IRP 's created by IoBuildDeviceIoControlRequest must be completed by a driver’s call to IoCompleteRequest, this is when the I/O manager frees the IRP. It also states that when the thread exits the I/O manager cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest.
So in these cases the driver writer is deffering the freeing of the IRP to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded so there could be 1000’s of IRP’s hanging around that are not getting freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

Yes, I think I am confused.

So, currently I have a function SendAwaitUrb that builds the irp with
IoBuildXx. I do not register a completion routine but just wait on an
event that is set by the lower driver when the request is complete.
I then just return from the SendAwaitUrb function with the lower drivers
status from the IoStatusBlock (registered in the call to IoBuildXx).
I do not do anything with the irp, it is not completed or freed. This
appears to be the same technique as used in many ddk sample drivers - in
those cases I do not see how the irps are completed or freed!?

This currently works with no problem. However I am concerned that I am
allocating lots of irps that are never freed as they are allocated in a
thread that belongs to my driver. They will ultimately only be freed
when my driver thread is terminated.

Are you suggesting that I MUST make a completion routine in order to
complete the irp
OR
Can I just call IoCompleteRequest after the event is signaled and the
KeWaitXx has returned.

Either way I should take care of these irps, right?

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 3:31 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

You are confusing yourself. When you build an irp with IoBuildXxx, you
can complete it in three ways

  1. return something != STATUS_MORE_PROCESSING_REQUIRED in your
    completion routine
  2. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and
    explicitly call IoCompleteRequest in the completion routine
  3. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and
    explicitly call IoCompleteRequest somewhere outside of the completion
    routine

Don’t rely on thread termination to clean up the irp on your behalf,
especially when you are in an arbitrary thread context like the pnp
start irp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 9, 2012 2:52 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

Thanks for your answer Doron.

So, on further inspection I found that my function SendAwaitUrb that
calls IoBuildDev… can be called directly from my PNP dispatch
function. In this case the irp from IoBuildDev… is created in the
context of the PNP request and so will be freed when IoCompleteRequest
is called for the original irp as long as this is not completed with
STATUS_MORE_PROCESSING_REQUIRED.

However when this function is called from my driver allocated thread I
need to explicitly complete the allocated irp with IoCompleteRequest
which will then free the irp.

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 09, 2012 1:51 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

So I do need to complete the request, and according to the documentation
for IoBuildDeviceIoControlRequest IoCompleteRequest is the way to do it
as this will free the irp.
Thanks,
Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 1:34 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Correct, but for IoBuildXxx generated irps, you need to complete the
request back to the io manager so the irp can be freed. This is unlike
IoAllocateIrp created IRPs which must never be completed back to the io
manager to be freed, your driver must free them with IoFreeIrp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bill Wandel
Sent: Thursday, August 9, 2012 1:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest
and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the
stack. I wait on an event for the completion of the IRP. This is
called in the context of a driver allocated thread that comes into
existance when the driver is loaded and terminates when the driver is
unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the
IRP 's created by IoBuildDeviceIoControlRequest must be completed by a
driver’s call to IoCompleteRequest, this is when the I/O manager frees
the IRP. It also states that when the thread exits the I/O manager
cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest.
So in these cases the driver writer is deffering the freeing of the IRP
to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded
so there could be 1000’s of IRP’s hanging around that are not getting
freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

You are fine. By not setting a completion routine at all, when the lower driver completes the request the completed request completes back to the io manager immediately, thus freeing the irp.

d

debt from my phone


From: Hayden Smith
Sent: 8/9/2012 4:23 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest and IoCompleteRequest

Yes, I think I am confused.

So, currently I have a function SendAwaitUrb that builds the irp with
IoBuildXx. I do not register a completion routine but just wait on an
event that is set by the lower driver when the request is complete.
I then just return from the SendAwaitUrb function with the lower drivers
status from the IoStatusBlock (registered in the call to IoBuildXx).
I do not do anything with the irp, it is not completed or freed. This
appears to be the same technique as used in many ddk sample drivers - in
those cases I do not see how the irps are completed or freed!?

This currently works with no problem. However I am concerned that I am
allocating lots of irps that are never freed as they are allocated in a
thread that belongs to my driver. They will ultimately only be freed
when my driver thread is terminated.

Are you suggesting that I MUST make a completion routine in order to
complete the irp
OR
Can I just call IoCompleteRequest after the event is signaled and the
KeWaitXx has returned.

Either way I should take care of these irps, right?

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 3:31 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

You are confusing yourself. When you build an irp with IoBuildXxx, you
can complete it in three ways

  1. return something != STATUS_MORE_PROCESSING_REQUIRED in your
    completion routine
  2. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and
    explicitly call IoCompleteRequest in the completion routine
  3. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and
    explicitly call IoCompleteRequest somewhere outside of the completion
    routine

Don’t rely on thread termination to clean up the irp on your behalf,
especially when you are in an arbitrary thread context like the pnp
start irp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 9, 2012 2:52 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

Thanks for your answer Doron.

So, on further inspection I found that my function SendAwaitUrb that
calls IoBuildDev… can be called directly from my PNP dispatch
function. In this case the irp from IoBuildDev… is created in the
context of the PNP request and so will be freed when IoCompleteRequest
is called for the original irp as long as this is not completed with
STATUS_MORE_PROCESSING_REQUIRED.

However when this function is called from my driver allocated thread I
need to explicitly complete the allocated irp with IoCompleteRequest
which will then free the irp.

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 09, 2012 1:51 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

So I do need to complete the request, and according to the documentation
for IoBuildDeviceIoControlRequest IoCompleteRequest is the way to do it
as this will free the irp.
Thanks,
Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 1:34 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Correct, but for IoBuildXxx generated irps, you need to complete the
request back to the io manager so the irp can be freed. This is unlike
IoAllocateIrp created IRPs which must never be completed back to the io
manager to be freed, your driver must free them with IoFreeIrp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bill Wandel
Sent: Thursday, August 9, 2012 1:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest
and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the
stack. I wait on an event for the completion of the IRP. This is
called in the context of a driver allocated thread that comes into
existance when the driver is loaded and terminates when the driver is
unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the
IRP 's created by IoBuildDeviceIoControlRequest must be completed by a
driver’s call to IoCompleteRequest, this is when the I/O manager frees
the IRP. It also states that when the thread exits the I/O manager
cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest.
So in these cases the driver writer is deffering the freeing of the IRP
to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded
so there could be 1000’s of IRP’s hanging around that are not getting
freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

> I noticed that all the samples in the DDK do not call IoCompleteRequest.

Driver below you will complete the IRP.

IRP’s hanging around that are not getting freed.

No.

You do not retain the IRP created this way. You create an accompanying event and pass it to IoBuildXxx.

After IoBuildXxx, you must do IoCallDriver sooner or later, better sooner.

After IoCallDriver, you must wait on the accompanying event, when it is signaled, the IRP is gone.

That’s why I dislike threaded IRPs and use IoAllocateIrp instead :slight_smile:


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

> Sorry, not sure I understand your question. I do not call IoCompleteRequest for this irp. How I complete the original irp that is passed to my driver is not relevant to the irp that I allocated inside my driver allocated thread, right?

Correct.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

>function. In this case the irp from IoBuildDev… is created in the

context of the PNP request

To avoid this mess, switch to IoAllocateIrp/IoBuildAsynchronousFsdRequest. Both create non-threaded IRPs. Probably you will be able to eliminate the worker thread in this case.

Note that, in PnP START path, you can only send URBs after START was processed by the stack below.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

As far as I know, the ONLY things that will be deallocated when a thread
terminates are the kernel thread control block and its stack. Whether in
user space or kernel space, there is no concept of a thread owning or
being responsible for any other allocations. You must free things up
yourself, or rely on behavior that passes the responsibility to some other
component. This is why, for example, you must never, ever call ExitThread
(or its numerous aliases) in a C++ program. Local objects that rely on
destuctors to maintain integrity of the environment will not be callled.
For example, std::vector has an associated heap-allocated block of memory.
If the thread exits in any fashion OTHER than returning from the
top-level thread function (which means all destructors have been properly
executed) then you have a storage leak. Note that this is also true for C
code, where it is not uncommon to allocate something as the thread starts
and deallocate it at the end, the classic example being

UINT threadfunc(LPVOID p)
{
MyThreadState * state = malloc(sizeofMyThreadState);
DoThreadStuff(state, p);
free(state);
return 0;
}

Whenever I get a program from a client, I run a little awk script against
it, looking for troublespots. All thread exit functions are in the list,
and invariably I find that if executed, they will leave the state
corrupted in one or more ways. In application space, it is also critical
to close the thread handle, because you will leak stacks in the app and
thread control blocks in the kernel, and potentially run out of handle
quota.
joe

You are fine. By not setting a completion routine at all, when the lower
driver completes the request the completed request completes back to the
io manager immediately, thus freeing the irp.

d

debt from my phone


From: Hayden Smith
Sent: 8/9/2012 4:23 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Yes, I think I am confused.

So, currently I have a function SendAwaitUrb that builds the irp with
IoBuildXx. I do not register a completion routine but just wait on an
event that is set by the lower driver when the request is complete.
I then just return from the SendAwaitUrb function with the lower drivers
status from the IoStatusBlock (registered in the call to IoBuildXx).
I do not do anything with the irp, it is not completed or freed. This
appears to be the same technique as used in many ddk sample drivers - in
those cases I do not see how the irps are completed or freed!?

This currently works with no problem. However I am concerned that I am
allocating lots of irps that are never freed as they are allocated in a
thread that belongs to my driver. They will ultimately only be freed
when my driver thread is terminated.

Are you suggesting that I MUST make a completion routine in order to
complete the irp
OR
Can I just call IoCompleteRequest after the event is signaled and the
KeWaitXx has returned.

Either way I should take care of these irps, right?

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 3:31 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

You are confusing yourself. When you build an irp with IoBuildXxx, you
can complete it in three ways

  1. return something != STATUS_MORE_PROCESSING_REQUIRED in your
    completion routine
  2. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and
    explicitly call IoCompleteRequest in the completion routine
  3. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and
    explicitly call IoCompleteRequest somewhere outside of the completion
    routine

Don’t rely on thread termination to clean up the irp on your behalf,
especially when you are in an arbitrary thread context like the pnp
start irp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 9, 2012 2:52 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

Thanks for your answer Doron.

So, on further inspection I found that my function SendAwaitUrb that
calls IoBuildDev… can be called directly from my PNP dispatch
function. In this case the irp from IoBuildDev… is created in the
context of the PNP request and so will be freed when IoCompleteRequest
is called for the original irp as long as this is not completed with
STATUS_MORE_PROCESSING_REQUIRED.

However when this function is called from my driver allocated thread I
need to explicitly complete the allocated irp with IoCompleteRequest
which will then free the irp.

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 09, 2012 1:51 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

So I do need to complete the request, and according to the documentation
for IoBuildDeviceIoControlRequest IoCompleteRequest is the way to do it
as this will free the irp.
Thanks,
Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 1:34 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Correct, but for IoBuildXxx generated irps, you need to complete the
request back to the io manager so the irp can be freed. This is unlike
IoAllocateIrp created IRPs which must never be completed back to the io
manager to be freed, your driver must free them with IoFreeIrp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bill Wandel
Sent: Thursday, August 9, 2012 1:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest
and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the
stack. I wait on an event for the completion of the IRP. This is
called in the context of a driver allocated thread that comes into
existance when the driver is loaded and terminates when the driver is
unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the
IRP 's created by IoBuildDeviceIoControlRequest must be completed by a
driver’s call to IoCompleteRequest, this is when the I/O manager frees
the IRP. It also states that when the thread exits the I/O manager
cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest.
So in these cases the driver writer is deffering the freeing of the IRP
to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded
so there could be 1000’s of IRP’s hanging around that are not getting
freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

Sorry, I missed part of this question. When a thread terminates, all
pending I/O is cancelled. Note that cancelling an IRP is NOT the same as
freeing it, although in a properly-written driver the cancellation
eventually leads to an IoCompleteRequest with IoStatus.Status =
STATUS_CANCELLED. If you are not using KMDF, you are responsible for
causing this to happen. I believe the default behavior of KMDF will
handle this for queued IRPs, but if you have an active IRP which has
initiated a transaction on the device, and is waiting for an interrupt,
but that device has extremely long or potentially unbounded response time,
then you are additionally responsible for doing whatever it takes to abort
that transfer, and this may e nontrivial, and depends on what must be done
to your device (for example, if it is a DMA transfer, you have to have a
way to stop the transfer, because when you complete the IRP those page
frames whose physicalmaddresses were loaded into the DMA control registers
may be reallocated for another purpose and you don’t want the DMA to
overwrite them. Devices with unbounded response times are miserable to
write drivers for.
joe

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the
stack. I wait on an event for the completion of the IRP. This is called
in the context of a driver allocated thread that comes into existance when
the driver is loaded and terminates when the driver is unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the
IRP 's created by IoBuildDeviceIoControlRequest must be completed by a
driver’s call to IoCompleteRequest, this is when the I/O manager frees the
IRP. It also states that when the thread exits the I/O manager cancels
the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest.
So in these cases the driver writer is deffering the freeing of the IRP to
the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded so
there could be 1000’s of IRP’s hanging around that are not getting freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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

Got it. Thanks.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 6:19 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

You are fine. By not setting a completion routine at all, when the lower
driver completes the request the completed request completes back to the
io manager immediately, thus freeing the irp.

d

debt from my phone


From: Hayden Smith
Sent: 8/9/2012 4:23 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Yes, I think I am confused.

So, currently I have a function SendAwaitUrb that builds the irp with
IoBuildXx. I do not register a completion routine but just wait on an
event that is set by the lower driver when the request is complete.
I then just return from the SendAwaitUrb function with the lower drivers
status from the IoStatusBlock (registered in the call to IoBuildXx).
I do not do anything with the irp, it is not completed or freed. This
appears to be the same technique as used in many ddk sample drivers - in
those cases I do not see how the irps are completed or freed!?

This currently works with no problem. However I am concerned that I am
allocating lots of irps that are never freed as they are allocated in a
thread that belongs to my driver. They will ultimately only be freed
when my driver thread is terminated.

Are you suggesting that I MUST make a completion routine in order to
complete the irp
OR
Can I just call IoCompleteRequest after the event is signaled and the
KeWaitXx has returned.

Either way I should take care of these irps, right?

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 3:31 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

You are confusing yourself. When you build an irp with IoBuildXxx, you
can complete it in three ways

  1. return something != STATUS_MORE_PROCESSING_REQUIRED in your
    completion routine
  2. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and
    explicitly call IoCompleteRequest in the completion routine
  3. return STATUS_MORE_PROCESSING_REQUIRED in your completion routine and
    explicitly call IoCompleteRequest somewhere outside of the completion
    routine

Don’t rely on thread termination to clean up the irp on your behalf,
especially when you are in an arbitrary thread context like the pnp
start irp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 9, 2012 2:52 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Hi,

Thanks for your answer Doron.

So, on further inspection I found that my function SendAwaitUrb that
calls IoBuildDev… can be called directly from my PNP dispatch
function. In this case the irp from IoBuildDev… is created in the
context of the PNP request and so will be freed when IoCompleteRequest
is called for the original irp as long as this is not completed with
STATUS_MORE_PROCESSING_REQUIRED.

However when this function is called from my driver allocated thread I
need to explicitly complete the allocated irp with IoCompleteRequest
which will then free the irp.

Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hayden Smith
Sent: Thursday, August 09, 2012 1:51 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

So I do need to complete the request, and according to the documentation
for IoBuildDeviceIoControlRequest IoCompleteRequest is the way to do it
as this will free the irp.
Thanks,
Hayden

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, August 09, 2012 1:34 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

Correct, but for IoBuildXxx generated irps, you need to complete the
request back to the io manager so the irp can be freed. This is unlike
IoAllocateIrp created IRPs which must never be completed back to the io
manager to be freed, your driver must free them with IoFreeIrp

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bill Wandel
Sent: Thursday, August 9, 2012 1:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Basic question regarding
IoBuildDeviceIoControlRequest and IoCompleteRequest

The driver that you send the IRP to completes the request.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@lasercard.com
Sent: Thursday, August 09, 2012 4:19 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Basic question regarding IoBuildDeviceIoControlRequest
and IoCompleteRequest

Hi,

In my driver I use IoBuildDeviceIoControlRequest to send a URB down the
stack. I wait on an event for the completion of the IRP. This is
called in the context of a driver allocated thread that comes into
existance when the driver is loaded and terminates when the driver is
unloaded.

Now the documentation for IoBuildDeviceIoControlRequest states that the
IRP 's created by IoBuildDeviceIoControlRequest must be completed by a
driver’s call to IoCompleteRequest, this is when the I/O manager frees
the IRP. It also states that when the thread exits the I/O manager
cancels the IRP.

I noticed that all the samples in the DDK do not call IoCompleteRequest.
So in these cases the driver writer is deffering the freeing of the IRP
to the time the thread is terminated? Correct?

For my driver the thread is not terminated until the driver is unloaded
so there could be 1000’s of IRP’s hanging around that are not getting
freed.
Is this correct? Seems like this could be a big problem!
Should I be calling IoCompleteRequest?

Thanks,
Hayden


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

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