Penguin
Annotated edit history of MemoryMap version 10, including all changes. View license author blame.
Rev Author # Line
9 DeanDavis 1 The [Linux] VirtualMemory Map (as seen by a UserSpace program)<br>
2 <code>
10 PerryLorier 3 <?plugin OldStyleTable
9 DeanDavis 4 | __Starts at__| __Contains__<br>
5 | ffffffff |< End of the universe<br>
6 | ffffe000 |< vsyscall table (new in 2.5.x)<br>
7 | c0000000 |< Off limits, reserved for the kernel<br>
8 | bfffffff |< Process stack (grows down)<br>
9 | bffff000 |< Process heap (grows up)<br>
10 | 40000000 |< Libraries<br>
11 | zzzzzzzz |< Unused<br>
12 | yyyyyyyy |< __.bss__, uninitialised program data<br>
13 | xxxxxxxx |< __.data__ segment, initialised program data<br>
14 | 08048000 |< __.text__ segment, program code<br>
15 | 00000000 |< Unmapped to trap [NULL] pointers<br><br>
10 PerryLorier 16 ?>
9 DeanDavis 17 </code>
8 AristotlePagaltzis 18 "BSS" means __b__lock __s__tarted by __s__ymbol and is a segment of uninitialised that is only stored in the BinaryExecutable image as a length and offset, since it would otherwise waste space. The "text" segment on the other hand contains ''initialized'' global variables and ''is'' stored in the BinaryExecutable.
6 PeterBuxton 19
20 !!Practical examples
21 !Library-mapped memory (using ldd(1))
10 PerryLorier 22 <verbatim>
23 $ ldd /bin/ls
24 librt.so.1 => /lib/librt.so.1 (0x40026000)
25 libc.so.6 => /lib/libc.so.6 (0x40038000)
26 libpthread.so.0 => /lib/libpthread.so.0 (0x4016a000)
27 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
28 </verbatim>
6 PeterBuxton 29
9 DeanDavis 30 !Program code<br>
10 PerryLorier 31 <verbatim>
32 $ cat > x.c
9 DeanDavis 33
10 PerryLorier 34 #include <stdio.h>
35 int main(void) {printf("%p\n", main);return 0;}
36 $ gcc -o x x.c && ./x
37 0x8048344
38 $
39 </verbatim>
40 (this is printing the address of the main function.)
6 PeterBuxton 41
42 !Process Heap
10 PerryLorier 43 <verbatim>
44 $ cat > x2.c
45
46 #include <stdio.h>
47 int main(void) {char c;printf("%p\n", &c); return 0;}
48 $ gcc -o x2 x2.c && ./x2
49 0xbffffab7
50 </verbatim>
6 PeterBuxton 51
52 !Process Data and bss segment
9 DeanDavis 53
10 PerryLorier 54 <verbatim>
55 $ perl -e 'my $var; print \$var . "\n"'
9 DeanDavis 56 SCALAR(0x814f38c)<br>
10 PerryLorier 57 </verbatim>
58 (note that this is the address in the [Perl] interpreter)
6 PeterBuxton 59
10 PerryLorier 60 <verbatim>
6 PeterBuxton 61 $ cat > x3.c
9 DeanDavis 62
10 PerryLorier 63 #include <stdio.h>
64 #include <stdlib.h>
65 int main(void) {char *p=!malloc(3);printf("%p\n", p); return 0;}
66 $ gcc -o x3 x3.c && ./x3
67 0x8049628
68 </verbatim>
6 PeterBuxton 69 Also,
10 PerryLorier 70 <verbatim>
6 PeterBuxton 71 cat /proc/''pid''/maps
10 PerryLorier 72 </verbatim>
6 PeterBuxton 73 gives you the memory map for a program :)