2012年4月12日 星期四

VirtualCopy MmMapIoSpace in WINCE 6

http://discovertheexperience.blogspot.com/2009/04/windows-embedded-ce-60-memory-mapping.html

In Windows Embedded CE 6.0 there are some APIs which can only be called from Kernel Mode due to trust issues. The memory mapping APIs like VirtualCopyMmMapIoSpace (which is a wrapper for VirtualAlloc and VirtualCopy), … now belong to those Kernel Mode only APIs. Consequently you might ask: “So there is no way to call MmMapIoSpace directly from User Mode?” Well not quite, there is but one exception and that is a User Mode driver. The reflector service of a particular User Mode driver which runs in Kernel Mode can call MmMapIoSpace on behalf of that User Mode driver. However, it will not do so unless it knows that the User Mode driver is allowed to access the addresses in question. But how does the reflector service get this information you might ask? Well It gets it from the User Mode driver’s registry: more specific from the IoBase and IoLen keys. You can also use multi-strings here to specify multiple base addresses and lengths. And since this part of the registry is only accessible by privileged applications we have a protection against unauthorized altering of those keys.

But what if you need to call a memory mapping API such asMmMapIoSpace from a User Mode application? How now brown cow? Well you got several options how to deal with this problem:
  • You can make the code that calls the memory mapping functions a driver. Remember to specify the IoBase and IoLenregistry keys if you make it a User Mode driver.

  • You can make the code that calls the memory mapping functions into a DLL that you then have to load into the Kernel via LoadKernelLibrary.

  • You can create a dummy Kernel Mode driver that implementsIOCTL_DO_VIRTUAL_COPY to call VirtualCopy.

There is another important restriction on VirtualCopy and therefore also on MmMapIoSpace in Windows Embedded CE 6.0: Calls to either of these two memory mapping functions will fail if it crosses a 32 MB section boundary. To avoid this you may have to call these APIs multiple times.




http://blog.csdn.net/Jack__h/article/details/4939911
http://www.cppblog.com/milkyway/archive/2007/03/27/20738.html


VirtualCopy 的WINCE 5, 6, 7 的解釋各有不同,值得一看
WINCE 5 -- 傳統的, MEM_PHYSICAL 解釋不同, return 的address 2MB 不同
http://msdn.microsoft.com/en-us/library/aa450977.aspx
WINCE 6  -- 講了如何call API 的替代方法
http://msdn.microsoft.com/en-us/library/ee483154(v=winembedded.60).aspx
WINCE 7
http://msdn.microsoft.com/en-us/library/ee483154.aspx

沒有留言: