c++ - Why does the address of a function change with every run? -


i'm struggling mapping addresses symbols debugging purposes (getting callstack). ms dbghelp.dll can tell symbol address (see symfromaddr, msdn). however, doesn't work , wonder how ever work, because addresses seem change every run of program:

#include <iostream> void foo() {}  int _tmain(int argc, _tchar* argv[]) {     const long unsigned int addr = reinterpret_cast<long unsigned int>(&foo);     std::cout << "address: " << std::hex << addr << std::endl;     return 0; } 

output:

d:\dev\sandbox\debug>sandbox.exe address: 901320 d:\dev\sandbox\debug>sandbox.exe address: ce1320 d:\dev\sandbox\debug>sandbox.exe address: 3a1320 d:\dev\sandbox\debug>sandbox.exe address: 3f1320 

how different program ever read address stacktrace , map functions? sounds magic me. didn't find in linked documentation says have subtract address or whatever.

in understanding since overcome real-mode every process has virtual memory space anyway, no need roll dice load address more. understand uncertainties of absolute address in case of dlls, not main executable.

tried on win7 vs2008.

address space layout randomization


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -