Sigh.
When process teardown proceeds, it is because the LAST thread in the
process exits (threads always self-terminate, last thread in the process
tears down the process).
What is more likely is that a thread in the process is blocked and not
terminating because it has waited with APCs disabled.
When the last thread terminates (that is, the last thread calls
PspExitThread) it will walk the handle table for the process and close
all of the handles in the table. Hence, my point - if you don’t see the
IRP_MJ_CLEANUP it is because the last thread isn’t terminating. Use the
debugger to check the process and the thread; if you have one thread
remaining, check to see if it has pending APCs (“!apc” in the debugger)
and if it does, then look at the wait IRQL and the APC disable bits ("dt
nt!_KTHREAD
"). If it really IS blocking the
APC delivery, you'll need to figure out why - either a raise to IRQL
APC_LEVEL or the use of a guarded mutex (W2K3 only) will cause this.
I've used the IRP_MJ_CLEANUP technique numerous times - and it is VASTLY
easier than using the cancellation technique in IRPs.
Regards,
Tony
Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Stephen Williams
Sent: Wednesday, June 29, 2005 8:01 PM
To: ntdev redirect
Subject: Re:[ntdev] IRP_MJ_CLEANUP is not called
The IRP_MJ_CLEANUP documentation says:
"Receipt of this request indicates that the last handle for a
file object that is associated with the target device object has
been closed (but, due to outstanding I/O requests, might not have
been released)."
What do the "outstanding I/O requests" refer to? A little further
along, it says:
"..., the driver must cancel and complete only the currently queued
IRPs that are associated with the file object handle that is being
released."
How can this function "cancel and complete" any IRPs if the IRPs
must be cancelled and completed before this function will run? I
simply don't get it. And under the title "Writing Dispatch Routines"
and "DispatchCleanup Routines" it says a driver's DispatchCleanup
routine should:"
* Cancel all IRPs that are currently queued to the target device
object, if they are associated iwth the file object that is
specified in the FileObject member of the driver's I/O stack
location.
But again, how can there *be* any queued IRPs, in *any* queue, if
they are cancelled by the O/S before the cleanup is called?
Color me brightly confused.
Doron Holan wrote:
> The cleanup irp is not waiting, it is the process cleanup code in
> general that is waiting. I bet if you look at the pended irp w/out
the
> cancel routine, Irp->Cancel is TRUE. The process cleanup code is
trying
> to complete all pending i/o by canceling it. If you need to process
the
> irp's completion at passive level, allocate a work item before you
pend
> the request and in the cancellation routine queue to a work item to
> finish the cancellation processing.
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Stephen
Williams
> Sent: Wednesday, June 29, 2005 3:04 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] IRP_MJ_CLEANUP is not called
>
>
> I must be doing something stupid, but I'm not getting a call
> to my IRP_MJ_CLEANUP dispatch routine.
>
> The setup is that the application issues an ioctl to pin down
> and map some memory for the device to scribble on. The driver
> leaves the IRP for that ioctl pending, so that the pages stay
> pinned.
>
> I have a cleanup routine that I want to use to detect that the
> application is killed, or closes the handle with the pending
> ioctl. I have no cancel routine for the IRP, I need to do some
> work in PASSIVE mode and hoped that the cleanup routine will
> allow me to cleanup pending IRPs.
>
> But it's not happening that way. I do not get a cleanup irp
> (and close of the handle hangs) if my map ioctl is pending.
> What is the cleanup irp waiting for?
--
Steve Williams "The woods are lovely, dark and deep.
steve at icarus.com But I have promises to keep,
http://www.icarus.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep."
---
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com