0

So I'm trying to understand how a process is assigned a base address once its loaded into memory. If I understand correctly each process has its own virtual address space, and each virtual address is mapped to physical memory locations by the mmu and each process believes they have the virtual range 0x00000000 through 0x7FFFFFFF for themselves in the x86 architechture.

Lets say I have program 1 .exe that is loaded at the virtual address 0x121000 enter image description here

and lets say I have another program called program 2.exe that is loaded in the virtual address 0xF71000

enter image description here

If both programs have their own virtual address space why aren't they loaded at the same virtual address by default? and is it possible for the programs to load at a different virtual address if they are executed again or will program 1.exe always be loaded at address 0x121000 every time its executed?

1

I believe what makes the difference is ASLR - Adress Space Layout Randomization - Read about it here - so basically it's just a layer of security protection.

It's indeed possible to load two different processes to the same virtual address base - the virtual address abstraction makes it possible.

The loading base address of a process will most likely be kept the same until your next reboot.

| improve this answer | |
  • So only the stack, heap, and load address are randomly selected? Does that mean that if I find a pointer in the text segment to a structure that's allocated in the heap I will be able to access that structure by calculating the offset between the base address and the pointer? – Nice Aug 27 at 7:23
  • Also, the loading address of different libraries, that have ASLR enabled will be randomized. You can find a pointer only at run-time - at the binary level, there will be nothing that accesses the heap directly (by address). – macro_controller Aug 27 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.