WdfDeviceCreate() and STATUS_INVALID_DEVICE_STATE

I’m converting a WDM driver to WDF (KMDF), but have run into a snag with my WdfDeviceCreate() calls. I currently one and only one active WdfDeviceCreate() call in all of my driver, under the EvtDeviceAdd() callback, but it fails every time with the status STATUS_INVALID_DEVICE_STATE (0xC0000184). I’m led by the WdfDeviceCreate() reference page to believe this is caused because “…the driver has already created a device object for the device”. I’m very puzzled. Frankly, I had this code fragment working until I modified my DEVICE_EXTENSION, but I don’t think that’s why it’s failing, as I swapped out the old for the new, and problem remains.

That said, I’m wondering what the framework might be keying off to return this status? I.e. are there other conditions which would yield this status?

Code snippet that is attached is very unremarkable for its generic nature,
hence my extreme puzzlement.

Thanks very much in advance for any help or suggestions.
Mike

NTSTATUS

EvtDeviceAdd(IN WDFDRIVER Driver, IN PWDFDEVICE_INIT DeviceInit)

WDF_OBJECT_ATTRIBUTES attrib;

NTSTATUS status;

WDFDEVICE device;

DEVICE_EXTENSION *p_fdo;

WDF_PNPPOWER_EVENT_CALLBACKS callbacks;

UNREFERENCED_PARAMETER(Driver);

PAGED_CODE ();

WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&callbacks);

callbacks.EvtDevicePrepareHardware = EvtPrepareHardware;

callbacks.EvtDeviceReleaseHardware = EvtReleaseHardware;

callbacks.EvtDeviceD0Entry = EvtDeviceD0Entry;

callbacks.EvtDeviceD0Exit = EvtDeviceD0Exit;

WdfDeviceInitSetPnpPowerEventCallbacks( DeviceInit, &callbacks );

WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN);

WdfDeviceInitSetExclusive(DeviceInit, FALSE);

WDF_OBJECT_ATTRIBUTES_INIT(&attrib);

WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, DEVICE_EXTENSION);

status = WdfDeviceCreate(DeviceInit, &attrib, &device);

if (!NT_SUCCESS(status))

{

DbgPrint,(“WdfDeviceCreate failed with 0x%x\n”, status);

return status; //failure path…

}

// success path…

PS [Sorry if this posting is a duplicate. My first posting late on
6/15/2009 didn’t appear on two updates from NtDev].

Run

!wdfkd.wdflogdump (your driver name)

And it will tell you what is going wrong

d

Sent from my phone with no t9, all spilling mistakes are not intentional.

-----Original Message-----
From: xxxxx@schange.com
Sent: Tuesday, June 16, 2009 5:28 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] WdfDeviceCreate() and STATUS_INVALID_DEVICE_STATE

I’m converting a WDM driver to WDF (KMDF), but have run into a snag with my WdfDeviceCreate() calls. I currently one and only one active WdfDeviceCreate() call in all of my driver, under the EvtDeviceAdd() callback, but it fails every time with the status STATUS_INVALID_DEVICE_STATE (0xC0000184). I’m led by the WdfDeviceCreate() reference page to believe this is caused because “…the driver has already created a device object for the device”. I’m very puzzled. Frankly, I had this code fragment working until I modified my DEVICE_EXTENSION, but I don’t think that’s why it’s failing, as I swapped out the old for the new, and problem remains.

That said, I’m wondering what the framework might be keying off to return this status? I.e. are there other conditions which would yield this status?

Code snippet that is attached is very unremarkable for its generic nature,
hence my extreme puzzlement.

Thanks very much in advance for any help or suggestions.
Mike

NTSTATUS

EvtDeviceAdd(IN WDFDRIVER Driver, IN PWDFDEVICE_INIT DeviceInit)





WDF_OBJECT_ATTRIBUTES attrib;

NTSTATUS status;

WDFDEVICE device;

DEVICE_EXTENSION *p_fdo;

WDF_PNPPOWER_EVENT_CALLBACKS callbacks;

UNREFERENCED_PARAMETER(Driver);

PAGED_CODE ();

WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&callbacks);

callbacks.EvtDevicePrepareHardware = EvtPrepareHardware;

callbacks.EvtDeviceReleaseHardware = EvtReleaseHardware;

callbacks.EvtDeviceD0Entry = EvtDeviceD0Entry;

callbacks.EvtDeviceD0Exit = EvtDeviceD0Exit;

