Windows 10 中的 WDF 驱动程序新增功能What's New for WDF Drivers in Windows 10

本主题汇总了 Windows 10 中的 Windows 驱动程序框架 (WDF) 驱动程序的新功能和改进。This topic summarizes the new features and improvements for Windows Driver Frameworks (WDF) drivers in Windows 10.

Windows 10 版本 1903(2019 年 3 月更新,19H1)包括内核模式驱动程序框架 (KMDF) 版本 1.29 和用户模式驱动程序框架 (UMDF) 版本 2.29。Windows 10, version 1903 (March 2019 Update, 19H1) includes Kernel-Mode Driver Framework (KMDF) version 1.29 and User-Mode Driver Framework (UMDF) version 2.29.

可以使用这些框架版本为以下操作系统生成驱动程序:You can use these framework versions to build drivers for:

  • Windows 10(所有 SKU)Windows 10 (all SKUs)
  • Windows Server 版本 1809Windows Server, version 1809

有关版本历史记录,请参阅 KMDF 版本历史记录UMDF 版本历史记录For version history, see KMDF Version History and UMDF Version History. 除非特别说明,否则本页中的 UMDF 参考介绍的是版本 2 的功能,该功能在 UMDF 版本 1 中不提供。Except where noted, UMDF references on this page describe version 2 functionality that is not available in UMDF version 1.

适用于 Windows 10 版本 1903 的 WDF 中的新功能New in WDF for Windows 10, version 1903

未添加或更改任何功能。No functionality added or changed.

适用于 Windows 10 版本 1809 的 WDF 中的新功能New in WDF for Windows 10, version 1809

适用于 Windows 10 版本 1803 的 WDF 中的新功能New in WDF for Windows 10, version 1803

适用于 Windows 10 版本 1709 的 WDF 中的新功能New in WDF for Windows 10, version 1709

请参阅 KMDF 版本历史记录UMDF 版本历史记录See KMDF Version History and UMDF Version History.

适用于 Windows 10 版本 1703 的 WDF 中的新功能New in WDF for Windows 10, version 1703

在 Windows 10 版本 1703 中,WDF 包含以下增强功能:In Windows 10, version 1703, WDF includes the following enhancements:

  • 新的 WDF 验证程序设置,用于检测是否过多地创建了对象New WDF Verifier settings to detect excessive object creation

    某些情况下,框架对象未正确设置父级且在使用后未删除。In some cases, framework objects are incorrectly parented and not deleted after use. 有了此功能,就可以指定对象的最大数目,以及超过此阈值时会发生什么情况。With this feature, you can specify a maximum number of objects and what should happen when this threshold is exceeded.

    若要开始监视,请在 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\<driver service>\Parameters\wdf 项下添加以下注册表值:To start monitoring, add the following registry values under: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\<driver service>\Parameters\wdf

    1. 添加名为 ObjectLeakDetectionLimit 且带阈值的 DWORD 值。Add a DWORD value named ObjectLeakDetectionLimit with the threshold value. 这是最大的对象数,对象类型如 ObjectsForLeakDetection 项中所述。This is the maximum number of objects of the types described in the ObjectsForLeakDetection key.

    2. 添加名为 ObjectsForLeakDetection 的新 REG_MULTI_SZ 值,用于列出要验证的每个类型名称。Add a new REG_MULTI_SZ value named ObjectsForLeakDetection that lists each type name to verify. 例如,可以指定 WDFDMATRANSACTION WDFDEVICEFor example, you could specify WDFDMATRANSACTION WDFDEVICE. 若要指定所有句柄类型,请使用 * 作为字符串。To specify all handle types, use * as the string.

    3. 若要控制在超过此阈值的情况下是否应导致调试断点或 Bug 检查,请设置 DbgBreakOnError 项。To control whether exceeding this threshold should cause a debug break or a bugcheck, set the DbgBreakOnError key.

      默认情况下,如果 ObjectsForLeakDetection 项未指定,则框架会监视 WDFREQUEST、WDFWORKITEM、WDFKEY、WDFSTRING、WDFOBJECT 和 WDFDEVICE。By default, if the ObjectsForLeakDetection key is not specified, the framework monitors WDFREQUEST, WDFWORKITEM, WDFKEY, WDFSTRING, WDFOBJECT, and WDFDEVICE.

      此限制随安装的设备数伸缩,因此,如果驱动程序创建了 3 个 WDFDEVICE 对象,则 WDF 验证程序限制是 ObjectLeakDetectionLimit 中指定的值的 3 倍。The limit scales with the number of devices installed, so if the driver creates three WDFDEVICE objects, the WDF Verifier limit is three times the value specified in ObjectLeakDetectionLimit.

      如果指定 WDFREQUEST,则验证程序仅将驱动程序创建的 WDFREQUEST 对象计入。If you specify WDFREQUEST, the verifier only counts WDFREQUEST objects that the driver creates.

      此功能当前不支持跟踪 WDFMEMORY 对象类型。This feature does not currently support tracking the WDFMEMORY object type.

  • SleepStudy 工具提供了有关 KMDF 驱动程序的信息SleepStudy tool provides info on KMDF drivers

    SleepStudy 软件工具报告 KMDF 驱动程序具有的妨碍系统进入睡眠的电源参考数。The SleepStudy software tool reports the number of power references that a KMDF driver has that are preventing the system from going to sleep. 有关详细信息,请参阅 Modern standby SleepStudy(新式待机 SleepStudy)。For more info, see Modern standby SleepStudy.

