Have you ever written a hardware driver? Here's a few common
errors, and how to avoid them.According to Microsoft, these are the biggest bloopers driver
developers make, along with how Windows Driver Foundation (WDF)
helps prevent them:
Drivers typically make mistakes in:
- Handling IRPs for asynchronous I/Os. (Not setting IoMarkIrpPending while pending an IRP)
- Bugs in their cancellation logic. (Not clearing the cancel routine before completing a request)
- Synchronizing their I/O request flow with the PNP/PM requests. (Freezing, thawing queues etc.)
WDF solves these issues, says Microsoft, by providing higher levels of abstractions. Queues for asynchronous I/O with built-in
cancellation and a complete PNP state machine are integrated with
the queues. This means the hard aspects of handling requests,
pending them on PNP state changes or canceling the requests in the
queue are implemented by Microsoft code and the driver developer
does not need to worry about them.
Another area where driver developers commonly make errors is in synchronizing DPC/ISRs with their dispatch routines. WDF provides built-in locking to solve this problem, according to Microsoft.