I am studying virtual memory mappings of memory regions in Linux. The executable is a simple counting program. When two instances of the program are run, the following are the mappings shown by /proc/pid/maps
. The location of heap, stack, vvar, vdso, etc appear to have a random offset at load time. Why is this done?
Instance 1: Heap starts at 013f4000
00400000-00401000 r--p 00000000 08:16 3557412 <program-exe>
00401000-00480000 r-xp 00001000 08:16 3557412 <program-exe>
00480000-004a5000 r--p 00080000 08:16 3557412 <program-exe>
004a6000-004ac000 rw-p 000a5000 08:16 3557412 <program-exe>
004ac000-004ad000 rw-p 00000000 00:00 0
013f4000-01417000 rw-p 00000000 00:00 0 [heap]
7ffd98bd8000-7ffd98bf9000 rw-p 00000000 00:00 0 [stack]
7ffd98bfc000-7ffd98bff000 r--p 00000000 00:00 0 [vvar]
7ffd98bff000-7ffd98c00000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]
Instance 2: Heap starts at 013cc000
00400000-00401000 r--p 00000000 08:16 3557412 <program-exe>
00401000-00480000 r-xp 00001000 08:16 3557412 <program-exe>
00480000-004a5000 r--p 00080000 08:16 3557412 <program-exe>
004a6000-004ac000 rw-p 000a5000 08:16 3557412 <program-exe>
004ac000-004ad000 rw-p 00000000 00:00 0
013cc000-013ef000 rw-p 00000000 00:00 0 [heap]
7ffe3717d000-7ffe3719e000 rw-p 00000000 00:00 0 [stack]
7ffe371fa000-7ffe371fd000 r--p 00000000 00:00 0 [vvar]
7ffe371fd000-7ffe371fe000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]