Developing Drivers with the Windows® Driver Foundation

Total Page:16

File Type:pdf, Size:1020Kb

Developing Drivers with the Windows® Driver Foundation A01T623743.fm Page 1 Thursday, March 22, 2007 9:58 AM Developing Drivers with the Windows® Driver Foundation Penny Orwick Guy Smith PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2007 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Control Number: 2007922586 Printed and bound in the United States of America. 1 2 3 4 5 6 7 8 9 QWT 2 1 0 9 8 7 Distributed in Canada by H.B. Fenn and Company Ltd. A CIP catalogue record for this book is available from the British Library. Microsoft Press books are available through booksellers and distributors worldwide. For further infor- mation about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send comments to [email protected]. Microsoft, Microsoft Press, Excel, Internet Explorer, MSDN, MS-DOS, Outlook, SideShow, Visual Studio, Win32, Windows, Windows Media, Windows NT, Windows Server, Windows Vista, Xbox, and Xbox 360 are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. 7KLVERRNH[SUHVVHVWKHDXWKRU¶VYLHZVDQGRSLQLRQV7KHLQIRUPDWLRQFRQWDLQHGLQWKLVERRNLVSURYLGHG without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions Editor: Ben Ryan Developmental Editor: Devon Musgrave Project Editor: Denise Bankaitis Body Part No. X13-62472 A03C623743.fm Page iii Wednesday, March 21, 2007 7:56 PM Contents at a Glance Part 1 Getting Started with WDF 1 Introduction to WDF . 3 2 Windows Driver Fundamentals. 23 3 WDF Fundamentals. 51 Part 2 Exploring the Frameworks 4 Overview of the Driver Frameworks . 67 5 WDF Object Model . 91 6 Driver Structure and Initialization . 129 Part 3 Applying WDF Fundamentals 7 Plug and Play and Power Management . 165 8 I/O Flow and Dispatching . 223 9 I/O Targets . 307 10 Synchronization. 379 11 Driver Tracing and Diagnosability . 411 12 WDF Support Objects. 441 13 UMDF Driver Template. 475 Part 4 Additional Topics for KMDF Drivers 14 Beyond the Frameworks . 497 15 Scheduling, Thread Context, and IRQL . 507 16 Hardware Resources and Interrupts . 529 17 Direct Memory Access . 549 18 An Introduction to COM . 583 iii A03C623743.fm Page iv Wednesday, March 21, 2007 7:56 PM iv Table of Contents Part 5 Building, Installing, and Testing a WDF Driver 19 How to Build WDF Drivers. 617 20 How to Install WDF Drivers . 635 21 Tools for Testing WDF Drivers. 667 22 How to Debug WDF Drivers . 697 23 PREfast for Drivers . 731 24 Static Driver Verifier . 823 A04T623743.fm Page v Wednesday, March 21, 2007 7:58 PM Table of Contents Foreword. xxiii Acknowledgments . xxvii Part 1 Getting Started with WDF 1 Introduction to WDF . 3 About This Book . 4 Who Should Read This Book . 4 About Part 1: Getting Started with WDF . 5 About Part 2: Exploring the Frameworks. 6 About Part 3: Applying WDF Fundamentals . 6 About Part 4: Digging Deeper: More Topics for WDF Drivers . 8 About Part 5: Building, Installing, and Testing a WDF Driver . 9 Conventions Used in This Book. 10 Getting Started with Driver Development. 11 System Requirements for Driver Development. 12 How to Obtain and Install the WDK. 13 WDK Libraries. 14 WDK Documentation . 14 WDK Tools. 15 WDK Samples. 16 How to Obtain Checked Builds of Windows . 17 How to Obtain Debugging Tools . 18 How to Obtain OSR Learning Devices . 19 Key Information Sources . 20 Key References . 22 What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: www.microsoft.com/learning/booksurvey/ v A04T623743.fm Page vi Wednesday, March 21, 2007 7:58 PM vi Table of Contents 2 Windows Driver Fundamentals. 23 What Is a Driver?. 24 Core Windows Architecture . 25 Driver Architecture . 27 Kernel Objects and Data Structures . 31 The Windows I/O Model . 31 I/O Requests. 32 How a Device Stack Handles IRPs. 33 Data Buffers and I/O Transfer Types . 34 How to Transfer Data to or from a Device . 35 About Plug and Play and Power Management . 36 Basic Kernel-Mode Programming . 36 Interrupts and IRQLs. 37 Concurrency and Synchronization . 39 Memory . 42 Tips for Programming in Kernel Mode . 44 A Basic Vocabulary . 47 3 WDF Fundamentals . 51 WDF and WDM. 51 What Is WDF? . 52 WDF Object Model. 53 Programming Interface . ..
Recommended publications
  • TK Backman, Jason Yang, SW Development at MS
    T.K. Backman Jason Yang [email protected] [email protected] Principal Development Lead Principal Development Lead Debugging and Tools Group Analysis Technologies Team Windows Engineering Desktop Windows Engineering Desktop Microsoft Corporation Microsoft Corporationnnn Code on a massive scale Developers on a massive scale Tight constraints on schedules University of Washington 3/2/2011 2 ◦ Company structure Why the world is not just about developers ☺ ◦ Innovation strategy How we actually improve software over time ◦ Dynamic tension When people are involved, everything changes ◦ Development cycles How we build software products in cycles ◦ Program analysis How we push quality upstream ◦ Windows engineering system How we build large-scale products University of Washington 3/2/2011 3 ◦ Total size: ~89,000 employees ◦ Windows & Office – “perfect org structure” PM – program managers Dev – software developers Test – software developers in test ◦ Around 1000 PM+Dev+Test feature teams on 100s of products University of Washington 3/2/2011 4 ◦ Team size: ~10,000 employees ◦ Sales & marketing ◦ Project managers / product managers ◦ 30 feature teams 1500 Devs 1500 Testers 1000 PMs ◦ Customer support engineers ◦ Build engineers University of Washington 3/2/2011 5 “I often say that when you can measure what you are speaking about, and express it in numbers, you know something about it; but when you cannot measure it, when you cannot express it in numbers, your knowledge is of a meager and unsatisfactory kind; it may be the beginning
    [Show full text]
  • Scheduling, Thread Context, and IRQL
    Scheduling, Thread Context, and IRQL December 31, 2020 Abstract This paper presents information about how thread scheduling, thread context, and a processor’s current interrupt request level (IRQL) affect the operation of kernel- mode drivers for the Microsoft® Windows® family of operating systems. It is intended to provide driver writers with a greater understanding of the environment in which their code runs. A companion paper, “Locks, Deadlocks, and Synchronization” at http://www.microsoft.com/whdc/hwdev/driver/LOCKS.mspx, builds on these fundamental concepts to address synchronization issues in drivers. Contents Introduction ....................................................................................................................... 3 Thread Scheduling ............................................................................................................ 3 Thread Context and Driver Routines .................................................................................. 4 Driver Threads .................................................................................................................. 5 Interrupt Request Levels .................................................................................................... 6 Processor-Specific and Thread-Specific IRQLs .............................................................. 8 IRQL PASSIVE_LEVEL ............................................................................................ 8 IRQL PASSIVE_LEVEL, in a critical region ..............................................................
    [Show full text]
  • Run-Commands-Windows-10.Pdf
    Run Commands Windows 10 by Bettertechtips.com Command Action Command Action documents Open Documents Folder devicepairingwizard Device Pairing Wizard videos Open Videos Folder msdt Diagnostics Troubleshooting Wizard downloads Open Downloads Folder tabcal Digitizer Calibration Tool favorites Open Favorites Folder dxdiag DirectX Diagnostic Tool recent Open Recent Folder cleanmgr Disk Cleanup pictures Open Pictures Folder dfrgui Optimie Drive devicepairingwizard Add a new Device diskmgmt.msc Disk Management winver About Windows dialog dpiscaling Display Setting hdwwiz Add Hardware Wizard dccw Display Color Calibration netplwiz User Accounts verifier Driver Verifier Manager azman.msc Authorization Manager utilman Ease of Access Center sdclt Backup and Restore rekeywiz Encryption File System Wizard fsquirt fsquirt eventvwr.msc Event Viewer calc Calculator fxscover Fax Cover Page Editor certmgr.msc Certificates sigverif File Signature Verification systempropertiesperformance Performance Options joy.cpl Game Controllers printui Printer User Interface iexpress IExpress Wizard charmap Character Map iexplore Internet Explorer cttune ClearType text Tuner inetcpl.cpl Internet Properties colorcpl Color Management iscsicpl iSCSI Initiator Configuration Tool cmd Command Prompt lpksetup Language Pack Installer comexp.msc Component Services gpedit.msc Local Group Policy Editor compmgmt.msc Computer Management secpol.msc Local Security Policy: displayswitch Connect to a Projector lusrmgr.msc Local Users and Groups control Control Panel magnify Magnifier
    [Show full text]
  • Descarga De Software Y Configuración De Azure Education A) Creación De
    Descarga de software y configuración de Azure Education a) Creación de cuenta en Azure Education - Ingrese a http://aka.ms/devtoolsforteaching - Seleccione la opción - Inicie sesión con su cuenta Microsoft vinculada a sus correos @udp.cl o @mail.udp.cl (mismas cuentas para descarga de office en https://www.microsoft.com/es- es/education/products/office). Fig. 1: Login - Si usted ya tiene creada si cuenta Microsoft asociada a su correo mail.udp.cl o udp.cl puede realizar el login directamente. En caso de que su cuenta no esté activada, debe realizar primero el registro. - Es probable que se requiera agregar medios de verificación y de recuperación de cuenta por olvido de clave (a través de celular o de correo electrónico alternativo). - Una vez finalizados los pasos anteriores, se debe aceptar los términos y condiciones. El único obligatorio es el primer recuadro de la figura expuesta a continuación). Fig. 2: Términos y condiciones b) Descarga de software para la docencia Una vez finalizado el registro, verá una pantalla Fig. 3: Pantalla inicial Podrá realizar mini-tutoriales (ej: cómo construir web apps en Azure), cursos, descarga de software, entre otros. Para instalar un software específico, debe dar click a la opción “Software” del menú lateral izquierdo, desplegándose todo lo disponible para descarga. Fig. 4: Software Para descargar, debe hacer click en el software de interés. Aparecerá una ventana en el costado derecho de la pantalla. Fig. 5: Descarga de instalador Al dar click en el botón Download comenzará la descarga del instalador. Debe copiar la clave de instalación (Product Key que aparecerá al dar click al botón “View Key”).
    [Show full text]
  • Unit OS6: Device Management
    Lab Manual - OS6 Device Management Unit OS6: Device Management 6.4. Lab Manual Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze 1 Lab Manual - OS6 Device Management Copyright Notice © 2000-2005 David A. Solomon and Mark Russinovich These materials are part of the Windows Operating System Internals Curriculum Development Kit, developed by David A. Solomon and Mark E. Russinovich with Andreas Polze Microsoft has licensed these materials from David Solomon Expert Seminars, Inc. for distribution to academic organizations solely for use in academic environments (and not for commercial use) 2 2 Lab Manual - OS6 Device Management Roadmap for Section 6.4. Lab experiments investigating: Viewing Security Processes Looking at the SAM Viewing Access Tokens Looking at Security Identifiers (SIDs) Viewing a Security Descriptor structure Investigating ordering of Access Control Entries (ACEs) Investigating Privileges 3 This Lab Manual includes experiments investigating the the I/O system mechanisms and concepts implemented inside the Windows operating system. Students are expected to carry out Labs in addition to studying the learning materials in Unit OS6. A thorough understanding of the concepts presented in Unit OS6: Device Management is a prerequisite for these Labs. 3 Lab Manual - OS6 Device Management Lab: Viewing the Installed Driver List View the list of System Drivers in the Software Environment section of the Windows Information utility (Msinfo32.exe) Note: the distinction between File System Drivers and Kernel Drivers is from the Type value in the driver’s Registry key. This distinction is meaningless. 4 Lab objective: Viewing the Loaded Driver List You can see a list of registered drivers on a Windows 2000 system by going to the Drivers section of the Computer Management Microsoft Management Console (MMC) snapin or by right-clicking the My Computer icon on the desktop and selecting Manage from the context menu.
    [Show full text]
  • Webroot Secureanywhere® Business – DNS Protection Apache License 2.0 • Aws-Sdk-Net Copyright © Amazon.Com, Inc. Apache
    Webroot SecureAnywhere® Business – DNS Protection Apache License 2.0 • aws-sdk-net Copyright © Amazon.com, Inc. Apache License Version 2.0, January 2004 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. “License” shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. “Licensor” shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. “Legal Entity” shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, “control” means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. “You” (or “Your”) shall mean an individual or Legal Entity exercising permissions granted by this License. “Source” form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. “Object” form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. “Work” shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
    [Show full text]
  • Windows Kernel Internals II Windows Driver Model University of Tokyo – July 2004*
    Windows Kernel Internals II Windows Driver Model University of Tokyo – July 2004* Dave Probert, Ph.D. Advanced Operating Systems Group Windows Core Operating Systems Division Microsoft Corporation © Microsoft Corporation 2004 1 Windows I/O Model Asychronous, Packet-based, Extensible Device discovery supports plug-and-play — volumes automatically detected and mounted — power management support (ACPI) Drivers attach to per device driver stacks — Drivers can filter actions of other drivers in each stack Integrated kernel support — memory Manager provides DMA support — HAL provides device access, PnP manages device resources — Cache manager provides file-level caching via MM file-mapping Multiple I/O completion mechanisms: —synchronous —update user-mode memory status —signal events —callbacks within initiating thread —reaped by threads waiting on an I/O Completion Port © Microsoft Corporation 2004 2 IO Request Packet (IRP) IO operations encapsulated in IRPs IO requests travel down a driver stack in an IRP Each driver gets an IRP stack location which contains parameters for that IO request IRP has major and minor codes to describe IO operations Major codes include create, read, write, PNP, devioctl, cleanup and close Irps are associated with the thread that made the IO request © Microsoft Corporation 2004 3 Object Relationships Driver Object Device Object Device Device Device Object Object Object Volume Device Object Driver Object File Object File Object © Microsoft Corporation 2004 4 Layering Drivers Device objects attach one on top of another
    [Show full text]
  • Installing, Using and Testing Microsoft Windows Driver Kit (WDK)
    www.installsetupconfig.com Installing, Using and Testing Microsoft Windows Driver Kit (WDK) What do we have in this session? Introduction Installing the WDK The Windows Debuggers Installing Symbols Package The WinDbg Starting WinDbg Verifying WDK Installation Steps on Using WDK and Building Windows Driver from Code Sample Building a Windows Driver Sample Drivers and Services Installing/Registering a Driver Starting a Driver Viewing Driver Output Unloading a Driver Print Devices: Generic Text-Only Driver Sample Useful WDK references: Introduction The Windows machine specification used in this session are: 1. Operating System : Windows XP Pro SP2 2. RAM : 2 GB DDR2 3. HDD : 160++GB 4. Display : 128 MB ATI PCI Express 5. Processor : Intel Core 2 Duo 4400 2.00 GHz The DDK has been superseded by the Windows Driver Kit (WDK). While the DDK can be downloaded openly, you may need to register for free and participate in the respective Microsoft community to download WDK. Microsoft said that the WDK should be used for the following reasons: 1. Use the Windows Vista build environments in the WDK to build drivers that use new features or functionality available only in Windows Vista. 2. Use the Windows Server 2003 build environments in the WDK to build drivers that use new features or functionality available only in Windows Server 2003. 3. Use the Windows XP build environments in the WDK to build drivers that do not use new functionality available only in Windows Vista or only in Windows Server 2003 and that are targeted for either Windows XP or Windows Server 1 www.installsetupconfig.com 2003 and Windows XP.
    [Show full text]
  • Windows Internals, Sixth Edition, Part 2
    spine = 1.2” Part 2 About the Authors Mark Russinovich is a Technical Fellow in ® the Windows Azure™ group at Microsoft. Windows Internals He is coauthor of Windows Sysinternals SIXTH EDITION Administrator’s Reference, co-creator of the Sysinternals tools available from Microsoft Windows ® The definitive guide—fully updated for Windows 7 TechNet, and coauthor of the Windows Internals and Windows Server 2008 R2 book series. Delve inside Windows architecture and internals—and see how core David A. Solomon is coauthor of the Windows Internals book series and has taught components work behind the scenes. Led by a team of internationally his Windows internals class to thousands of renowned internals experts, this classic guide has been fully updated Windows developers and IT professionals worldwide, SIXTH for Windows 7 and Windows Server® 2008 R2—and now presents its including Microsoft staff. He is a regular speaker 6EDITION coverage in two volumes. at Microsoft conferences, including TechNet As always, you get critical, insider perspectives on how Windows and PDC. operates. And through hands-on experiments, you’ll experience its Alex Ionescu is a chief software architect and internal behavior firsthand—knowledge you can apply to improve consultant expert in low-level system software, application design, debugging, system performance, and support. kernel development, security training, and Internals reverse engineering. He teaches Windows internals courses with David Solomon, and is ® In Part 2, you will: active in the security research community.
    [Show full text]
  • Installing Microsoft Windows Driver Development Kit (DDK) for Microsoft Windows Server 2003 Service Pack 1 (SP1) on Windows XP Pro SP2
    www.tenouk.com Installing Microsoft Windows Driver Development Kit (DDK) for Microsoft Windows Server 2003 Service Pack 1 (SP1) on Windows XP Pro SP2 This step-by-step document also contains how-to install the Debugging Tools for Windows and Symbols Package. Machine specification used in this scenario. 1. Operating System : Windows Xp Pro SP2 2. RAM : 2 GB DDR2 3. HDD : 160++G 4. Display : 128 MB ATI PCI Express 5. Processor : Intel Core 2 Duo 4400 2.00 GHz Installing the DDK First of all we need to download the ISO from Microsoft or you can buy the CD as well. The current version is Windows Server 2003 SP1 that covers Windows 2000, Windows XP and Windows 2003 Server family. This DDK has been superseded by the Windows Driver Kit (WDK). We will try to install the WDK later. While the DDK can be downloaded openly, you need to register for free and participate in the respective Microsoft community to download WDK. Microsoft said that the WDK should be used for the following reasons: 1. Use the Windows Vista build environments in the WDK to build drivers that use new features or functionality available only in Windows Vista. 2. Use the Windows Server 2003 build environments in the WDK to build drivers that use new features or functionality available only in Windows Server 2003. 3. Use the Windows XP build environments in the WDK to build drivers that do not use new functionality available only in Windows Vista or only in Windows Server 2003 and that are targeted for either Windows XP or Windows Server 2003 and Windows XP.
    [Show full text]
  • Dan's Motorcycle Windows Commands
    1 Complete List of Run Commands in Windows XP, Vista, 7, 8 & 8.1 ¶ People can get stuck if they are attacked with viruses or in any way can’t access different Applications in Windows. Sometimes it gets difficult to find the commands to start the applications directly. Knowing the Run Command for a program in different Windows versions can be very useful. if you’d like to start a program from a script file or if you only have access to a command line interface this can be helpful. For example, If you have Microsoft Word installed (Any version of Microsoft Office®) rather then searching or clicking the start icon, locating the Microsoft Office folder and then clicking the Microsoft Word. You can use the Windows Run Box instead to access the application directly. Just Click Start and Click Run or press "Window Key + R" and type "Winword" and press enter, Microsoft Word will open immediately. Here is a, hopefully, Complete list of RUN Commands in Windows XP, Vista, 7, 8 and 8.1 for your quick and easy access. Description of Applications Run Command 32-bit ODBC driver under 64-bit platform = C:\windows\sysWOW64\ odbcad32.exe 64 bit ODBC driver under 64-bit platform = C:\windows\system32\ odbcad32.exe Accessibility Controls access.cpl Accessibility Options control access.cpl Accessibility Wizard accwiz Copyright © 1999-2016 dansmc.com. All rights reserved. Adapter Troubleshooter (Vista/Win7) AdapterTroubleshooter 2 Add Features to Windows 8 Win8 windowsanytimeupgradeui Add Hardware Wizard Win8 hdwwiz Add New Hardware Wizard hdwwiz.cpl Add/Remove
    [Show full text]
  • Hyperplatform User Document
    HyperPlatform User Document Table of Contents 1. About this document..............................................................................................................................2 2. Get started..............................................................................................................................................3 2.1. Description..........................................................................................................................................3 2.2. Prerequisites........................................................................................................................................3 2.3. Creating a new project........................................................................................................................3 2.4. What is Next........................................................................................................................................7 3. Development and Debug Tips................................................................................................................8 3.1. Description..........................................................................................................................................8 3.2. Using VMware Workstation................................................................................................................8 3.3. Using Bochs........................................................................................................................................8
    [Show full text]