此页其余部分介绍 Windows 10 版本 1507 中增加的功能。The rest of this page describes functionality that was added in Windows 10, version 1507.

WDF 源代码已公开发布WDF source code is publicly available

  • WDF 源代码现在位于 GitHub 上,以开源方式提供。The WDF source code is now available as open source on GitHub. Windows 10 中提供的 WDF 运行时库是根据此源代码生成的。This is the same source code from which the WDF runtime library that ships in Windows 10 is built. 如果能够按照驱动程序和 WDF 之间的交互步骤进行操作,则可更有效地调试驱动程序。You can debug your driver more effectively when you can follow the interactions between the driver and WDF. http://github.com/Microsoft/Windows-Driver-Frameworks 下载它。Download it from http://github.com/Microsoft/Windows-Driver-Frameworks.

  • Windows 10 上的 WDF 的专用符号文件现在可以通 Microsoft 符号服务器获取。The private symbol files for WDF on Windows 10 are now available through the Microsoft Symbol Server.

  • Windows 驱动程序工具包 (WDK) 10 示例现在也发布到 GitHub。The Windows Driver Kit (WDK) 10 samples are also now published to GitHub. http://github.com/Microsoft/Windows-Driver-Samples 下载它们。Download them from http://github.com/Microsoft/Windows-Driver-Samples.

自动对框架代码进行源级别调试Automatic Source Level Debugging of Framework Code

使用 WinDbg 调试 Windows 10 上的 WDF 驱动程序时,WinDbg 会自动从 Microsoft 的公共 GitHub 存储库检索框架源代码。When you use WinDbg to debug a WDF driver on Windows 10, WinDbg automatically retrieves the framework source code from Microsoft's public GitHub repository. 可以通过此功能在调试时单步执行 WDF 源代码,了解框架的内部结构,不需将源代码下载到本地计算机。You can use this feature to step through the WDF source code while debugging, and to learn about framework internals without downloading the source code to a local machine. 有关详细信息,请参阅 New support for source-level debugging of WDF code in Windows 10(全新支持:在 Windows 10 中对 WDF 代码进行源级别调试)、Debugging with WDF Source(通过 WDF 源进行调试)并观看视频:使用 WDF 源代码调试驱动程序For more information, see New support for source-level debugging of WDF code in Windows 10, Debugging with WDF Source, and Video: Debugging your driver with WDF source code.

通用驱动程序符合性Universal Driver Compliance

所有 WDF 驱动程序示例和 Visual Studio 驱动程序模板都兼容通用 Windows 驱动程序All WDF driver samples and Visual Studio driver templates are Universal Windows driver compliant.

所有 KMDF 和 UMDF 2 功能都兼容通用 Windows 驱动程序。All KMDF and UMDF 2 functionality is Universal Windows driver compliant.

