0
votes

I am on a 64bit debian (Linux alexDesktop 2.6.32-5-amd64 #1 SMP Fri Feb 15 15:39:52 UTC 2013 x86_64 GNU/Linux).

I am trying to understand the memory maps in linux.
/bin/bash is my example.

ps output:

  PID TTY          TIME CMD
23921 pts/48   00:00:00 bash
29431 pts/48   00:00:00 ps

cat /proc/23921/maps output:

00400000-004d9000 r-xp 00000000 08:02 4350017                            /bin/bash
006d9000-006e2000 rw-p 000d9000 08:02 4350017                            /bin/bash
006e2000-006e8000 rw-p 00000000 00:00 0
00fac000-01001000 rw-p 00000000 00:00 0                                  [heap]
7f47d6a4c000-7f47d6a57000 r-xp 00000000 08:02 887361                     /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f47d6a57000-7f47d6c56000 ---p 0000b000 08:02 887361                     /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f47d6c56000-7f47d6c57000 r--p 0000a000 08:02 887361                     /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f47d6c57000-7f47d6c58000 rw-p 0000b000 08:02 887361                     /lib/x86_64-linux-gnu/libnss_files-2.13.so
7f47d6c58000-7f47d6c62000 r-xp 00000000 08:02 887373                     /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f47d6c62000-7f47d6e61000 ---p 0000a000 08:02 887373                     /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f47d6e61000-7f47d6e62000 r--p 00009000 08:02 887373                     /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f47d6e62000-7f47d6e63000 rw-p 0000a000 08:02 887373                     /lib/x86_64-linux-gnu/libnss_nis-2.13.so
7f47d6e63000-7f47d6e78000 r-xp 00000000 08:02 887371                     /lib/x86_64-linux-gnu/libnsl-2.13.so
7f47d6e78000-7f47d7077000 ---p 00015000 08:02 887371                     /lib/x86_64-linux-gnu/libnsl-2.13.so
7f47d7077000-7f47d7078000 r--p 00014000 08:02 887371                     /lib/x86_64-linux-gnu/libnsl-2.13.so
7f47d7078000-7f47d7079000 rw-p 00015000 08:02 887371                     /lib/x86_64-linux-gnu/libnsl-2.13.so
7f47d7079000-7f47d707b000 rw-p 00000000 00:00 0
7f47d707b000-7f47d7082000 r-xp 00000000 08:02 887363                     /lib/x86_64-linux-gnu/libnss_compat-2.13.so
7f47d7082000-7f47d7281000 ---p 00007000 08:02 887363                     /lib/x86_64-linux-gnu/libnss_compat-2.13.so
7f47d7281000-7f47d7282000 r--p 00006000 08:02 887363                     /lib/x86_64-linux-gnu/libnss_compat-2.13.so
7f47d7282000-7f47d7283000 rw-p 00007000 08:02 887363                     /lib/x86_64-linux-gnu/libnss_compat-2.13.so
7f47d7283000-7f47d72a8000 r-xp 00000000 08:02 887309                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f47d72a8000-7f47d74a7000 ---p 00025000 08:02 887309                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f47d74a7000-7f47d74ab000 r--p 00024000 08:02 887309                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f47d74ab000-7f47d74ac000 rw-p 00028000 08:02 887309                     /lib/x86_64-linux-gnu/libtinfo.so.5.9
7f47d74ac000-7f47d762c000 r-xp 00000000 08:02 887367                     /lib/x86_64-linux-gnu/libc-2.13.so
7f47d762c000-7f47d782c000 ---p 00180000 08:02 887367                     /lib/x86_64-linux-gnu/libc-2.13.so
7f47d782c000-7f47d7830000 r--p 00180000 08:02 887367                     /lib/x86_64-linux-gnu/libc-2.13.so
7f47d7830000-7f47d7831000 rw-p 00184000 08:02 887367                     /lib/x86_64-linux-gnu/libc-2.13.so
7f47d7831000-7f47d7836000 rw-p 00000000 00:00 0
7f47d7836000-7f47d7838000 r-xp 00000000 08:02 887360                     /lib/x86_64-linux-gnu/libdl-2.13.so
7f47d7838000-7f47d7a38000 ---p 00002000 08:02 887360                     /lib/x86_64-linux-gnu/libdl-2.13.so
7f47d7a38000-7f47d7a39000 r--p 00002000 08:02 887360                     /lib/x86_64-linux-gnu/libdl-2.13.so
7f47d7a39000-7f47d7a3a000 rw-p 00003000 08:02 887360                     /lib/x86_64-linux-gnu/libdl-2.13.so
7f47d7a3a000-7f47d7a5b000 r-xp 00000000 08:02 887311                     /lib/x86_64-linux-gnu/libncurses.so.5.9
7f47d7a5b000-7f47d7c5a000 ---p 00021000 08:02 887311                     /lib/x86_64-linux-gnu/libncurses.so.5.9
7f47d7c5a000-7f47d7c5b000 r--p 00020000 08:02 887311                     /lib/x86_64-linux-gnu/libncurses.so.5.9
7f47d7c5b000-7f47d7c5c000 rw-p 00021000 08:02 887311                     /lib/x86_64-linux-gnu/libncurses.so.5.9
7f47d7c5c000-7f47d7c7c000 r-xp 00000000 08:02 887370                     /lib/x86_64-linux-gnu/ld-2.13.so
7f47d7e6c000-7f47d7e70000 rw-p 00000000 00:00 0
7f47d7e79000-7f47d7e7b000 rw-p 00000000 00:00 0
7f47d7e7b000-7f47d7e7c000 r--p 0001f000 08:02 887370                     /lib/x86_64-linux-gnu/ld-2.13.so
7f47d7e7c000-7f47d7e7d000 rw-p 00020000 08:02 887370                     /lib/x86_64-linux-gnu/ld-2.13.so
7f47d7e7d000-7f47d7e7e000 rw-p 00000000 00:00 0
7fff4bc2a000-7fff4bc3f000 rw-p 00000000 00:00 0                          [stack]
7fff4bc41000-7fff4bc42000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

can someone explain why the first four lines of the output is different with the other? the address there is 32bit address, not 64bit.

1

1 Answers

3
votes

This output is generated by show_map_vma in fs/task_mmu.c. The relevant line of code is:

seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
                start,
                end,
                flags & VM_READ ? 'r' : '-',
                flags & VM_WRITE ? 'w' : '-',
                flags & VM_EXEC ? 'x' : '-',
                flags & VM_MAYSHARE ? 's' : 'p',
                pgoff,
                MAJOR(dev), MINOR(dev), ino);

So you can see that the standard printf-style formatting specifies %08lx, meaning a minimum of 8 hex digits, prefixed with zeros. Any numbers larger than this (aka 64-bit values) will simply print more digits.


Issuing the command readelf -l $(which bash) will list its program headers. You'll see that the bash ELF file has been linked such that its .text (and other) sections are loaded up at the virtual address 0x400000. The output of /proc/[pid]/maps is simply reflecting this.