Memory map or physical address of some memory allocated by malloc
How can I get the memory map or physical address of some memory allocated by malloc?
Please help me. I cannot get it anywhere.
Thanks in advance.
Find out the virtual page number of the virtual address (by dividing by sysconf(_SC_PAGE_SIZE)), and use it as an index to the correct 64-bit descriptor in /proc/self/pagemap (or /proc/pid/pagemap for process pid). Read the 64-bit descriptor. If the page is present (highest bit, bit 63, is 1) and not swapped (bit 62 is 0), then the lowest 55 bits shifted left by (bits 56..61 = 0..63) tells the start address of the physical page. Add the offset of the virtual address from the start of the virtual page (i.e. virtual address modulus sysconf(_SC_PAGE_SIZE)), and you get the physical address of the virtual address the pointer points to.
|All times are GMT -5. The time now is 02:35 PM.|