2018/03/16

Windows Blue Screen: ATTEMPTED_SWITCH_FROM_DPC

While debugging my windows driver, I got a blue screen with error code ATTEMPTED_SWITCH_FROM_DPC,

MS doc says one cannot wait in a DPC:

A wait operation, attach process, or yield was attempted from a DPC routine. This is an illegal operation.

https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/bug-check-0xb8--attempted-switch-from-dpc

I think it relates to locking a resource with WdfWaitLockAcquire(), which is called in a completion function of a IO request.

MS doc says:

If the driver services the I/O request by creating I/O activity on the device, the driver typically calls WdfRequestComplete from its EvtInterruptDpc or EvtDpcFunc callback function.

https://docs.microsoft.com/en-us/windows-hardware/drivers/wdf/completing-i-o-requests

So the completion function could be called in the DPC context. 


I can use spin lock though:

On the other hand, they can acquire and release a driver's executive spin lock with KeAcquireSpinLockAtDpcLevel and KeReleaseSpinLockFromDpcLevel, which run faster than KeAcquireSpinLock and KeReleaseSpinLock.

https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/guidelines-for-writing-dpc-routines

No comments:

Post a Comment

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...