| Framework Aims to Increase Driver Reliability |
| May 9, 2005 |
|
A forthcoming set of APIs aims to reduce the amount of boilerplate code Windows developers must write and increase device driver reliability. The new Windows Driver Foundation (WDF) APIs offer improvements to the current kernel-mode drivers and enable some drivers to run in user mode, isolating the OS from errant drivers. However, at its Apr. 2005 Windows Hardware Engineering Conference (WinHEC), Microsoft reiterated that while the API improvements for kernel-mode drivers will be supported on Windows 2000 and later, its current plans support only user-mode drivers on the next version of Windows (code-named Longhorn). Existing Model Fragile, Hard to Program Current Windows device drivers are built on a set of APIs known as the Windows Driver Model (WDM), a complex API that is error-prone and requires developers to include hundreds, and in some cases thousands, of lines of boilerplate code to support OS features such as advanced power management and Plug and Play. To help developers build drivers, Microsoft has over the years introduced a number of device-specific APIs known as "miniports." Each miniport offers its own API tailored for a specific class of devices, such as network cards and storage devices. However, as new features were added to the base OS, they appeared as different APIs in the various miniports. Further complicating matters is the move toward multifunction devices, such as a music player that also functions as a mass storage device. It's difficult to create drivers for such devices because the miniport APIs were not designed with multifunction devices in mind. In addition to making things difficult for device manufacturers, the WDM also makes it more difficult for Microsoft to evolve Windows. The WDM APIs provide direct access to many low-level OS data structures, making it impossible for Microsoft to modify those structures without breaking compatibility with existing device drivers and forcing Microsoft's developers to resort to ever more complex workarounds. Windows Driver Foundation Aims to Simplify The WDF, which was announced in 2004 and is currently in beta testing, aims to simplify the existing driver model by providing two frameworks that implement the bulk of the common code required of all device drivers: a kernel-mode framework for drivers that require direct access to hardware resources, such as processor interrupts and direct memory access, and a user-mode framework for drivers that simply perform input/output (I/O) operations. The kernel-mode framework provides the same basic features as the existing WDM and miniport drivers but significantly reduces the amount of code developers must write to support OS features such as power management and Plug and Play. In an example given by Microsoft, a typical network driver built on the old WDM required more than 13,000 lines of source code, nearly 8,000 of which were devoted to implementing power management and Plug and Play. The same driver written using the new WDF kernel-mode framework requires only 7,200 lines of code and fewer than 1,800 lines of power-management and Plug-and-Play code. By reducing the total lines of code developers must write, Microsoft hopes to increase the reliability of device drivers and therefore the reliability of Windows itself. Information gathered as part of the Windows Error Reporting system has shown that faulty device drivers are the leading cause of Windows "blue screen" crashes. User-Mode Drivers Isolated from OS The user-mode framework aims to further improve driver reliability but also imposes some restrictions. The key benefits provided by the user-mode framework are as follows: OS isolation. Because they run in user mode (like applications) rather than in kernel mode, user-mode drivers do not have direct access to memory belonging to the OS. Therefore, the OS is able to restart a user-mode driver that has crashed without affecting the overall stability of the OS. Option to use C++. Unlike kernel-mode drivers, which must be written in the C programming language, user-mode drivers can be written in either C or C++. C++ is a more modern language, provides additional error checking, and supports object-oriented programming. Better tool support. Unlike kernel-mode drivers, which must be debugged using specialized tools and are restricted to a limited set of API calls, user-mode drivers can be debugged using standard developer tools and have access to all Win32 APIs. User-Mode Drivers on Longhorn Only? Along with those benefits, however, come several restrictions that may reduce the appeal of user-mode drivers for many vendors. First, user-mode drivers are designed for protocol-based or serial-bus-based devices, such as portable storage devices and portable media players, and do not have access to low-level CPU resources, such as processor interrupts or direct memory access. Second, separating drivers from the OS would typically cause their performance to decrease. But for the kinds of devices that user-mode drivers are designed to support, the speed of the I/O channel (e.g., USB 1.1 vs. USB 2.0) has the greatest impact on performance. Therefore, Microsoft expects user-mode drivers to offer comparable performance to kernel-mode drivers. But the biggest limitation is that Microsoft's current plans call for supporting user-mode drivers only on Longhorn. The company said at WinHEC that it is investigating support for user-mode drivers on Windows XP. Even with Windows XP support, hardware vendors with significant numbers of corporate customers (a large number of which are still running Windows 2000) are unlikely to go to the extra effort to write user-mode drivers, since they would have to create a kernel-mode driver as well anyway. Resources An introduction to WDF can be found at www.microsoft.com/whdc/driver/wdf/wdf-intro.mspx. More details on the user-mode framework are at download.microsoft.com/download/5/D/6/5D6EAF2B-7DDF-476B-93DC-7CF0072878E6/UMDF_Intro.doc. Documentation for both the user- and kernel-mode frameworks is available at download.microsoft.com/download/5/d/6/5d6eaf2b-7ddf-476b-93dc-7cf0072878e6/KMDF.exe and download.microsoft.com/download/5/d/6/5d6eaf2b-7ddf-476b-93dc-7cf0072878e6/UMDF.exe. |