Sharing memory between driver and application  
Author Message
cosmini





PostPosted: Fri Feb 01 13:08:40 PST 2008 Top

Platbuilder >> Sharing memory between driver and application

Does anyone know how to share memory between the driver and application so
that we do not have to use conventional DeviceIoControl, where IO manager
will spend some time copying data from system buffer to application (user)
buffer?

Looks like METHOD_OUT_DIRECT/METHOD_IN_DIRECT is not supported under windows
CE according to documentation. However, for CE 5.0 there is refernce to
METHOD_OUT_DIRECT in some CDROM driver in Public\Common for CD driver. For
CE 6.0 there is refernce to the same for touch screen driver. Is there any
undocumented feature?

Windows OS194  
 
 
Dean





PostPosted: Fri Feb 01 13:08:40 PST 2008 Top

Platbuilder >> Sharing memory between driver and application Memory mapped files are one way of dealing with this...

--
Dean Ramsier - eMVP
BSQUARE Corporation




> Does anyone know how to share memory between the driver and application so
> that we do not have to use conventional DeviceIoControl, where IO manager
> will spend some time copying data from system buffer to application (user)
> buffer?
>
> Looks like METHOD_OUT_DIRECT/METHOD_IN_DIRECT is not supported under
> windows CE according to documentation. However, for CE 5.0 there is
> refernce to METHOD_OUT_DIRECT in some CDROM driver in Public\Common for CD
> driver. For CE 6.0 there is refernce to the same for touch screen driver.
> Is there any undocumented feature?
>


 
 
Dean





PostPosted: Fri Feb 01 13:40:20 PST 2008 Top

Platbuilder >> Sharing memory between driver and application By the way, DeviceIoControl doesn't necessarily mean there has to be a copy.
The driver and app can map to the same memory through the magic of virtual
memory addressing. The driver has the choice of copying, but doesn't have
to.

--
Dean Ramsier - eMVP
BSQUARE Corporation




> Memory mapped files are one way of dealing with this...
>
> --
> Dean Ramsier - eMVP
> BSQUARE Corporation
>
>


>> Does anyone know how to share memory between the driver and application
>> so that we do not have to use conventional DeviceIoControl, where IO
>> manager will spend some time copying data from system buffer to
>> application (user) buffer?
>>
>> Looks like METHOD_OUT_DIRECT/METHOD_IN_DIRECT is not supported under
>> windows CE according to documentation. However, for CE 5.0 there is
>> refernce to METHOD_OUT_DIRECT in some CDROM driver in Public\Common for
>> CD driver. For CE 6.0 there is refernce to the same for touch screen
>> driver. Is there any undocumented feature?
>>
>
>


 
 
kkxl





PostPosted: Sat Feb 02 19:06:20 PST 2008 Top

Platbuilder >> Sharing memory between driver and application CreateFileMapping (), MapViewOfFile()

In the driver, you can use CreateFileMapping function to create a
named file-mapping object, then in the application use the function to
open the named file-mapping object you created.

you can find them in WM Documentation
 
 
Michael





PostPosted: Sun Feb 03 09:25:37 PST 2008 Top

Platbuilder >> Sharing memory between driver and application There isn't an I/O Manager per se as in NT (I guess you're trying to compare
to NT model?). So any buffer copying is done by the driver. NT does it so
that the kernel doesn't take a fault if the application perhaps frees its
copy of the buffer (since every request is async at the driver level). If
you have an async IOCTL, then you should probably copy the buffer for the
same reason. If the IOCTL is synchronous, you can probably do as Dean
suggested - just map the same memory (e.g. MapPtrToProcess) for WinCE 5.0 or
less. I don't think you can do that for WinCE 6.0, though. The InBuf and
OutBuf will already be mapped (or copied), but any pointers embedded in
there - probably best to flatten / marshal everything into the InBuf.

You also have ReadProcessMemory / WriteProcessMemory. That's the WinCE 6.0
way to "map the same memory" and, fortunately, will work in WinCE 5.0, too.
You do need to know the process making the request (so you can get an
hProcess neeeded for those calls). In WinCE 5.0 and earlier, you can call
GetCallerProcess(). Not sure about WinCE 6.0.

--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com




> Does anyone know how to share memory between the driver and application so
> that we do not have to use conventional DeviceIoControl, where IO manager
> will spend some time copying data from system buffer to application (user)
> buffer?
>
> Looks like METHOD_OUT_DIRECT/METHOD_IN_DIRECT is not supported under
> windows CE according to documentation. However, for CE 5.0 there is
> refernce to METHOD_OUT_DIRECT in some CDROM driver in Public\Common for CD
> driver. For CE 6.0 there is refernce to the same for touch screen driver.
> Is there any undocumented feature?
>

 
 
Dean





PostPosted: Mon Feb 04 09:20:11 PST 2008 Top

Platbuilder >> Sharing memory between driver and application If
> you have an async IOCTL, then you should probably copy the buffer for the
> same reason. If the IOCTL is synchronous, you can probably do as Dean
> suggested - just map the same memory (e.g. MapPtrToProcess) for WinCE 5.0
> or less. I don't think you can do that for WinCE 6.0, though. The InBuf
> and OutBuf will already be mapped (or copied), but any pointers embedded
> in there - probably best to flatten / marshal everything into the InBuf.

Use CeOpenCallerBuffer/CeCloseCallerBuffer to map embedded pointers in CE6.
If call will be asynchronous, use
CeAllocAsynchronousBuffer/CeFreeAsynchronousBuffer. The Async calls must be
made on pointers that are already marshalled (either by the kernel for
pointer parameters, or by the user with CeOpenCallerBuffer for embedded
pointers).

If you want to copy a pointer parameter for asynchronous use in CE6, use
CeAllocDuplicateBuffer.

--
Dean Ramsier - eMVP
BSQUARE Corporation




> There isn't an I/O Manager per se as in NT (I guess you're trying to
> compare to NT model?). So any buffer copying is done by the driver. NT
> does it so that the kernel doesn't take a fault if the application perhaps
> frees its copy of the buffer (since every request is async at the driver
> level). If you have an async IOCTL, then you should probably copy the
> buffer for the same reason. If the IOCTL is synchronous, you can probably
> do as Dean suggested - just map the same memory (e.g. MapPtrToProcess) for
> WinCE 5.0 or less. I don't think you can do that for WinCE 6.0, though.
> The InBuf and OutBuf will already be mapped (or copied), but any pointers
> embedded in there - probably best to flatten / marshal everything into the
> InBuf.
>
> You also have ReadProcessMemory / WriteProcessMemory. That's the WinCE
> 6.0 way to "map the same memory" and, fortunately, will work in WinCE 5.0,
> too. You do need to know the process making the request (so you can get an
> hProcess neeeded for those calls). In WinCE 5.0 and earlier, you can call
> GetCallerProcess(). Not sure about WinCE 6.0.
>
> --
> Michael Salamone, eMVP
> Entrek Software, Inc.
> www.entrek.com
>
>


>> Does anyone know how to share memory between the driver and application
>> so that we do not have to use conventional DeviceIoControl, where IO
>> manager will spend some time copying data from system buffer to
>> application (user) buffer?
>>
>> Looks like METHOD_OUT_DIRECT/METHOD_IN_DIRECT is not supported under
>> windows CE according to documentation. However, for CE 5.0 there is
>> refernce to METHOD_OUT_DIRECT in some CDROM driver in Public\Common for
>> CD driver. For CE 6.0 there is refernce to the same for touch screen
>> driver. Is there any undocumented feature?
>>
>