WdfDeviceInitSetPnpPowerEventCallbacks( DeviceInit, &callbacks );

WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN);

WdfDeviceInitSetExclusive(DeviceInit, FALSE);

WDF_OBJECT_ATTRIBUTES_INIT(&attrib);

WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, DEVICE_EXTENSION);

status = WdfDeviceCreate(DeviceInit, &attrib, &device);

if (!NT_SUCCESS(status))

{

DbgPrint,(“WdfDeviceCreate failed with 0x%x\n”, status);

return status; //failure path…

}





// success path…



PS [Sorry if this posting is a duplicate. My first posting late on
6/15/2009 didn’t appear on two updates from NtDev].


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

xxxxx@schange.com wrote:

I’m converting a WDM driver to WDF (KMDF), but have run into a snag with my WdfDeviceCreate() calls. I currently one and only one active WdfDeviceCreate() call in all of my driver, under the EvtDeviceAdd() callback, but it fails every time with the status STATUS_INVALID_DEVICE_STATE (0xC0000184). I’m led by the WdfDeviceCreate() reference page to believe this is caused because “…the driver has already created a device object for the device”. I’m very puzzled. Frankly, I had this code fragment working until I modified my DEVICE_EXTENSION, but I don’t think that’s why it’s failing, as I swapped out the old for the new, and problem remains.

Do you have any IoCreateDevice calls left over in your WDM code?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

>Doron Holan

Run !wdfkd.wdflogdump (your driver name) And it will tell you what is going wrong

Thanks, Doron. That’s a good suggestion. Afterwards, I read your posting about setting up for wdf logging. For some reason my KMDF V1.7 symbols or some other setting is not matching up, although I have refreshed my cache for Wdf01000.pdb and setup my symbols, loaded the right architecture’s wdfkd.dll and set the appropriate .tmf. The target is 64 bits, but I checked from both 32 and 64 bit windbg hosts, just to ensure that it wasn’t a translation problem. I see the following error output:

!EvtDeviceAdd+0xbc:
fffffadb575997bc 488d059dfbffff lea rax,[MCIDrv!EvtPrepareHardware (fffffadb57599360)]
3: kd> !wdflogdump mcidrv
Trace searchpath is:

