Calling Support Routines That Use Spin Locks

Calling KeAcquireSpinLock or KeAcquireInStackQueuedSpinLock sets the IRQL on the current processor to DISPATCH_LEVEL until a corresponding call to KeReleaseSpinLock or KeReleaseInStackQueuedSpinLock restores the previous IRQL. Consequently, drivers must be executing at IRQL <= DISPATCH_LEVEL when they call KeAcquireSpinLock or KeAcquireInStackQueuedSpinLock.

Callers of KeAcquireSpinLockAtDpcLevel, KeAcquireInStackQueuedSpinLockAtDpcLevel, KeReleaseInStackQueuedSpinLockFromDpcLevel, and KeReleaseSpinLockFromDpcLevel run faster because they are already running at IRQL = DISPATCH_LEVEL so these support routines need not reset IRQL on the current processor. Consequently, it is a fatal error on most Windows platforms to call KeAcquireSpinLockAtDpcLevel or KeAcquireInStackQueuedSpinLockAtDpcLevel while running at IRQL less than DISPATCH_LEVEL. It is also an error to release a spin lock that was acquired with KeAcquireSpinLock by calling KeReleaseSpinLockFromDpcLevel because the caller's original IRQL is not restored.

Routines that hold an executive spin lock, such as the ExInterlocked*Xxx, usually execute at IRQL = DISPATCH_LEVEL until they release the spin lock and return control to the caller. However, it is possible for a driver's [InterruptService]( routine and [SynchCritSection]( routines (which run at DIRQL) to call certain **ExInterlockedXxx*** routines, such as the ExInterlockedXxxList routines, as long as the spin lock passed to the routine is used exclusively by the ISR and SynchCritSection routines.

Each routine that holds an interrupt spin lock executes at the DIRQL of an associated set of interrupt objects. Therefore, a driver must not call KeAcquireSpinLock and KeReleaseSpinLock nor any other routine that uses an executive spin lock from its ISR or SynchCritSection routines. Such a call is an error that can cause a system deadlock, requiring the user to reboot his or her machine. Note that if a driver's ISR or SynchCritSection routine calls an ExInterlockedXxxList routine, the driver cannot reuse the spin lock it passes to the ExInterlockedXxxList routines in calls to the KeXxxSpinLock or KeXxxSpinLockXxxDpcLevel support routines.

If a driver has a multivector ISR or more than one ISR, its routines can call KeSynchronizeExecution while executing at any IRQL up to the SynchronizeIrql value specified for the associated interrupt objects when they were connected.

Send comments about this topic to Microsoft