WDFMEMORY and associated buffer

I haven't been able to find this in the docs or on the web, maybe I haven't
searched using the right terms. If I use WdfMemoryCreateFromLookaside(),
then WdfMemoryGetBuffer() to get a system VA to a buffer I can pass around,
is there a way to get back to the associated WDFMEMORY analogous to the way
you can get to a WDFOBJECT from a context by calling
WdfObjectContextGetObject() on the address of the context?

The workaround is to put a WDFMEMORY in my buffer, and assign it as soon as
I get it the first time, but I'd rather not do that if I don't need to.

Thanks,

Phil

Philip D. Barila
Seagate Technology LLC
(720) 684-1842
As if I need to say it: Not speaking for Seagate.

No, there is no backlink from a system VA pointer back to the owning WDFMEMORY that owns it. Not sure how that would work, I guess KMDF could store the object pointer before system va returned, but that breaks down on PAGE_SIZE or greater allocations since the VA returned is required to be aligned on PAGE_SIZE. KMDF could store it after the system VA, but then it would have to know the size of the memory as well....

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Philip D. Barila
Sent: Tuesday, September 18, 2007 3:50 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] WDFMEMORY and associated buffer

I haven't been able to find this in the docs or on the web, maybe I haven't
searched using the right terms. If I use WdfMemoryCreateFromLookaside(),
then WdfMemoryGetBuffer() to get a system VA to a buffer I can pass around,
is there a way to get back to the associated WDFMEMORY analogous to the way
you can get to a WDFOBJECT from a context by calling
WdfObjectContextGetObject() on the address of the context?

The workaround is to put a WDFMEMORY in my buffer, and assign it as soon as
I get it the first time, but I'd rather not do that if I don't need to.

Thanks,

Phil

Philip D. Barila
Seagate Technology LLC
(720) 684-1842
As if I need to say it: Not speaking for Seagate.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:

To unsubscribe, visit the List Server section of OSR Online at ListServer/Forum

OK, thanks for confirming what I had found. I don't mind keeping the
WDFMEMORY object, since I need to. I just didn't want to do it
unnecessarily.

Entirely for curiosity's sake, how do you do it with contexts? The ways I
imagine it would work with contexts have the same limitations you described
below, so I'm quite curious.

Phil

Philip D. Barila
Seagate Technology LLC
(720) 684-1842
As if I need to say it: Not speaking for Seagate.

"Doron Holan" wrote in message
news:xxxxx@ntdev...
No, there is no backlink from a system VA pointer back to the owning
WDFMEMORY that owns it. Not sure how that would work, I guess KMDF could
store the object pointer before system va returned, but that breaks down on
PAGE_SIZE or greater allocations since the VA returned is required to be
aligned on PAGE_SIZE. KMDF could store it after the system VA, but then it
would have to know the size of the memory as well....

Contexts do not have to be aligned to a PAGE_SIZE boundary if their size is >= PAGE_SIZE so I can always store the object pointer in a header before the context and use CONTAINING_RECORD to get from the context to the header. It looks something like this

struct ContextHeader {
PCWDF_OBJECT_CONTEXT_TYPE_INFO Type;
FxObject* Object;
...
ULONG_PTR Context[1]; <-- the start of your context
}

dt wdf01000!FxContextHeader to see all of its glory

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Philip D. Barila
Sent: Tuesday, September 18, 2007 5:21 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] WDFMEMORY and associated buffer

OK, thanks for confirming what I had found. I don't mind keeping the
WDFMEMORY object, since I need to. I just didn't want to do it
unnecessarily.

Entirely for curiosity's sake, how do you do it with contexts? The ways I
imagine it would work with contexts have the same limitations you described
below, so I'm quite curious.

Phil

Philip D. Barila
Seagate Technology LLC
(720) 684-1842
As if I need to say it: Not speaking for Seagate.

"Doron Holan" wrote in message
news:xxxxx@ntdev...
No, there is no backlink from a system VA pointer back to the owning
WDFMEMORY that owns it. Not sure how that would work, I guess KMDF could
store the object pointer before system va returned, but that breaks down on
PAGE_SIZE or greater allocations since the VA returned is required to be
aligned on PAGE_SIZE. KMDF could store it after the system VA, but then it
would have to know the size of the memory as well....

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

Does that imply that contexts may not be > 4K, or that contexts > 4K fail
the WdfObjectContextGetObject() call? I imagined exactly what you provided
below for the WDFMEMORY buffer, and the snippet below is almost exactly what
you described in your musing about how you would provide the back pointer
for the WDFMEMORY object, and I'm having a hard time seeing any really
significant difference between the two ...

Again, this is strictly for curiosity's sake, I'm not going to dive below
the covers here, just wondering what I'm missing that makes the two so much
more different than I'm seeing.

Thanks for all the insight,

Phil

Philip D. Barila
Seagate Technology LLC
(720) 684-1842
As if I need to say it: Not speaking for Seagate.