请注意,UMDF 1 驱动程序仅在 Windows 10 桌面版和早期的 Windows 桌面版上运行。Note that UMDF 1 drivers run only on Windows 10 for desktop editions and earlier versions of desktop Windows. 想要使用 UMDF 2 的通用功能?Want to benefit from the universal capabilities of UMDF 2? 若要了解如何移植旧的 UMDF 1 驱动程序,请参阅将驱动程序从 UMDF 1 移植到 UMDF 2To learn how to port your old UMDF 1 driver, see Porting a Driver from UMDF 1 to UMDF 2.

调试和诊断能力Debugging and Diagnosability

  • 所有 KMDF 和 UMDF 2 驱动程序都可以使用一个始终打开且始终提供的即时跟踪记录器 (IFR)。All KMDF and UMDF 2 drivers can use an always on, always available Inflight Trace Recorder (IFR). 当驱动程序提供自定义跟踪时,驱动程序 IFR 日志将包含跟踪消息。When a driver provides a custom trace, the driver IFR log contains the trace messages. 请注意,新的驱动程序 IFR 日志独立于 WDF 为每个驱动程序创建的框架 IFR 日志。Note that the new driver IFR log is separate from the framework IFR log that WDF creates for each driver.

    很容易就可以打开 IFR。It's easy to turn on the IFR. 请参阅 Inflight Trace Recorder (IFR) for logging traces(用于记录跟踪的即时跟踪记录器 (IFR))和在 KMDF 和 UMDF 驱动程序中使用即时跟踪记录器See Inflight Trace Recorder (IFR) for logging traces and Using Inflight Trace Recorder in KMDF and UMDF Drivers.

  • IFR 在不可分页的内存中保留一个循环缓冲区,其中有 WPP 跟踪。The IFR maintains a circular buffer of WPP traces in non-pageable memory. 如果驱动程序出现故障,则会在故障转储文件中频繁保存日志。If a driver crashes, the logs are frequently included in the crash dump file.

  • 如果在驱动程序二进制文件中启用 IFR,则在驱动程序的生命周期内,IFR 会始终存在并处于运行状态。If you turn on the IFR in your driver binary, the IFR is present and running during the lifetime of your driver. 不需启动显式跟踪收集会话。You don't need to start an explicit trace collection session.

    • IFR 日志包含在小型转储文件中,除非相应的驱动程序未确定或者该崩溃是主机超时。IFR logs are included in minidump files except when the responsible driver is undetermined or if the crash was a host timeout.

    • 如果连接了调试程序,则可通过发出 !wdfkd.wdflogdump 来访问驱动程序和框架 IFR 日志。If you have a debugger connected, you can access both the driver and framework IFR logs by issuing !wdfkd.wdflogdump.

    • 即使未连接调试程序,也可以访问这两种日志。If you do not have a debugger connected, you can still access both logs. 若要了解具体方法,请观看视频:在没有调试程序的情况下访问驱动程序 IFR 日志To learn how, see Video: Accessing driver IFR logs without a debugger.

    • 调试 UMDF 驱动程序时,可以将框架日志与驱动程序日志合并在一起,方法是发出以下命令: !wdfkd.wdflogdump <drivername.dll> -mWhen debugging a UMDF driver, you can merge framework logs with driver logs by issuing: !wdfkd.wdflogdump <drivername.dll> -m

  • UMDF 日志 (WudfTrace.etl) 和转储现在位于 %ProgramData%\Microsoft\WDF 中而不是 %systemDrive%\LogFiles\Wudf 中。UMDF logs (WudfTrace.etl) and dumps are now located in %ProgramData%\Microsoft\WDF instead of %systemDrive%\LogFiles\Wudf.

  • 可以通过新的调试程序命令 !wdfkd.wdfumtriage 以内核为中心查看系统中的所有 UMDF 设备。New debugger command: !wdfkd.wdfumtriage provides a kernel-centric view of all UMDF devices on the system.

  • 可以运行 !analyze 来调查 UMDF 验证程序故障或 UMDF 未处理异常。You can run !analyze to investigate UMDF verifier failures or UMDF unhandled exceptions. 这适用于实时内核调试,以及对 %ProgramData% \Microsoft\WDF 中的用户故障转储文件进行的调试。This works for live kernel debugging as well as debugging user crash dump files from %ProgramData%\Microsoft\WDF.

  • 在 KMDF 和 UMDF 2 中,可以在调试程序中监视电源参考使用情况。In KMDF and UMDF 2, you can monitor power reference usage in the debugger. 有关信息,请参阅在 WDF 中调试电源参考漏孔For info, see Debugging Power Reference Leaks in WDF.

  • 可以使用 !wdfkd.wdfcrashdump 显示有关 UMDF 2 驱动程序的错误信息。You can use !wdfkd.wdfcrashdump to display error information about UMDF 2 drivers. 有关详细信息,请参阅 !wdfkd.wdfcrashdumpFor more information, see !wdfkd.wdfcrashdump.

