LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Memory map or physical address of some memory allocated by malloc (http://www.linuxquestions.org/questions/programming-9/memory-map-or-physical-address-of-some-memory-allocated-by-malloc-927419/)

demon007 02-03-2012 10:06 AM

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.

Nominal Animal 02-04-2012 06:17 AM

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:08 AM.