Hello!
I’m having trouble with a seemingly trivial WDF task. I want to create a
work item, but when calling WdfWorkItemCreate I get a blue screen. The code I use to create the work item looks like this:
struct ReadWorkerContext
{
WDFIOTARGET SerialPort;
ReadMessageContext* ReadMessageContext;
};
VOID ReadWorker(WDFWORKITEM WorkItem)
{
ReadWorkerContext* readWorkerContext = GetReadWorkerContext(WorkItem);
CreateAndSendReadRequest(readWorkerContext->SerialPort,
readWorkerContext->ReadMessageContext);
WdfObjectDelete(WorkItem);
}
NTSTATUS CreateReadWorker(WDFIOTARGET SerialPort, ReadMessageContext* ReadMessageContext)
{
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.ParentObject = WdfIoTargetGetDevice(SerialPort);
WDF_WORKITEM_CONFIG config;
WDF_WORKITEM_CONFIG_INIT(&config, ReadWorker);
WDFWORKITEM workItem ;
NTSTATUS status = WdfWorkItemCreate(&config, &attributes, &workItem);
TDS_CHECK_STATUS(status, “could not create work item”);
WdfWorkItemEnqueue(workItem);
return STATUS_SUCCESS;
}
I would think that this would be very straight forward. However, I get a blue screen when WdfWorkItemCreate is called. Loading the memory dump in WinDbg I get this information:
[snip]
BugCheck 7E, {80000003, 80526fbc, f9df3614, f9df3310}
*** No owner thread found for resource 80551360
*** No owner thread found for resource 80551360
*** No owner thread found for resource 80551360
*** No owner thread found for resource 80551360
Probably caused by : Wdf01000.sys ( Wdf01000!FxObject::_GetEffectiveLock+87 )
[snip]
STACK_TEXT:
f9df36d8 f74d0366 8167c4a8 f750d7ac f9df3794 nt!DbgBreakPoint
f9df36ec f74dacb9 81144880 811448b4 00000003 Wdf01000!FxObject::_GetEffectiveLock+0x87
f9df3724 f74daefa f9df3794 f9df37b8 f9df37b4 Wdf01000!FxWorkItem::Initialize+0x86
f9df3740 f74bd1c0 816981a8 f9df37b8 f9df3794 Wdf01000!FxWorkItem::Create+0x4b
f9df3764 f9cbcb9d 816981a8 f9df37b8 f9df3794 Wdf01000!imp_WdfWorkItemCreate+0x483
f9df377c f9cbcf4c f9df37b8 f9df3794 f9df37b4 hello!WdfWorkItemCreate+0x1d [c:\winddk\6000\inc\wdf\kmdf\10\wdfworkitem.h @ 98]
f9df37c4 f9cbd212 7eb2e220 817abd48 81144a48 hello!`anonymous namespace’::CreateReadWorker+0x3c [c:\source\hypercom\message.cpp @ 128]
f9df3808 f9cbfe10 7eebb778 00000000 003f005c hello!StartMessageReading+0xb2 [c:\source\hypercom\message.cpp @ 208]
f9df3920 f74f707c 7eebb778 7e7e1c50 7e7cd4a8 hello!UsbSamp_EvtDevicePrepareHardware+0x210 [c:\source\hypercom\device.cpp @ 313]
f9df3940 f74f73ae f9df395b 00000008 8111a048 Wdf01000!FxPkgPnp::PnpPrepareHardware+0x7c
f9df395c f74f6245 8111a048 f750f260 8111a048 Wdf01000!FxPkgPnp::PnpEventHardwareAvailable+0x6f
f9df3984 f74f6fa0 00000108 8111a0e8 8111a048 Wdf01000!FxPkgPnp::PnpEnterNewState+0x15c
[snip]
Does anyone here have any ideas as to why this doesn’t work? =)
I have verified that the SerialPort handle has the same value as when it was created with WdfIoTargetCreate. I have also verified that the handle returned by WdfIoTargetGetDevice has the same value as the WDFDEVICE handle passed to EvtDevicePrepareHardware.
Any input on this would be greatly appreciated!
Regards,
Mattias