Search code examples
windowskmdfwdf

KMDF WdfDriverCreate function returns "insufficient resources"


I'm trying to write a kmdf driver to target a custom PCIe board. On following the default project that Microsoft provides, I made a few minor changes to the .inf file, mainly changing the names of strings and providing the hardware ID of our PCIe board.

Deploying the driver works as it should. The driver installs and shows up on the device manager, but it says that it didn't install correctly or it may be corrupted.

On debugging, I see that WdfDriverCreate fails with an error of 0xC000009A, which means insufficient resources.

For reference, this is the generated code that the kmdf template project makes for you, which is what I am currently running:

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;
}

My first question is, What would cause this?

I attempted to dump a log after the error is raised by running

!wdfkd.wdflogdump mydriver.sys

But it never works. I ensured that all symbol paths are loaded properly, as shown below

    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

Where "CIPDriver" is my driver.

On running the dump command, this is the output:

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.

And the output of .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

Where C:\winsymbols is a cache of Microsofts's symbols which I acquired by following the guide here: https://msdn.microsoft.com/en-us/library/windows/hardware/ff558829(v=vs.85).aspx

My second question is, how do I correctly setup the debugger to dump out the logs?

Thanks


Solution

  • I don't quite understand why this helps, but if I turned off KMDF verifier under

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

    And deploy the driver, it works. If I turn that on, it fails. I deployed my driver a few times toggling that option on and off and it always fails when it's on.

    I posted this question along with my findings. Maybe someone there could answer why this is the case: https://www.osronline.com/showthread.cfm?link=277793