Accessing Memory from a Driver (Windows Embedded CE 6.0)
1/6/2010
When you execute code in kernel mode, in contrast to user mode, you must have access to the entire physical memory. Because an interrupt service thread (IST) runs in user mode and could need access to a block of physical memory to communicate with a device, you must map this block of memory to the address space in which the IST runs.
To map a block of memory to the address space of the IST
Call VirtualAlloc to reserve a block of virtual memory.
You must pass the MEM_RESERVE value as an argument to this function. Windows Embedded CE allocates the memory and gives you a pointer to the block.
Call VirtualCopy to map this block of memory to the corresponding block of physical memory.
Specify the PAGE_NOCACHE argument so that the values inside that block are not cached. This flag will force the system to not optimize out a read.
VirtualCopy also supports the PAGE_PHYSICAL flag. You must set this flag when you are mapping physical memory that resides beyond 512 MB, that is, physical memory with an address above 0x1FFFFFFF.**
You can free virtual memory by using the VirtualFree function.**
In Windows CE 5.0 and earlier, if a device driver creates a thread, and in that thread you call MapPtrToProcess, you must use GetCurrentPermissions and SetProcPermissions to retrieve and reset process permissions.
In Windows Embedded CE 6.0, you do not have to provide special handling that maps a pointer to a different process unless you are working with an embedded pointer. If you are working with an embedded pointer in a thread, you must call CeOpenCallerBuffer and CeCloseCallerBuffer instead of the deprecated functions MapPtrToProcess, GetCurrentPermissions, and SetProcPermissions.**
See Also
Concepts
Device Driver Development Concepts
Memory Access Permissions