To further emphasize the importance of *when* convert the handle to a pointer, let me explain how the request pipe line works. By the time a WDFQUEUE related callback is invoked, you are no longer guaranteed to be in the context of the calling process. This is especially true if the request arrives to a power managed queue and the device is currently not in D0. The request will only be presented when the device is in D0 which will be in some other thread context.
EvtIoInCallerContext is guaranteed to be in the caller’s context, but there are no other guarantees. For instance, there is no guarantee about device power state at the time the function is called nor is there a guarantee that the top level queue which will process the event is even dispatching (note that you are not passed a WDFQUEUE, rather your WDFDEVICE). The only thing you should do in this callback is map Xxx (be it a handle, raw UM pointers, etc) from the caller’s context to your driver’s/request’s context area.
d
– I can spell, I just can’t type.
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, February 22, 2006 7:15 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] ObReferenceObjectByHandle fails when device is not in D0 state
It has nothing to do with D0 state.? It has everything to do with *when* you can ObReferenceObjectByHandle.
?
You should *not* store the handle in you data structures, and then use ObReferenceObjectByHandle when you feel like interacting with the handle.? The reason is that you have no idea what process context you’ll be running in, and ObReferenceObjectByHandle operates on the handle table of the current process.? (Note: There are exceptions for kernel handles, but they do not apply here.)
?
You *should* call ObReferenceObjectByHandle in IRP_MJ_DEVICE_CONTROL dispatch handler, and store the *pointer* to the device in your data structures.? This pointer is guaranteed to be valid in all process contexts, since it points directly to the object.? Then, when you are done using the pointer, you should call ObDereferenceObject.? Otherwise, the object will never be released.
?
– arlie
?
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Alex Farber
Sent: Wednesday, February 22, 2006 1:28 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] ObReferenceObjectByHandle fails when device is not in D0 state
Doron, from your answer I understand that I cannot be sure that ObReferenceObjectByHandle? will allways succeed even if device is in D0 state. I will try to implement EvtIoInCallerContext context, thank you very much for information.
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com