What if Unload routine releases a resource that DPC routine uses later?

I would like to have the driver, which has not yet been opened by any
application, enable interrupts on a board to detect for overheating.

Is it possible for the system, upon receiving a “net stop driver” command
from the user, to call a driver’s Unload routine when there is a queued
DPC or
when a DPC routine is being executed?

If it is possible, I don’t see any way to prevent a DPC routine
from using a resource, such as a synchronization object,
that may have already been released by a concurrent execution
of the Unload routine.

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
the driver’s DPC and begins executing the associated DPC routine.
At the same time Processor 2 begins executing the driver’s Unload call
from the system, requesting that all resources be released and 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, I don’t believe this call has any affect
on the DPC
whose routine 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 any way to prevent this from happening?

Thanks for any help.
Chris


GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today! For your FREE software, visit:
http://dl.www.juno.com/get/web/.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Before you enqueue the DPC, increment a global count of enqueued DPCs, perhaps using InterlockedIncrement
decrement this at the end of the DPC function. Have the unload routine poll this until its zero, having the thread sleep
for a short duration.

In addition, the unload routine should do something to prevent you from queuing more DPC…
-DH
----- Original Message -----
From: “Christopher Marcos”
To: “NT Developers Interest List”
Sent: Thursday, September 27, 2001 6:07 PM
Subject: [ntdev] What if Unload routine releases a resource that DPC routine uses later?

> I would like to have the driver, which has not yet been opened by any
> application, enable interrupts on a board to detect for overheating.
>
> Is it possible for the system, upon receiving a “net stop driver” command
> from the user, to call a driver’s Unload routine when there is a queued
> DPC or
> when a DPC routine is being executed?
>
> If it is possible, I don’t see any way to prevent a DPC routine
> from using a resource, such as a synchronization object,
> that may have already been released by a concurrent execution
> of the Unload routine.
>
> 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
> the driver’s DPC and begins executing the associated DPC routine.
> At the same time Processor 2 begins executing the driver’s Unload call
> from the system, requesting that all resources be released and 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, I don’t believe this call has any affect
> on the DPC
> whose routine 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 any way to prevent this from happening?
>
> Thanks for any help.
> Chris
>
> ________________________________________________________________
> GET INTERNET ACCESS FROM JUNO!
> Juno offers FREE or PREMIUM Internet access for less!
> Join Juno today! For your FREE software, visit:
> http://dl.www.juno.com/get/web/.
>
> —
> You are currently subscribed to ntdev as: xxxxx@syssoftsol.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com