用于 WDF 驱动程序的性能跟踪工具Performance Tracing tool for WDF drivers

可以使用 Windows 性能工具包 (WPT) 查看给定的 KMDF 或 UMDF 2 驱动程序的性能数据。You can use the Windows Performance Toolkit (WPT) to view performance data for a given KMDF or UMDF 2 driver. 启用跟踪时,框架会针对 I/O、PnP 和电源回调路径生成 ETW 事件。When tracing is enabled, the framework generates ETW events for I/O, PnP, and Power callback paths. 然后,你可以在 Windows Performance Analyzer (WPA) 中查看各种图,了解 I/O 吞吐率、CPU 使用率和回调性能。You can then view graphs in the Windows Performance Analyzer (WPA) that show I/O throughput rates, CPU utilization, and callback performance. WPT 包括在 Windows 评估和部署工具包 (ADK) 中。The WPT is included in the Windows Assessment and Deployment Kit (ADK).

有关详细信息,请参阅 New Performance Tools for WDF Drivers in Windows 10(Windows 10 中用于 WDF 驱动程序的全新性能工具)和将 Windows 性能工具包 (WPT) 与 WDF 配合使用For more information, see New Performance Tools for WDF Drivers in Windows 10 and Using the Windows Performance Toolkit (WPT) with WDF.

针对 UMDF 中的 HID 驱动程序的其他支持Additional support for HID drivers in UMDF

  • UMDF 现在完全支持 HID 筛选器(按 HIDClass 枚举)和微型驱动程序。UMDF now fully supports HID filters (enumerated by HIDClass) and minidrivers. 直接移植现有的 KMDF 驱动程序或编写新的 UMDF 2 筛选器,然后系统就会自动启用该功能。Simply port your existing KMDF driver or write a new UMDF 2 filter; the functionality is automatically enabled.

  • 按 ACPI 枚举的 UMDF HID 微型驱动程序可以执行选择性挂起。UMDF HID minidrivers that are enumerated by ACPI can perform selective suspend. 有关详细信息,请参阅创建 WDF HID 微型驱动程序For more information, see Creating WDF HID Minidrivers.

  • UMDF 驱动程序现在可以安装在 HID 堆栈中,用于低延迟输入设备,例如触控和鼠标。UMDF drivers can now be installed in the HID stack for low latency input devices such as touch and mouse. 用于输入设备的驱动程序应该指定 UmdfHostPriority INF 指令。A driver for an input device should specify the UmdfHostPriority INF directive. 有关信息,请参阅在 INF 文件中指定 WDF 指令For information, see Specifying WDF Directives in INF Files.

支持的中断适用于 GPIO 支持的设备Support for interrupts for GPIO-backed devices

UMDF 不再需要 WinUSBUMDF no longer requires WinUSB

为 UMDF 中的 USB 驱动程序添加了新的支持。New support has been added for USB drivers in UMDF. UMDF 2 USB 驱动程序不再使用 WinUSB。A UMDF 2 USB driver no longer uses WinUSB. 为了使用新的功能,驱动程序将 UmdfDispatcher 指令设置为 NativeUSB 而不是 WinUSBTo use the new functionality, the driver sets the UmdfDispatcher directive to NativeUSB, instead of WinUSB. 请参阅在 INF 文件中指定 WDF 指令See Specifying WDF Directives in INF Files.

改进的性能Improved Performance

  • UMDF 系统组件占用较少的磁盘空间。UMDF system components consume less disk space.

  • KMDF 和 UMDF 驱动程序使用较少的非分页内存。KMDF and UMDF drivers use less non-paged memory.

  • 改进的框架版本检查功能减少了标头/库不匹配项。Improved framework version checking reduces header/library mismatches.

  • UMDF 为 HID 传输提供改进的缓冲区映射。UMDF provides improved buffer mapping for HID transfers.