Compartilhar via


Driver Quality - Part 2

This is a continuation of the article I wrote here. This part focuses on the utilities that you can add to your toolbox which will help you ensure quality for drivers for which you do have source code access. Both of these tools are used during compile time of your driver and are available from the Windows Driver Kit Development kit. Please see the first article (link above) to find out how to procure the kit.

The first tool is PREfast for Drivers – which I’ll call PFD in this article. PFD is a compile-time static verification tool that analyzes your C or C++ code and looks for common basic coding errors that the compiler may have missed. This utility does not actually execute any code that it's validating but instead tries to detect come of the compile issues that the compiler itself may ignore and would probably be pretty difficult to debug. In addition – PFD has an additional module which is designed to detect errors in the kernel-mode driver code. If you’re interested in seeing one example of the tool’s output then here’s a MSDN sample for PFD called "Uninitialized Variables and NULL Pointers". If you want to read more about PFD then you can check out this link. PFD was designed to analyze 32-bit code written for either the x86 or the x86-64 architecture. (commonly called 'x64' – not to be confused with the IA64 architecture) I also recommend that you check out the PREfast Step-by-Step page here. Finally, I found that Channel 9 has done a video about PREfast for Drivers. One of the developers Donn Terry is interviewed on the topic of PFD and even provides some insight as to what benefits and differences (at a high level) between PREfast for Drivers and PREfast.

The second tool is Static Driver Verifier – which I’ll call SDV in this article. SDV takes a systematic approach to verifying the driver code to ensure that your driver code, which is written in C, doesn’t cause any interoperability issues with the Windows OS kernel. This utility will examine all code paths within the code and even has the ability to find errors in obscure code paths which may or may not be exercised even with through testing. SDV can validate File System Filter drivers as well as device drivers which are in compliance with the Windows Driver Model. (WDM) It can validate function drivers, filter drivers, and bus drivers in the x86 as well as the x86-64 environment. If you're interested in seeing one example of the tool's usage and output then you can check out this article titled "Verifying Fail_Driver1". If you want to read more about SDV you can visit this link.

So you may ask “Nick – what would you do?” Well – I would run both utilities if my code was written in C and if my code was written in C++ or managed code (.NET) then I would only use PFD. Yes – that’s right. You read that correctly. PFD can even verify drivers written in managed code! Also - if you're interested in the normal PREfast (the version used against your applications) then you can get it by purchasing Visual Studio 2005 Team Edition for Software Developers or Visual Studio 2005 Team Suite. For more information on either of those please see this link. (search for the words "Static Code Analyzer" to find where PREfast applies)

Ultimately it is up to you, the drivers’ developers and testers, to ensure that the drivers which are shipping on/in your company’s product are of the utmost quality. After it’s all said and done you definitely don’t want users to be greeted with a blue screen. *Grin*

Cheers!

- Nick