Writing SynchCritSection Routines
Drivers use their SynchCritSection routines for either of two basic purposes:
Programming a device for an I/O operation
Accessing shared state information
Like an ISR, a SynchCritSection routine must execute as quickly as possible, doing only what is necessary to set up device registers or update context data, before returning.
Because KeSynchronizeExecution holds a device driver's interrupt spin lock while its SynchCritSection routine runs, the driver's ISR cannot execute until the SynchCritSection routine returns control.
For any received IRP, a device driver should do as much I/O processing as possible either at IRQL PASSIVE_LEVEL in its dispatch routines (or possibly device-dedicated threads), or at IRQL DISPATCH_LEVEL in its StartIo routine and DPC routines.
For additional information about how critical sections are synchronized, see Using Spin Locks: An Example.