Best Practices for Managing Thread Context and IRQL in KMDF Drivers

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, ...

Get Developing Drivers with the Windows® Driver Foundation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.