I am new to Windows device driver programming. I know that certain operations can only be performed in IRQL PASSIVE_LEVEL. For example, Microsoft has this sample code for writing to a file from the kernel driver:
if (KeGetCurrentIrql() != PASSIVE_LEVEL)
return STATUS_INVALID_DEVICE_STATE;
Status = ZwCreateFile(...);
My question is: what prevents IRQL from rising after checking KeGetCurrentIrql()above? Let's say a context or swithch flow arises, can IRQL suddenly become DISPATCH_LEVELwhen it returns to my driver, which then leads to a system crash?
If this is NOT possible, then why not just check the IRQL in the function DriverEntryand do it once for everyone?
source
share