Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
- From: "Ross Jordan [MSFT]" <ross.nospam.jordan@xxxxxxxxxxxxx>
- Date: Wed, 16 May 2007 10:24:18 -0700
With regard to #1, VirtualAllocEx can be used to allocate memory in a specified process. Read/WriteProcessMemory can be used to access this memory (these apis aren't particularly fast). We don't generally recommend APIs working in this way.
-Ross
<andyraf@xxxxxxxxxxxxx> wrote in message news:1178857764.169292.259800@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On May 10, 2:35 pm, Dave Peverley <dpever...@xxxxxxxxxxxxxx> wrote:Hi all,
First off, apologies if this is a repost - I think something
odd is going on with my news server!
I've got a pretty complex driver I'm porting up at the moment
and am stuck scratching my head over a slightly odd issue. I have
an API that talks to the driver via DeviceIoControl() with various
structures that relate to API parameters.
For all of the calls so far its been straightforward mapping
embedded pointers via CeOpenCallerBuffer() and CeCloseCallerBuffer().
However there's a particular API function where the app passes in :
UINT8 **bufferarray;
UINT32 buffersize;
UINT32 buffercount;
This is an array of pointers to (n) buffers that get set up
_by_the_driver_ and returned to the caller rather than passed
in. i.e. the app sets up the count and size parameters and then
the driver allocates the buffers (via an internal allocation
routine from its own block of reserved memory). So I can map
in the bufferarray to set the pointers up in, but I can't work
out how to map the allocated buffers back into the callers
process space.
Obviously to map the buffer back out via the CeOpenCallerBuffer()
idiom it would have to have been passed in in the first place which
it wasnt so I'm kind of stumped trying to think what the most correct
mechanism to do this by would be?!
Of course I understand that changing the driver so it doesn't work
this way is likely to be the first suggested answer but this is a very
large driver and API that is cross platform to various other OS's and
this isn't a feasible option sadly...
Has anyone else had to try and get around this or a similar issue
in CE6.0 yet?
Best Wishes,
~Pev
Ok, obviously you've already though of the most obvious solution,
which is to change the API (allocating memory in the kernel and
passing it back to the caller is not a great design).
Anyway, I think you basically have two options:
1. I think there's an API allowing you to allocate memory in the
caller's process space. Look up CeRemoteHeapCreate. I suspect this
won't solve your problem because it sounds like you need to map a
specific reserved area of memory to the caller, and I think Remote
Heaps are dynamically allocated on the client's heap (they basically
act as if the client code had allocated them).
2. Use VirtualCopyEx to map a region of kernel memory to the client's
memory space. This is most likely to solve your problem, and is
exactly what we do in things like DirectDraw when we need to map the
frame buffer into the client's address space. There are a couple of
things to keep in mind with this mechanism:
- The minimal size that is actually mapped is 64k, so lots of small
allocations will eat up virtual memory space and waste MMU entries.If
you need to pass back a bunch of small pointers to data blocks that
all share the same memory region, it's better to just map the entire
region once and then calculate the client addresses for each block
within the region yourself rather than calling VirtualCopyEx for each
small block.
- On ARMV4 processors, the OS will automatically disable caching for
any memory blocks that are aliased to two different virtual addresses
(which is what VirtualCopyEx does).
-Andy
.
- References:
- CE6.0 Driver Pointer Marshalling - passing pointers out only?
- From: Dave Peverley
- Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
- From: andyraf
- CE6.0 Driver Pointer Marshalling - passing pointers out only?
- Prev by Date: Re: Touch screen driver Link error
- Next by Date: Re: RegFlushKey CE 6.0?
- Previous by thread: Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
- Next by thread: Command-line for Target Download dialog?
- Index(es):
Relevant Pages
|