Hi,

I want to return to the user application a mapping to a physical buffer.

Suppose the virtual address in the address space of device.exe is paddr
does

ioctl(instance, pin, size, pout, size, unused)
{
pnewaddr = MapPtrProcess(paddr, GetCallerProcess())
pout = pnewaddr //should this be *pout = pnewaddr
}

return the new mapping in pout ?

Re: Mapping physical memory into Application space by Anthony

Anthony
Wed Jun 29 02:01:13 CDT 2005

Not sure I really understand what you want.
If you have a physical address, you new to call mmmapiospace to get a
virtual pointer to this buffer.
If you already have a virtual address to this buffer, mapped in another
process, then you can call MapPtrToProcess and use the returned value as a
pointer to th buffer.

pout=pnewaddr won't work. The content pout must be changed, not pout itself.

hope this helps

--
----------------------------------------------------------------
Anthony Pellerin
ADENEO (ADESET)
Windows Embedded Consultant
<apellerin AT adeneo DOT adetelgroup DOT com>
http://www.adeneo.adetelgroup.com
Tél : +33 (0)4.72.18.57.77
Fax : +33 (0)4.72.18.57.78
----------------------------------------------------------------


"viddec" <viddec@discussions.microsoft.com> wrote in message
news:A44FECF3-C447-4F6D-95C7-D9CB79242D5D@microsoft.com...
> Hi,
>
> I want to return to the user application a mapping to a physical buffer.
>
> Suppose the virtual address in the address space of device.exe is paddr
> does
>
> ioctl(instance, pin, size, pout, size, unused)
> {
> pnewaddr = MapPtrProcess(paddr, GetCallerProcess())
> pout = pnewaddr //should this be *pout = pnewaddr
> }
>
> return the new mapping in pout ?
>
>



Re: Mapping physical memory into Application space by Steve

Steve
Wed Jun 29 08:42:00 CDT 2005

Where does this code run? Where do the pointers come from? The OS already
maps the pointers it knows about as direct parameters. You only need to map
pointers embedded in data structures you are passing in the buffers the
buffer pointers point to.


--
Steve Maillet
EmbeddedFusion
www.EmbeddedFusion.com
smaillet at EmbeddedFusion dot com



RE: Mapping physical memory into Application space by viddec

viddec
Wed Jun 29 09:09:04 CDT 2005



This code runs in a device driver (as part of device.exe), i have tried to
make the code more understandable below:

pout is a ptr to a struct that has an embedded pointer called buffer.

ioctl(instance, pin, size, pout, size, unused)
{
paddr = MmapIoSpace(physical_address)
// trying to map paddr from device.exe to the calling application
pnewaddr = MapPtrProcess(paddr, GetCallerProcess())
pout->buffer = pnewaddr

}

In the application:

buffer_struct some_buf;

ioctl(fd, IOCTL, NULL, 0, &some_buf, sizeof(some_buf))

memcpy(some_buf.buffer, my_buf, some_length);

"viddec" wrote:

> Hi,
>
> I want to return to the user application a mapping to a physical buffer.
>
> Suppose the virtual address in the address space of device.exe is paddr
> does
>
> ioctl(instance, pin, size, pout, size, unused)
> {
> pnewaddr = MapPtrProcess(paddr, GetCallerProcess())
> pout = pnewaddr //should this be *pout = pnewaddr
> }
>
> return the new mapping in pout ?
>
>

Re: Mapping physical memory into Application space by Steve

Steve
Wed Jun 29 09:15:32 CDT 2005

You can't allocate a memory in a driver and return it to the application -
it's a massive security hole if you could. Instead the application allocates
the memory and then passes the pointer to the driver.


--
Steve Maillet
EmbeddedFusion
www.EmbeddedFusion.com
smaillet at EmbeddedFusion dot com



Re: Mapping physical memory into Application space by viddec

viddec
Wed Jun 29 09:31:01 CDT 2005


So, WinCe does not support the idea of mapping physical buffers to App
space. I can do this under Linux with the mmap system call. WinXP also allows
this but its not documented too well.

I could always pass the physical address to the application and have it call
MmapIOSpace(..)

Is the memory mapped using MmapIOSpace(..) accounted towards the process's
32MB limit ?

thanks for all the quick answers.


"Steve Maillet (eMVP)" wrote:

> You can't allocate a memory in a driver and return it to the application -
> it's a massive security hole if you could. Instead the application allocates
> the memory and then passes the pointer to the driver.
>
>
> --
> Steve Maillet
> EmbeddedFusion
> www.EmbeddedFusion.com
> smaillet at EmbeddedFusion dot com
>
>
>

Re: Mapping physical memory into Application space by Steve

Steve
Wed Jun 29 15:57:55 CDT 2005

Huh an Application can map the data it needs from a physical device using
TransBusAddrToVirtual() (which internally calls MmMapIoSpace(), which
internally calls VirtualAlloc/VirtualCopy) There is no direct way for a
driver to allocate memory on behalf of an application that the application
can then use. The expectation is that the application allocates it's own
buffer and provides that to the driver. It's really an arbitrary choice
and CE does it one way other systems may do the same or may do the opposite.

--
Steve Maillet
EmbeddedFusion
www.EmbeddedFusion.com
smaillet at EmbeddedFusion dot com



Re: Mapping physical memory into Application space by Zhongwei

Zhongwei
Thu Jun 30 10:16:31 CDT 2005

WinCE supports the idea of mapping physical buffers to App space. That is
what MmMapIoSpace does.

What you want is a virtual address of a physical buffer in your application
and you have the physical address of that buffer. So you can just call
MmMapIoSpace(physical_addr, length, FALSE) in your application and there is
no need for IOCtl. At most, you can get physical_addr with IOCtl and call
MmMapIoSpace in your application. What is the point to call MmMapIoSpace
and MapPtrProcess in the driver while you want to use the pointer in
application? It may work if you do it right though.

--
Zhongwei Wang
Applied Data Systems
www.applieddata.net
Application - Ready embedded systems
Microsoft Windows Embedded Partner
Gold Level Member


"viddec" <viddec@discussions.microsoft.com> wrote in message
news:5AF141B6-8FD9-4E85-BE3A-280EA42B79BB@microsoft.com...
>
> So, WinCe does not support the idea of mapping physical buffers to App
> space.



Re: Mapping physical memory into Application space by Steve

Steve
Thu Jun 30 12:43:06 CDT 2005

"I could always pass the physical address to the application and have it
call MmapIOSpace(..)"

Huh? Why would want to do that. The driver deals with the physical device
the application deals with it's own data buffers. The app gives a pointer to
a buffer to the driver and the driver gets data from the device and puts it
into the buffer.

Why don't you explain your scenario a bit better instead of just one attempt
to implement it. Tat would help give you better guidance on the way to go.


--
Steve Maillet
EmbeddedFusion
www.EmbeddedFusion.com
smaillet at EmbeddedFusion dot com