Would you please also attach the call-stack of the place where you call delete on the memory object?
Thanks,
Praveen
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Monday, May 11, 2009 6:42 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDFMEMORY - Why are EvtCleanupCallback and EvtDestroyCallback deferred to PASSIVE_LEVEL?
Praveen,
Details below.
-dave
The WDFMEMORY is a 'preallocated' type parented by a WDFDEVICE.
Memory was allocated with:
NTSTATUS ntStatus;
WDFMEMORY memory;
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes,
MY_MEM_CONTEXT);
attributes.ParentObject =
WdfObjectContextGetObject(DeviceContext);
attributes.EvtCleanupCallback = EvtMemContextCleanup;
attributes.EvtDestroyCallback = EvtMemContextDestroy;
ntStatus = WdfMemoryCreatePreallocated(
&attributes,
DeviceContext->ScratchBlock,
sizeof(DeviceContext->ScratchBlock),
&memory
);
In the above snippet DeviceContext is a WDF Object Context of a WDFDEVICE
object.
The call to WdfObjectDelete() on the memory occurs explicitly.
The parent object (the WDFDEVICE) is not being deleted at this time.
1: kd> !wdfkd.wdfmemory @@(Memory)
WDFMEMORY 0x7aa4b540: Buffer 0x88047200, Length 0x100 (256) bytes
1: kd> !wdfkd.wdfhandle @@(Memory)
Dumping WDFHANDLE 0x7aa4b540
Handle type is WDFMEMORY
Refcount: 1
Contexts:
context: dt 0x855b4b10 CW_TXCMD_CONTEXT (size is 0x90 bytes)
EvtCleanupCallback 96fc45d0 mydrv!EvtMemContextCleanup
EvtDestroyCallback 96fc4700 mydrv!EvtMemContextDestroy
Owning device: !wdfdevice 0x7aaf5ff8
1: kd> !wdfdevice 0x7aaf5ff8
Dumping WDFDEVICE 0x7aaf5ff8
WDM PDEVICE_OBJECTs:self 85577190, attached 84140360, pdo 84140360
Pnp state: 119 ( WdfDevStatePnpStarted )
Power state: 307 ( WdfDevStatePowerD0 )
Power Pol state: 565 ( WdfDevStatePwrPolStarted )
Default WDFIOTARGET: 7aa495e0
No pended pnp or power irps
Device is the power policy owner for the stack
Stack at time of EvtMemContextCleanup :
1: kd> k
ChildEBP RetAddr
83373c8c 807bfa7c mydrv!EvtMemContextCleanup
83373ca0 807c1530 Wdf01000!FxObject::CallCleanupCallbacks+0x39
83373cb4 807c1687 Wdf01000!FxObject::DisposeChildrenWorker+0x17f
83373cd8 807a9692 Wdf01000!FxObject::DeferredDisposeWorkItem+0xba
83373cf4 807a96cb Wdf01000!FxDisposeList::DrainListLocked+0x5d
83373d04 807a4f06 Wdf01000!FxDisposeList::_WorkItemThunk+0x1f
83373d24 807a4f69 Wdf01000!FxSystemWorkItem::WorkItemHandler+0x7a
83373d30 8183130b Wdf01000!FxSystemWorkItem::_WorkItemThunk+0x10
83373d44 8164d445 nt!IopProcessWorkItem+0x23
83373d7c 817eab18 nt!ExpWorkerThread+0xfd
83373dc0 81643a2e nt!PspSystemThreadStartup+0x9d
00000000 00000000 nt!KiThreadStartup+0x16
Stack at time of EvtMemContextDestroy:
1: kd> k
ChildEBP RetAddr
83373c68 807c0dab mydrv!EvtMemContextDestroy+0x8
83373c8c 80782f40 Wdf01000!FxObject::ProcessDestroy+0x6b
83373c9c 807c0f1c Wdf01000!FxObject::Release+0x42
83373cb8 807c1693 Wdf01000!FxObject::DeletedAndDisposedWorkerLocked+0xb2
83373cd8 807a9692 Wdf01000!FxObject::DeferredDisposeWorkItem+0xc6
83373cf4 807a96cb Wdf01000!FxDisposeList::DrainListLocked+0x5d
83373d04 807a4f06 Wdf01000!FxDisposeList::_WorkItemThunk+0x1f
83373d24 807a4f69 Wdf01000!FxSystemWorkItem::WorkItemHandler+0x7a
83373d30 8183130b Wdf01000!FxSystemWorkItem::_WorkItemThunk+0x10
83373d44 8164d445 nt!IopProcessWorkItem+0x23
83373d7c 817eab18 nt!ExpWorkerThread+0xfd
83373dc0 81643a2e nt!PspSystemThreadStartup+0x9d
00000000 00000000 nt!KiThreadStartup+0x16
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Rao
Sent: Monday, May 11, 2009 7:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDFMEMORY - Why are EvtCleanupCallback and
EvtDestroyCallback deferred to PASSIVE_LEVEL?
I tried this and that is not what I see.
I see EvtCleanup/Destroy invoked at dispatch level for NonPagedPool memory
objects and for pre-allocated memory objects. (We need to clarify this in
the docs that passive level is forced only for paged memory objects.)
I can think of someone in the hierarchy that you are trying to delete
needing passive cleanup/destroy causing this. Destroy can additionally get
deferred because of a ref-count. But if you deleting the object itself and
it has no children then this shouldn't happen.
Maybe if you post the complete call-stack for EvtCleanup/Destroy that would
give us some clue.
Thanks,
Praveen
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Monday, May 11, 2009 1:59 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDFMEMORY - Why are EvtCleanupCallback and
EvtDestroyCallback deferred to PASSIVE_LEVEL?
Praveen,
Nope. The WDFMEMORY objects have NonPagedPool specified or they are created
from 'pre-allocated' memory.
Does PASSIVE_LEVEL cleanup/destroy get selected for
WdfMemoryCreatePreallocated() allocated WDFMEMORY objects?
Thanks,
-dave
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Rao
Sent: Monday, May 11, 2009 4:40 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDFMEMORY - Why are EvtCleanupCallback and
EvtDestroyCallback deferred to PASSIVE_LEVEL?
David,
Cleanup/Destroy callbacks should be forced at passive level only for paged
pool memory objects.
Was the pool type NonPagedPool for memory objects in your case, and did you
still get callbacks invoked only at passive level?
Thanks,
Praveen
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of David R. Cattley
Sent: Saturday, May 09, 2009 1:08 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDFMEMORY - Why are EvtCleanupCallback and
EvtDestroyCallback deferred to PASSIVE_LEVEL?
Deleting the object itself.
The WDFMEMORY is parented by a WDFDEVICE (an FDO).
Attributes are otherwise defaulted (except for the cleanup/destroy callback
and the context type).
Based on WDK docs for the cleanup/destroy callbacks on WDFMEMORY are always
called at PASSIVE_LEVEL.
The framework is operating as documented and other than my failing to
understand the reason for the deferment, there is no problem here. The
object(s) do get the callbacks on a work item managed internal to the
framework. I was just expecting (that is, before I read the fine print in
the WDK docs) that when I called WdfObjectDelete() on the WDFMEMORY that it
would trigger cleanup/deletion *then*.
Thanks,
-dave
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Saturday, May 09, 2009 3:53 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDFMEMORY - Why are EvtCleanupCallback and
EvtDestroyCallback deferred to PASSIVE_LEVEL?
Are you deleting the object itself or a parent object? If an ancestor
object, what does the hierarchy look like?
d
Sent from my phone with no t9, all spilling mistakes are not intentional.
From: David R. Cattley
Sent: Saturday, May 09, 2009 11:52 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] WDFMEMORY - Why are EvtCleanupCallback and
EvtDestroyCallback deferred to PASSIVE_LEVEL?
Out of curiosity, what was the backing rational for deferring WDFMEMORY
cleanup/destroy to passive level? I feel I may be missing some fundamental
understanding of WDFMEMORY lifetime as I would have expected that
DISPATCH_LEVEL cleanup & destruction of WDFMEMORY objects would have been
permissible since they may be allocated at DISPATCH_LEVEL.
Thanks,
Dave Cattley
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
OSR Seminars – OSR
To unsubscribe, visit the List Server section of OSR Online at
ListServer/Forum
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
OSR Seminars – OSR
To unsubscribe, visit the List Server section of OSR Online at
ListServer/Forum
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
OSR Seminars – OSR
To unsubscribe, visit the List Server section of OSR Online at
ListServer/Forum
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
OSR Seminars – OSR
To unsubscribe, visit the List Server section of OSR Online at
ListServer/Forum
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
OSR Seminars – OSR
To unsubscribe, visit the List Server section of OSR Online at
ListServer/Forum
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
OSR Seminars – OSR
To unsubscribe, visit the List Server section of OSR Online at
ListServer/Forum
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
OSR Seminars – OSR
To unsubscribe, visit the List Server section of OSR Online at
ListServer/Forum
---
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
OSR Seminars – OSR
To unsubscribe, visit the List Server section of OSR Online at ListServer/Forum