Search code examples
memorymemory-addressdriverswdk

What realy means PHYSICAL_ADDRESS value in WDK drivers?


I have bit of a problem with understanding PHYSICAL_ADDRESS structure in WDK. I thought it's real physical address in physical memory. Now I've tried this - I've got virtual PC with 512 MB RAM and code in my driver

PHYSICAL_ADDRESS pa;
pa.QuadPart = 9223372036854775805; //max LONGLONG - 1
mr = MmMapIoSpace(pa , 100, 0);
DbgPrint("%i ", MmGetPhysicalAddress(mr));

... and it worked without problem. How is this possible with 512 MB RAM? Isn't max physical address 512 MB = cca 512 000 000? What realy means PHYSICAL_ADDRESS value?

PS: Please don't ask why am I doing this. I am just wondering how is this possible.


Solution

  • The code working without problem means that you successfully map that (possibly bogus) physical address to a virtual address that your code can read and write. This is just an entry in the page table. Apparently the system does not verify physical address range. Try derefencing the obtained virtual address: DbgPrint("%x\n", *((PULONG)mr));