计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
wdf-umdf【效率与协作】User-Mode Driver Framework v2 (UMDF). User-mode driver model that uses the same WDF object model as KMDF but runs in a host process (WUDFHost.exe) protected by the reflector. Required for some categories (Indirect Display Drivers, many sensor and camera drivers) and recommended for any driver that doesn't strictly need kernel mode. USE WHEN: user me…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: wdf-umdf description: | User-Mode Driver Framework v2 (UMDF). User-mode driver model that uses the same WDF object model as KMDF but runs in a host process (WUDFHost.exe) protected by the reflector. Required for some categories (Indirect Display Drivers, many sensor and camera drivers) and recommended for any driver that doesn't strictly need kernel mode.
USE WHEN: user mentions "UMDF", "WUDFHost", "user-mode driver", "reflector", "IDD", "ISensor", "WDFHOST", "UMDF v2", "FX2"
wdf-kmdf), classic UMDF v1 (deprecated, COM-based)
allowed-tools: Read, Grep, Glob, Write, EditDeep Knowledge: Use
mcp__documentation__fetch_docswith technology:wdf-umdf. Authoritative source:learn.microsoft.com/en-us/windows-hardware/drivers/wdf/getting-started-with-umdf-version-2.
WUDFHost.exe, a user-mode service host. No bugchecks if it crashes — reflector restarts it.WdfDriverCreate, WdfDeviceCreate, WdfRequest*). Differences are mostly which APIs are available, not how to call them.UMDF drivers expose the same DriverEntry symbol; the host loads the DLL and calls it:
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) {
WDF_DRIVER_CONFIG config;
WDF_DRIVER_CONFIG_INIT(&config, MyEvtDeviceAdd);
return WdfDriverCreate(DriverObject, RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
}
| Concern | KMDF | UMDF |
|---|---|---|
| Process | System (ntoskrnl.exe) | WUDFHost.exe (user mode) |
| Crash impact | Bugcheck | Host restart, device disappears briefly |
| C++ usage | Discouraged (no exceptions/RTTI) | Full C++ allowed (use the cpp skill freely) |
| Direct hardware access | MMIO, port I/O, DMA | Through reflector / a kernel companion driver if needed |
| Synchronous kernel APIs | Available | Not available — use Win32 / WDF user-mode equivalents |
| IRQL | Real IRQL discipline | Always at PASSIVE-equivalent (no DISPATCH worries) |
| Pool | ExAllocatePool2 | new / malloc / HeapAlloc |
| Tracing | WPP | WPP or standard ETW providers |
Practical consequence: UMDF is almost C++17/20 application code with WDF idioms wrapped around it. Memory bugs are caught by ASan-style tooling at user-mode dev time; kernel pitfalls disappear.
[Manufacturer]
%MfgName% = Standard,NT$ARCH$.10.0...19041
[Standard.NT$ARCH$.10.0...19041]
%Device.DeviceDesc% = MyDevice_Install, ROOT\MyDevice
[MyDevice_Install.NT]
CopyFiles = MyDevice.CopyFiles
AddReg = MyDevice.AddReg
[MyDevice_Install.NT.Services]
AddService = WUDFRd, 0x000001fa, WUDFRD_ServiceInstall
[WUDFRD_ServiceInstall]
DisplayName = "WUDF Reflector"
ServiceType = 1
StartType = 3
ErrorControl = 1
ServiceBinary= %12%\WUDFRd.sys
LoadOrderGroup = Base
[MyDevice_Install.NT.Wdf]
UmdfDispatcher = NativeUSB ; or NativeIDD, NativeHID, etc.
UmdfServiceOrder = MyUmdfDriver
UmdfKernelModeClientPolicy = AllowKernelModeClients
[MyUmdfDriver]
UmdfLibraryVersion = $UMDFVERSION$
DriverCLSID = {01234567-89AB-CDEF-0123-456789ABCDEF}
ServiceBinary = %13%\MyDevice.dll
WUDFRd.sys (the Reflector) sits in the kernel as the proxy for the user-mode driver. It:
You don't write reflector code; you write DLL code and the framework + reflector deliver requests to it.
UMDF cannot call arbitrary kernel APIs. Patterns:
DriverSolution/
├── MyUmdfDriver/ (.vcxproj — UMDF v2)
│ ├── Driver.cpp DriverEntry, EvtDeviceAdd
│ ├── Device.cpp Device-level WDF callbacks
│ ├── Queue.cpp IOCTL / Read / Write handlers
│ ├── MyUmdfDriver.def Exports
│ └── MyUmdfDriver.inf
├── MyUmdfDriverPackage/ Driver package (.cab + signing)
└── MyUmdfDriverTests/ User-mode test app (Win32 console / GTest)
WUDFHost.exe — much friendlier than KMDFHKLM\System\CurrentControlSet\Services\WUDFHost\Parameters\HostProcessDbgBreakOnStart=1 to break before driver loadApplication Verifier for memory/handle bugs (much like Driver Verifier for KMDF)| Anti-Pattern | Why It's Bad | Correct Approach |
|---|---|---|
| Treating UMDF callbacks as background work | They serialize requests | Hand off long work to a separate worker thread; complete the request when done |
| Calling kernel-only APIs | Won't link | Use Win32 / WDF user-mode equivalents |
| Holding a request indefinitely with no cancel handler | App hangs | Mark cancelable, handle EvtRequestCancel |
| Using process global state | Multiple device instances share the host | Per-device context via WDF_OBJECT_ATTRIBUTES |
Logging via OutputDebugString only | Lost in production | WPP/ETW with a published GUID |
| Assuming the host stays up | Reflector can recycle it | Persist nothing in process memory; reload from registry/file on EvtDevicePrepareHardware |