Share via


Accessing Memory from a Driver (Windows CE 5.0)

Send Feedback

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

  1. Call VirtualAlloc to reserve a block of virtual memory.

    You must pass the MEM_RESERVE value as an argument to this function. Microsoft® Windows® CE allocates the memory and gives you a pointer to the block.

  2. 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.

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.

See Also

Memory Access Permissions | Memory Architecture

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.