concurrency of DPC and Unload routines

Is it possible for the system to call a driver’s Unload routine
when there is a queued DPC or when a DPC routine is being executed?

I’m trying to make my driver multi-processor safe, and would like
to safeguard against the following scenario:

The driver is running on two processors. Processor 1 dequeues
a DPC and begins executing the associated DPC routine. At the same
time Processor 2 begins executing a Unload call from the system,
requesting that
all resources be released or that the driver be unloaded. Processor 1
then receives
an external interrupt which interrupts the execution of the DPC routine.

Before releasing the resources, the Unload routine calls KeRemoveQueueDpc
to
ensure that all queued DPCs are kept from starting, then releases all
driver resources.
However, this call apparently does not affect the DPC and its routine
that Processor 1
has already started executing. Processor 1 completes the handling of the
external interrupt,
then resumes executing the DPC routine and attempts to use a resource
that has already
been released by the Unload call. Is there a potential race condition or
blue sceen here?

Thanks for any information and insights.
Chris


YOU’RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there’s no risk! For your FREE software, visit:
http://dl.www.juno.com/get/tagj.

From: “Christopher Marcos”
Sent: Wednesday, August 16, 2000 3:33 PM

> Is it possible for the system to call a driver’s Unload routine
> when there is a queued DPC or when a DPC routine is being executed?

[snip]

Absolutely. Consider a multi-processor system in which your driver has just
queued a DPC to CPU 1, whilst the system is simultaneously unloading the
driver via a thread running on CPU 2. The DPC and unloading might literaly
take place at the same time and this will surely lead to nothing good.

There is no built-in protection for this sort of situation – you must take
it into account yourself. However, in a Plug and Play driver, this
shouldn’t be much of an issue, since the system won’t unload a driver until
all of its devices have processed IRP_MN_REMOVE_DEVICE. At that point, all
interrupt and DPC activity should have long ceased.

Is your driver Plug and Play?

- Matt