Windows Physical Direct Memory Mapping
- by chrisjleaf
I'm a bit disappointed there is almost no discussion of this no matter where I look so I guess I'll have to ask.
I'm writing a cross platform memory bench marking application which requires direct physical address mapping rather than virtual addressing.
EDIT
The solution would look something like the Linux/Unix system calls:
int fd = open("/dev/mem", O_RDONLY);
mmap(NULL, len, PROT_READ, MAP_SHARED, fd, PHYSICAL_ADDRESS_OFFSET);
which will require the kernel to either give you a virtual page mapping to the desired physical address or return that it failed. This does require supervisor privileges but that is ok.
I have seen a lot of information about shared memory and memory mapped files but all of these reside on disc and are thus not really useful when I'm trying to make a system dependent read. It is very similar to writing an IO driver although I do no need write permissions to the physical address.
This site gives an example of how to do it on a driver level using the Windows Driver Kit:
NT Insider: Sharing Memory between drivers and applications
This solution would probably require Visual Studio which currently I do not have access to. (I have downloaded the WDK api but it complained about my use of GCC for Windows).
I'm traditionally a Linux programmer so I'm hoping there might be something really simple I'm missing. Thanks in advance if you know something I don't!