"Doron Holan" wrote in message
news:xxxxx@ntdev...
Contexts do not have to be aligned to a PAGE_SIZE boundary if their size is
>= PAGE_SIZE so I can always store the object pointer in a header before the
context and use CONTAINING_RECORD to get from the context to the header. It
looks something like this

struct ContextHeader {
PCWDF_OBJECT_CONTEXT_TYPE_INFO Type;
FxObject* Object;
...
ULONG_PTR Context[1]; <-- the start of your context
}

dt wdf01000!FxContextHeader to see all of its glory

[my intervening reply snipped]

"Doron Holan" wrote in message
news:xxxxx@ntdev...
No, there is no backlink from a system VA pointer back to the owning
WDFMEMORY that owns it. Not sure how that would work, I guess KMDF could
store the object pointer before system va returned, but that breaks down on
PAGE_SIZE or greater allocations since the VA returned is required to be
aligned on PAGE_SIZE. KMDF could store it after the system VA, but then it
would have to know the size of the memory as well....

The system VA returned by a WDFMEMORY must conform to the rules that ExAllocatePool dictates. This basically means anything page size or bigger is guaranteed to be page aligned. This way you can use the buffer from a wdfmemory in pretty much any legacy situation. The contexts on a handle can be any size (I think it is actually limited to ushort_max), including >= page size....we just don't guarantee that the context pointer is page aligned, that's all.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Philip D. Barila
Sent: Tuesday, September 18, 2007 7:06 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:WDFMEMORY and associated buffer

Does that imply that contexts may not be > 4K, or that contexts > 4K fail
the WdfObjectContextGetObject() call? I imagined exactly what you provided
below for the WDFMEMORY buffer, and the snippet below is almost exactly what
you described in your musing about how you would provide the back pointer
for the WDFMEMORY object, and I'm having a hard time seeing any really
significant difference between the two ...

Again, this is strictly for curiosity's sake, I'm not going to dive below
the covers here, just wondering what I'm missing that makes the two so much
more different than I'm seeing.

Thanks for all the insight,

Phil

Philip D. Barila
Seagate Technology LLC
(720) 684-1842
As if I need to say it: Not speaking for Seagate.

"Doron Holan" wrote in message
news:xxxxx@ntdev...
Contexts do not have to be aligned to a PAGE_SIZE boundary if their size is
>= PAGE_SIZE so I can always store the object pointer in a header before the
context and use CONTAINING_RECORD to get from the context to the header. It
looks something like this

struct ContextHeader {
PCWDF_OBJECT_CONTEXT_TYPE_INFO Type;
FxObject* Object;
...
ULONG_PTR Context[1]; <-- the start of your context
}

dt wdf01000!FxContextHeader to see all of its glory

[my intervening reply snipped]

"Doron Holan" wrote in message
news:xxxxx@ntdev...
No, there is no backlink from a system VA pointer back to the owning
WDFMEMORY that owns it. Not sure how that would work, I guess KMDF could
store the object pointer before system va returned, but that breaks down on
PAGE_SIZE or greater allocations since the VA returned is required to be
aligned on PAGE_SIZE. KMDF could store it after the system VA, but then it
would have to know the size of the memory as well....

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

So the VA from a WDFMEMORY object is subject to the same constraints as that
returned by ExAllocatePool, while the VA of a context attached to that
WDFMEMORY object is not.

Thanks,

Phil

Philip D. Barila
Seagate Technology LLC
(720) 684-1842
As if I need to say it: Not speaking for Seagate.

"Doron Holan" wrote in message
news:xxxxx@ntdev...
The system VA returned by a WDFMEMORY must conform to the rules that
ExAllocatePool dictates. This basically means anything page size or bigger
is guaranteed to be page aligned. This way you can use the buffer from a
wdfmemory in pretty much any legacy situation. The contexts on a handle
can be any size (I think it is actually limited to ushort_max), including >=
page size....we just don't guarantee that the context pointer is page
aligned, that's all.

d

Correct.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Philip D. Barila
Sent: Wednesday, September 19, 2007 9:14 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:Re:WDFMEMORY and associated buffer

So the VA from a WDFMEMORY object is subject to the same constraints as that
returned by ExAllocatePool, while the VA of a context attached to that
WDFMEMORY object is not.

Thanks,

Phil

Philip D. Barila
Seagate Technology LLC
(720) 684-1842
As if I need to say it: Not speaking for Seagate.

"Doron Holan" wrote in message
news:xxxxx@ntdev...
The system VA returned by a WDFMEMORY must conform to the rules that
ExAllocatePool dictates. This basically means anything page size or bigger
is guaranteed to be page aligned. This way you can use the buffer from a
wdfmemory in pretty much any legacy situation. The contexts on a handle
can be any size (I think it is actually limited to ushort_max), including >=
page size....we just don't guarantee that the context pointer is page
aligned, that's all.

d

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