【问题标题】:KMDF WdfDriverCreate function returns "insufficient resources"KMDF WdfDriverCreate 函数返回“资源不足”
【发布时间】:2016-07-06 18:41:35
【问题描述】:

我正在尝试编写一个 kmdf 驱动程序以针对自定义 PCIe 板。按照微软提供的默认项目,我对 .inf 文件做了一些小改动,主要是更改字符串的名称并提供我们 PCIe 板的硬件 ID。

部署驱动程序正常工作。驱动程序安装并显示在设备管理器上,但它说它没有正确安装或可能已损坏。

在调试时,我看到 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”是我的驱动程序。

运行转储命令时,输出如下:

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 是我通过以下指南获得的 Microsoft 符号缓存:https://msdn.microsoft.com/en-us/library/windows/hardware/ff558829(v=vs.85).aspx

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

谢谢

【问题讨论】:

    标签: windows kmdf wdf


    【解决方案1】:

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

    下关闭了 KMDF 验证器
    [DriverName] Package -> Properties -> Configuration Properties -> Driver Install -> KMDF Verifier -> Enable KMDF Verifier 
    

    并部署驱动程序,它可以工作。如果我打开它,它会失败。我部署了我的驱动程序几次打开和关闭该选项,但它总是在打开时失败。

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

    【讨论】:

    • 我可以确认这解决了我的问题。 @shaboinkin 你最近安装了 WDK 吗?我在上周做了。也许最近的版本中存在错误?我正试图找出根本原因,这似乎很可能。
    • 是的,但是我安装了 WDK 8.1,它看起来早在 2014 年就已上传到 Microsoft 这边。我相信值 0 被传递到内存分配中,导致事情失败。如果你查看文件“handleapi.cpp”中的WDK(github.com/Microsoft/Windows-Driver-Frameworks)的源代码,有一个名为FxObjectHandleAlloc的函数,其中传入了“size”的参数。有注释提到size是由编译器。它在 fxobject.hpp 内的函数宏中使用了重载的 new 运算符。
    • 我从来没有得到改变来挖掘调试器来验证这确实是问题,因为它需要很长时间才能完成设置。但是在 FxObjectHandleAlloc 内部的其他故障点中,这是我唯一可以看到它失败的地方。在该函数中,它调用 FxPoolAllocateWithTag 最终调用 wdfpool.cpp 内部的 FxPoolAllocator,该函数在大小 == 0 时失败,或者在这些 Rtl* 函数的输出失败,我无法查看其源代码。无论出于何种原因让编译器传入 0 是我能想到的唯一会使其失败的事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    • 2020-08-01
    相关资源
    最近更新 更多