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. So, 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're already running at IRQL = DISPATCH_LEVEL so these support routines need not reset IRQL on the current processor. So, it's a fatal error on most Windows platforms to call KeAcquireSpinLockAtDpcLevel or KeAcquireInStackQueuedSpinLockAtDpcLevel while running at IRQL less than DISPATCH_LEVEL. It's also an error to release a spin lock that was acquired with KeAcquireSpinLock by calling KeReleaseSpinLockFromDpcLevel because the caller's original IRQL isn't restored.
Routines that hold an executive spin lock, such as the ExInterlockedXxx, usually execute at IRQL = DISPATCH_LEVEL until they release the spin lock and return control to the caller. However, it's 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 can't 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.