Understanding Windows Drivers and Kernel internals.

Understanding Windows OS internals and writing Device Driver can be a daunting task. In this blog I have tried to capture the essentials required to get up to speed on developing a Windows driver.

My effort here has been to bring together information from a number of resources I follow and present them on a common platform. The blog provides basic information required to understand the Windows Driver and begin with the process of driver development. Hopefully, driver writers and other enthusiasts who have just ventured out it in this field may find the blog useful.

I have categorized all the topics I have planned to cover in two Major sections or Parts:

Part 1: Windows Driver Fundamentals.

In this part, the topics covered are fundamental to Windows Driver and forms its core architecture. It is applicable to both WDM or WDF based driver.

Overview of WDM or WDF framework for driver is also introduced for having an understanding of what they actually mean. WDF Framework will be covered in depth in next parts.

Part 2: WDF Framework overview.

Once we have understanding of the Driver Fundamentals in Windows OS, we will cover WDF Framework. My plan is to mainly stick to KMDF based driver, since I have worked mainly on it. But subsequently, when I have worked more on UMDF based driver, I will be introducing it as part here.

Part 3: Driver Structure and Initialization: Building and Installation.

Now, that we have understanding of the Driver fundamentals and KMDF driver framework, I will introduce to the build environment and coding for the Drivers. We will see some basic drivers to cover all the concepts I have labelled.

Part 4: Smart Car Project.

Finally complete this introductory session to windows Driver with a project. Smart Car is a robotics project which will be able to do complete some basic Manoeuvring like line following or path following etc.

So moving on, these sections are organized as follows:

Part 1: Windows Driver Fundamental.

  1. Introduction: Windows Driver and its History.

    What is a Device Driver ?

    How is Device Driver implemented in Windows OS and the high level view of the Windows Driver Architecture.

    History gives a good perspective of how we reached here. This especially holds true in case of Windows. From the old days of DOS where the kernel was a free land and developers wrote their own hardware drivers in real-mode assembly code, conforming to no specific standard or interface to the highly structured, object oriented and event driven WDF driver model, Windows driver architecture has definitely come a long way.

  2. Windows Driver Architecture

    This and subsequent topics will discuss some important things regarding architecture of Windows OS and its fundamentals.

    Some topics discussed are :

    • Core Windows Driver Architecture. 
    • Device And Driver Layering: Device Objects and Device Stack. 
    • Kinds of Devices: PnP Devices and Legacy Devices. 
    • How the system Finds and Loads Drivers: Recursive Enumeration and Device Tree. 
     
  3. WDM and WDF Framework

    This topic is covered in detail in next Parts. This chapter is only be an introduction to these 2 driver models that can be followed to build Drivers for Windows OS.

    Going forward it is good to have an understanding of these Framework. In this topic we will cover Overview of the WDM and the Framework.

  4. Windows I/O Model.

    This topic will cover how data is communicated between Driver Layers.

    Data is represented as Request Packets or I/O Request Packets. IRPs are not just for data transfer but do much more. Its communication mechanism adopted by Windows to communicate between different components of Windows Driver Architecture.

  5. Memory Management for Windows Drivers

    Drivers allocate memory for purposes such as storing internal data, buffering data during I/O operations and sharing memory with other kernel-mode and user-mode components.

    Understanding the memory management techniques used by Windows is important for a driver writer because this affects the decisions regarding the scheduling and synchronization.

    This topic provides information about allocating and using memory in kernel-mode drivers. It describes the types of memory that are available for driver use, the appropriate techniques for allocating and using each type.

  6. Scheduling, Thread Context and IRQL

    Windows is a multitasking operating system that can run in symmetric multiprocessor environment. The driver code executes in the context of one thread or the other.

    This topic presents information about thread scheduling, thread context and processor's current interrupt request level (IRQL).

  7. Locks, Deadlocks and Synchronization.

    This topic discusses the synchronization mechanisms available to driver writer to protect shared memory locations in kernel-mode drivers for Windows. This will help us to determine when synchronization is required and how each type of available synchronization mechanism is used.

  8. User-mode Interactions.

    Many kernel-mode drivers must interact with user-mode components by sharing data, objects and handles; passing notification and synchronization information; and using settings and properties supplied by a user.

    We finally conclude this Part-1 of the introductory section to Windows Drivers with discussing about various techniques with which Drivers and Applications can interact.

Once we have completed the Part-1, we should have an understanding of the Windows Driver Architecture and its fundamentals.

Now, we are ready to learn and understand about the framework which provides us the driver model for many device types.

We are going to mainly discuss about the Kernel-Mode Driver Framework (KMDF), which is used for developing the kernel-mode drivers.

I will update more about the upcoming parts with end of earlier parts.

References:

Windows Driver Foundation resource on MSDN.

Windows Internals by by Russinovich, Solomon, and Ionescu (6th Edition).

Programming the Microsoft Windows Driver Model by Walter Oney (2nd Edition)

Developing Drivers with the Windows Driver Foundation by Penny Orwick and Guy Smith.

- Windows Programming/Device Driver Introduction WikiBooks.

Wikipedia on History of Microsoft Windows.

OSR Online site which is a must visit for every Windows Driver Developer and has everything related to writing, testing and maintaining Windows Drivers. 

No comments:

Post a Comment