The Windows Driver Model (WDM)

The Windows Driver Model (WDM) is the foundational driver architecture for Windows operating systems. It provides a standardized framework for developing device drivers, ensuring compatibility and stability across various hardware components.

Core Concepts

WDM is built around several key concepts:

Driver Stacks

WDM drivers are organized in a hierarchical structure called a device stack. Each device object in the stack represents a layer of functionality. A typical stack might include:

  1. Bus Driver: Handles the bus itself (e.g., PCI, USB).
  2. Filter Driver (optional): Intercepts or modifies I/O.
  3. Function Driver: Provides the primary functionality for the device.
  4. Lower Filter Driver (optional): Further filtering.
  5. Raw PDO (optional): For devices that don't fit the standard model.

I/O requests (IRPs) travel down the stack to the function driver and then potentially back up, allowing each layer to process the request.

IRP Processing

Drivers process IRPs by implementing specific dispatch routines. When an IRP arrives for a particular I/O function (e.g., IRP_MJ_READ, IRP_MJ_WRITE), the system calls the corresponding dispatch routine in the driver.


// Example of a dispatch routine signature
NTSTATUS DriverDispatchRead(
    PDEVICE_OBJECT DeviceObject,
    PIRP Irp
) {
    // Process the read request
    // ...
    return STATUS_SUCCESS;
}
            

Drivers can complete an IRP, pass it down to the next driver in the stack, or return it to the system.

Key WDM Components

Understanding the Driver Stack

The hierarchical nature of the driver stack is crucial for modularity and extensibility. It allows for independent development and debugging of different driver layers.

Evolution to WDF

While WDM is the foundation, Microsoft has introduced the Windows Driver Frameworks (WDF), which includes Kernel-Mode Driver Framework (KMDF) and User-Mode Driver Framework (UMDF). WDF simplifies driver development by abstracting many of the complexities of WDM, offering a more object-oriented approach.

Migrating to WDF

For new driver development, it is highly recommended to use WDF (KMDF or UMDF) as it significantly reduces development effort and improves driver quality compared to direct WDM programming.

This section provides a high-level overview of the Windows Driver Model. For detailed information on specific components and programming interfaces, please refer to the API Reference and related documentation.