Search code examples
cmemoryvirtualmtrace

Mtrace Physical Memory Allocation Log


I wanted to ask if I could use the mtrace() function in order for my program to log the physical addresses of the memory allocations. Also, if I use mtrace() and is able to show the addresses used for allocation, will this show me the addresses in the physical or virtual memory?

Thank you in advance.

Edit: Ok, so I run the following code:

#include <stdlib.h>
#include <mcheck.h>

int main(void) { 

mtrace(); /* Starts the recording of memory allocations and releases */

int* a = NULL;

a = malloc(sizeof(int)); /* allocate memory and assign it to the pointer */
if (a == NULL) {
    return 1; /* error */
}

free(a); /* we free the memory we allocated so we don't have leaks */
muntrace();

return 0; /* exit */

}

It gives me the following output:

=Start
@ ./a.out:[0x80484a6] + 0x9738378 0x4
@ ./a.out:[0x80484c4] + 0x9738378
= End

Are the addresses shown in virtual memory or in physical memory?


Solution

  • All addresses exposed to userspace applications, including those shown by mtrace(), are virtual memory addresses.