Trace format prefix is: %7!u!: %!FUNC! -
TMF file used for formatting IFR log is: d:\aps\nt\winddk\6001.18002\Tools\tracing\i386\wdf01007.tmf
Log at fffffadff96ad000
Gather log: Please wait, this may take a moment (reading 4024 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.

After reading a number of the MSDN blogs and Osr postings, I gather that this is really basic KMDF debugger extension stuff, but I’ve got to be missing something glaringly obvious. I also went back an reinstalled the 6001.18002 on my 32 bit windbg host to ensure it wasn’t that.

Tim Roberts
Do you have any IoCreateDevice calls left over in your WDM code?

Thanks, Tim. Good point, but no, I’ve removed all my old IoCreateDevice call instances in my newest build where WdfDeviceCreate() is failing with the STATUS_INVALID_DEVICE_STATE - I just verified.

Thanks again for all your help.

-Mike

What OS are you testing on? what is your .sympath?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@schange.com
Sent: Tuesday, June 16, 2009 11:24 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WdfDeviceCreate() and STATUS_INVALID_DEVICE_STATE

Doron Holan
Run !wdfkd.wdflogdump (your driver name) And it will tell you what is
going wrong

Thanks, Doron. That’s a good suggestion. Afterwards, I read your posting about setting up for wdf logging. For some reason my KMDF V1.7 symbols or some other setting is not matching up, although I have refreshed my cache for Wdf01000.pdb and setup my symbols, loaded the right architecture’s wdfkd.dll and set the appropriate .tmf. The target is 64 bits, but I checked from both 32 and 64 bit windbg hosts, just to ensure that it wasn’t a translation problem. I see the following error output:

!EvtDeviceAdd+0xbc:
fffffadb575997bc 488d059dfbffff lea rax,[MCIDrv!EvtPrepareHardware (fffffadb57599360)]
3: kd> !wdflogdump mcidrv
Trace searchpath is:

Trace format prefix is: %7!u!: %!FUNC! - TMF file used for formatting IFR log is: d:\aps\nt\winddk\6001.18002\Tools\tracing\i386\wdf01007.tmf
Log at fffffadff96ad000
Gather log: Please wait, this may take a moment (reading 4024 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.

After reading a number of the MSDN blogs and Osr postings, I gather that this is really basic KMDF debugger extension stuff, but I’ve got to be missing something glaringly obvious. I also went back an reinstalled the 6001.18002 on my 32 bit windbg host to ensure it wasn’t that.

Tim Roberts
Do you have any IoCreateDevice calls left over in your WDM code?

Thanks, Tim. Good point, but no, I’ve removed all my old IoCreateDevice call instances in my newest build where WdfDeviceCreate() is failing with the STATUS_INVALID_DEVICE_STATE - I just verified.

Thanks again for all your help.

-Mike


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Before I forget:

(1) .sympath
Symbol search path is: SRV*C:\WEBSymbols*http://msdl.microsoft.com/download/symbols;k:\symbols\x64

Where k:\symbols\x64 = my remote system’s private symbol path for a 64 bit image / target system.

(2) Wdf01000 info

#: kd> lm m wdf01000 v
start end module name
fffffadb57c7a000 fffffadb57d54000 wdf01000 (pdb symbols) C:\WEBSymbols\Wdf01000.pdb\33BD5E6301CC4C5B9A8FBC23605E1A4D1\Wdf01000.pdb
Loaded symbol image file: wdf01000.sys
Image path: wdf01000.sys
Image name: wdf01000.sys
Timestamp: Sat Jan 19 01:33:27 2008 (479199B7)
CheckSum: 000DBD8F
ImageSize: 000DA000
Translations: 0000.04b0 0000.04e4 0409.04b0 0409.04e4

Thanks, Doran -
(1) From WinMsd:

OS Name Microsoft(R) Windows(R) Server 2003 Standard x64 Edition
Version 5.2.3790 Service Pack 2 Build 3790

(2) Sympath
Symbol search path is: SRV*C:\WEBSymbols*http://msdl.microsoft.com/download/symbols;k:\symbols\x64

Does !lmi wdf01000 show that the symbols were loaded for wdf? Also, does !lmi show that private symbols were loaded for your driver?

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@schange.com
Sent: Tuesday, June 16, 2009 12:01 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WdfDeviceCreate() and STATUS_INVALID_DEVICE_STATE

Before I forget:

(1) .sympath
Symbol search path is: SRVC:\WEBSymbolshttp://msdl.microsoft.com/download/symbols;k:\symbols\x64

Where k:\symbols\x64 = my remote system’s private symbol path for a 64 bit image / target system.

(2) Wdf01000 info

#: kd> lm m wdf01000 v
start end module name
fffffadb57c7a000 fffffadb57d54000 wdf01000 (pdb symbols) C:\WEBSymbols\Wdf01000.pdb\33BD5E6301CC4C5B9A8FBC23605E1A4D1\Wdf01000.pdb
Loaded symbol image file: wdf01000.sys
Image path: wdf01000.sys
Image name: wdf01000.sys
Timestamp: Sat Jan 19 01:33:27 2008 (479199B7)
CheckSum: 000DBD8F
ImageSize: 000DA000
Translations: 0000.04b0 0000.04e4 0409.04b0 0409.04e4


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Doron, (sorry for my misspelling your name in my previous msg),

Yes, lmi shows that the symbols for wdf01000 and myDriver are loaded.
fffffadb57d1a000 fffffadb57df4000 wdf01000 (pdb symbols) wdf01000.sys
fffffadb57df4000 fffffadb57e40000 myDriver (private pdb symbols) MYDRIVER.SYS

I modified my MyDriver\parameters\Wdf registry as follows:
WDF Verifier settings for MYDRIVER.sys is ON
Pool tracking is ON
Handle verification is ON
IO verification is ON
Lock verification is ON
Device state verification is OFF
Handle reference tracking is OFF

And my logging shows more. I’m puzzled why this should make a difference, as I don’t recall seeing this in the list of preparation steps for Wdflogdump.

3: kd> !wdflogdump myDriver
Trace searchpath is:

Trace format prefix is: %7!u!: %!FUNC! -
TMF file used for formatting IFR log is: c:\aps\nt\winddk\6001.18002\tools\tracing\amd64\wdf01007.tmf
Log at fffffadff960e000
Gather log: Please wait, this may take a moment (reading 4024 bytes).
% read so far … 100
There are 2 log entries
— start of log —
1: FxInitialize - Initializing Pool 0xF960FEC8, Tracking -1313
2: FxDriver::AddDevice - Enter AddDevice PDO 6FF5BB70
---- end of log ----

After the WdfDeviceCreate() call.

3: kd> !wdflogdump myDriver
Trace searchpath is:

Trace format prefix is: %7!u!: %!FUNC! -
TMF file used for formatting IFR log is: c:\aps\nt\winddk\6001.18002\tools\tracing\amd64\wdf01007.tmf
Log at fffffadff960e000
Gather log: Please wait, this may take a moment (reading 4024 bytes).
% read so far … 100
There are 3 log entries
— start of log —
1: FxInitialize - Initializing Pool 0xF960FEC8, Tracking -1313
2: FxDriver::AddDevice - Enter AddDevice PDO 6FF5BB70
3: imp_WdfDeviceCreate - WDFDEVICE 0x5B6E8170 already createdSTATUS_INVALID_DEVICE_STATE
---- end of log ----

Dumping the PDO is a non-starter, as the debugger extension balks:

kd> !wdfdevice 0x6FF5BD40 0x1f
c0000005 Exception in c:\aps\nt\winddk\6001.18002\bin\amd64\wdfkd.dll.wdfdevice debugger extension.
PC: 0000000002800fc5 VA: 0000000000000000 R/W: 0 Parameter: 00000000`00000000

I’ll be able to check back and post later this evening (EST). Appreciate all the help.

Mike

It appears you called WdfDeviceCreate twice or somehow cached a PWDFDEVICE_INIT that was stale (maybe in a global?)

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@schange.com
Sent: Tuesday, June 16, 2009 1:10 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WdfDeviceCreate() and STATUS_INVALID_DEVICE_STATE

Doron, (sorry for my misspelling your name in my previous msg),

Yes, lmi shows that the symbols for wdf01000 and myDriver are loaded.
fffffadb57d1a000 fffffadb57df4000 wdf01000 (pdb symbols) wdf01000.sys
fffffadb57df4000 fffffadb57e40000 myDriver (private pdb symbols) MYDRIVER.SYS

I modified my MyDriver\parameters\Wdf registry as follows:
WDF Verifier settings for MYDRIVER.sys is ON
Pool tracking is ON
Handle verification is ON
IO verification is ON
Lock verification is ON
Device state verification is OFF
Handle reference tracking is OFF

And my logging shows more. I’m puzzled why this should make a difference, as I don’t recall seeing this in the list of preparation steps for Wdflogdump.

3: kd> !wdflogdump myDriver
Trace searchpath is:

Trace format prefix is: %7!u!: %!FUNC! - TMF file used for formatting IFR log is: c:\aps\nt\winddk\6001.18002\tools\tracing\amd64\wdf01007.tmf
Log at fffffadff960e000
Gather log: Please wait, this may take a moment (reading 4024 bytes).
% read so far … 100
There are 2 log entries
— start of log —
1: FxInitialize - Initializing Pool 0xF960FEC8, Tracking -1313
2: FxDriver::AddDevice - Enter AddDevice PDO 6FF5BB70
---- end of log ----

After the WdfDeviceCreate() call.

3: kd> !wdflogdump myDriver
Trace searchpath is:

Trace format prefix is: %7!u!: %!FUNC! - TMF file used for formatting IFR log is: c:\aps\nt\winddk\6001.18002\tools\tracing\amd64\wdf01007.tmf
Log at fffffadff960e000
Gather log: Please wait, this may take a moment (reading 4024 bytes).
% read so far … 100
There are 3 log entries
— start of log —
1: FxInitialize - Initializing Pool 0xF960FEC8, Tracking -1313
2: FxDriver::AddDevice - Enter AddDevice PDO 6FF5BB70
3: imp_WdfDeviceCreate - WDFDEVICE 0x5B6E8170 already createdSTATUS_INVALID_DEVICE_STATE
---- end of log ----

Dumping the PDO is a non-starter, as the debugger extension balks:

kd> !wdfdevice 0x6FF5BD40 0x1f
c0000005 Exception in c:\aps\nt\winddk\6001.18002\bin\amd64\wdfkd.dll.wdfdevice debugger extension.
PC: 0000000002800fc5 VA: 0000000000000000 R/W: 0 Parameter: 00000000`00000000

I’ll be able to check back and post later this evening (EST). Appreciate all the help.

Mike


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>It appears you called WdfDeviceCreate twice or somehow cached a >PWDFDEVICE_INIT that was stale (maybe in a global?)

It’s entirely possible on the latter. I’ll do some more checking and make another post tomorrow AM. Just curious, is there any other way that WdfDeviceCreate() could fail with the STATUS_INVALID_DEVICE_STATE?

One other note if it helps. Earlier on I had also tried converting an old IoCreateDevice() to a WdfDeviceCreate() in DriverEntry(). This WdfDeviceCreate() also had failed with STATUS_INVALID_DEVICE_STATE using a fresh PWDFDEVICE_INIT that was created by a WdfControlDeviceInitAllocate() call. (This call in DriverEntry() is currently disabled - I verified that it is not executing, so it isn’t causing the failure in my EvtDeviceAdd() callback.)

As always, much appreciate your help. I’m familiar with WDM, but just learning KMDF. —Mike

!wdfkd.wdflogdump is pretty specific here, we may have mult paths returning the same error code, but each of those paths will place a different entry into the log to differentiate when debugging.

d

Sent from my phone with no t9, all spilling mistakes are not intentional.

-----Original Message-----
From: xxxxx@schange.com
Sent: Tuesday, June 16, 2009 9:03 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WdfDeviceCreate() and STATUS_INVALID_DEVICE_STATE

>It appears you called WdfDeviceCreate twice or somehow cached a >PWDFDEVICE_INIT that was stale (maybe in a global?)

It’s entirely possible on the latter. I’ll do some more checking and make another post tomorrow AM. Just curious, is there any other way that WdfDeviceCreate() could fail with the STATUS_INVALID_DEVICE_STATE?

One other note if it helps. Earlier on I had also tried converting an old IoCreateDevice() to a WdfDeviceCreate() in DriverEntry(). This WdfDeviceCreate() also had failed with STATUS_INVALID_DEVICE_STATE using a fresh PWDFDEVICE_INIT that was created by a WdfControlDeviceInitAllocate() call. (This call in DriverEntry() is currently disabled - I verified that it is not executing, so it isn’t causing the failure in my EvtDeviceAdd() callback.)

As always, much appreciate your help. I’m familiar with WDM, but just learning KMDF. —Mike


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Good catch. You nailed it. I happened to notice that the DeviceInit pointer went zero after a successfull WdfDeviceCreate() call in my older copy of the driver, but for now obvious reasons it did not in my newer driver.

I’m rather embarassed that I was blind to this one character difference in my source control for some reason; it’s all about assumptions. I assumed the differences were due to spaces or tabs - I was wrong.

I specified:
status = WdfDeviceCreate(DeviceInit, &attributes, &device);

But I should have specified:

status = WdfDeviceCreate(&DeviceInit, &attributes, &device);

As you and other diligent OSR contributors and readers well know, WdfDeviceCreate takes as it’s first parameter: PWDFDEVICE_INIT* DeviceInit. I missed this on repeated readings.

Doron - thanks very much for your patience and diligence in helping me find and fix the root cause.

Tim - thanks also for your hints on IoCreateDevice(). It’s a good reminder to me and to us all.

Best,

Mike

I am surprised that this even compiled, this is a type mismatch for which their is no implicit conversion. What warning level are you using?

d

Sent from my phone with no t9, all spilling mistakes are not intentional.

-----Original Message-----
From: xxxxx@schange.com
Sent: Wednesday, June 17, 2009 7:26 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WdfDeviceCreate() and STATUS_INVALID_DEVICE_STATE

Good catch. You nailed it. I happened to notice that the DeviceInit pointer went zero after a successfull WdfDeviceCreate() call in my older copy of the driver, but for now obvious reasons it did not in my newer driver.

I’m rather embarassed that I was blind to this one character difference in my source control for some reason; it’s all about assumptions. I assumed the differences were due to spaces or tabs - I was wrong.

I specified:
status = WdfDeviceCreate(DeviceInit, &attributes, &device);

But I should have specified:

status = WdfDeviceCreate(&DeviceInit, &attributes, &device);

As you and other diligent OSR contributors and readers well know, WdfDeviceCreate takes as it’s first parameter: PWDFDEVICE_INIT* DeviceInit. I missed this on repeated readings.

Doron - thanks very much for your patience and diligence in helping me find and fix the root cause.

Tim - thanks also for your hints on IoCreateDevice(). It’s a good reminder to me and to us all.

Best,

Mike


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>I am surprised that this even compiled, this is a type mismatch for which their is no implicit conversion. What warning level are you using?

\W4 - I’m puzzled as well. --Mike