To avoid problems related to thread context and IRQL, adopt these practices:
Unless you are certain that a driver function is called in a particular thread context, never make any assumptions about the contents of the user-mode address space.
Know which driver functions can be called at IRQL>=DISPATCH_LEVEL and understand the restrictions that running at this level places on driver code.
Store any data that can be accessed at IRQL>=DISPATCH_LEVEL in nonpaged memory.
Possible locations are the device object context area, a driver-allocated space in nonpaged pool memory, or the kernel-mode stack.
Use Driver Verifier, the PAGED_CODE and PAGED_CODE_LOCKED macros, SDV, PREfast for Drivers, and debugger extensions to help find IRQL-related bugs in drivers.
Test drivers on as many hardware configurations as possible, including multiprocessor systems.