KMDF WdfDriverCreate函数返回“资源不足”

KMDF WdfDriverCreate函数返回“资源不足”

问题描述:

我正在尝试编写一个kmdf驱动程序来定位自定义PCIe板。在遵循Microsoft提供的默认项目之后,我对.inf文件进行了一些小修改,主要是更改字符串的名称并提供我们的PCIe板卡的硬件ID。KMDF WdfDriverCreate函数返回“资源不足”

部署驱动程序的工作原理应该如此。驱动程序安装并显示在设备管理器上,但它表示它没有正确安装或可能已损坏。

在调试时,我看到WdfDriverCreate失败,错误为0xC000009A,这意味着资源不足。

以供参考,这是生成的代码,该KMDF模板项目让你,这是我目前正在运行:

NTSTATUS 
DriverEntry(
    _In_ PDRIVER_OBJECT DriverObject, 
    _In_ PUNICODE_STRING RegistryPath 
    ) 
{ 
    WDF_DRIVER_CONFIG config; 
    NTSTATUS status; 
    WDF_OBJECT_ATTRIBUTES attributes; 

    // 
    // Initialize WPP Tracing 
    // 
    WPP_INIT_TRACING(DriverObject, RegistryPath); 

    TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Entry"); 

    // 
    // Register a cleanup callback so that we can call WPP_CLEANUP when 
    // the framework driver object is deleted during driver unload. 
    // 
    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, DEVICE_CONTEXT); 
    attributes.EvtCleanupCallback = CIPDriverEvtDriverContextCleanup; 

    WDF_DRIVER_CONFIG_INIT(&config, 
          CIPDriverEvtDeviceAdd 
          ); 

    KdPrint(("CIP: Driver Entry\n")); 
    status = WdfDriverCreate(DriverObject, 
          RegistryPath, 
          &attributes, 
          &config, 
          WDF_NO_HANDLE 
          ); 

    if (!NT_SUCCESS(status)) { 
     TraceEvents(TRACE_LEVEL_ERROR, TRACE_DRIVER, "WdfDriverCreate failed %!STATUS!", status); 
     KdPrint(("CIP: WdfDriverCreate failed with status - 0x%x\n", status)); 
     WPP_CLEANUP(DriverObject); 
     return status; 
    } 

    TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Exit"); 

    return status; 
} 

我的第一个问题是,什么会导致此?

我试图转储错误日志将被运行

!wdfkd.wdflogdump mydriver.sys 

提出,但它永远不会奏效了。我确保所有符号路径加载正确,如下所示

fffff880`05fdd000 fffff880`05fe6000 CIPDriver (private pdb symbols) C:\Users\jimmyjoebobby\Documents\Visual Studio 2013\Projects\CIPDriver\x64\Win7Debug\CIPDriver.pdb   
22: kd> lm m wdf* 
start    end     module name 
fffff880`00e5e000 fffff880`00f20000 Wdf01000 (pdb symbols)   c:\winsymbols\Wdf01000.pdb\03FC6AA4329F4372BE924775887225632\Wdf01000.pdb 
fffff880`00f20000 fffff880`00f30000 WDFLDR  (pdb symbols)   c:\winsymbols\wdfldr.pdb\9674B20D2E5B4E7AA2DE143F642A176E2\wdfldr.pdb 

其中“CIPDriver”是我的驱动程序。

在运行dump命令,这是输出:

22: kd> !wdfkd.wdflogdump CIPDriver.sys 
Trace searchpath is: 

Trace format prefix is: %7!u!: %!FUNC! - 
TMF file used for formatting log is: C:\WinDDK\7600.16385.1\tools\tracing\amd64\wdf01000.tmf 
Log at fffffa80356232f8 
Gather log: Please wait, this may take a moment (reading 0 bytes). 
% read so far ... 
warn: The log could not be accessed 
hint: Are the symbols the WDF library available? 
hint: The log is inaccessable after driver unload. 

和.sympath

22: kd> .sympath 
Symbol search path is: C:\Users\jimmyjoebobby\Documents\Visual Studio 2013\Projects\CIPDriver\Win7Debug;C:\winsymbols 
Expanded Symbol search path is: c:\users\jimmyjoebobby\documents\visual studio 2013\projects\cipdriver\win7debug;c:\winsymbols 

的输出,其中C:\ winsymbols是我收购了微软的符号的高速缓存以下指南在这里:https://msdn.microsoft.com/en-us/library/windows/hardware/ff558829(v=vs.85).aspx

我的第二个问题是,我如何正确设置调试器来转储出日志?

感谢

我不明白为什么这会有所帮助,但如果我

[DriverName] Package -> Properties -> Configuration Properties -> Driver Install -> KMDF Verifier -> Enable KMDF Verifier 

下关闭KMDF验证和部署的驱动程序,它的工作原理。如果我打开它,它会失败。我部署了几次驱动程序来打开和关闭该选项,打开时它总是失败。

我发布了这个问题以及我的发现。也许有人可以回答为什么这样的情况:https://www.osronline.com/showthread.cfm?link=277793

+0

我可以证实这一点解决了我的问题。 @shaboinkin最近是否安装了WDK?我在上周做到了。也许最近发布的版本中有一个错误?我试图弄清楚根本原因,这似乎很可能。 – Warty

+0

是的,但我安装了WDK 8.1,它在2014年似乎已经上传到微软的那一方。我相信0的值被传递到内存分配中,从而导致失败。 如果您在文件“handleapi”中检查WDK的源代码(https://github.com/Microsoft/Windows-Driver-Frameworks)。cpp“中,有一个名为FxObjectHandleAlloc的函数,它传递了一个”size“参数。有一个评论提到编译器传入的大小,它在fxobject.hpp中的函数宏中使用了一个重载的new运算符 – shaboinkin

+0

我从来没有通过调试器进行修改来验证这确实是问题,因为它需要很长的时间才能完成设置,但FxObjectHandleAlloc内部的其他故障点是唯一可以看到的地方它失败了,在该函数中调用它,FxPoolAllocateWithTag最终调用wdfpool.cpp中的FxPoolAllocator,该函数在大小== 0时失败,或者在这些Rtl *函数的输出中失败,这些函数我无法查看无论出于何种原因,让编译器传入0是我唯一能想到的事情将使它失败。 – shaboinkin