2

Consider the mappings in the virtual memory of a small test program I wrote:

0000000000400000     20K r-x--  /home/arvidj/dev/examples/testgen.c.out
0000000000604000      4K r----  /home/arvidj/dev/examples/testgen.c.out
0000000000605000      4K rw---  /home/arvidj/dev/examples/testgen.c.out
0000000000606000     16K rw---    [ anon ]
00007ffff7a12000   1780K r-x--  /lib/x86_64-linux-gnu/libc-2.17.so
00007ffff7bcf000   2048K -----  /lib/x86_64-linux-gnu/libc-2.17.so
00007ffff7dcf000     16K r----  /lib/x86_64-linux-gnu/libc-2.17.so
00007ffff7dd3000      8K rw---  /lib/x86_64-linux-gnu/libc-2.17.so
00007ffff7dd5000     20K rw---    [ anon ]
00007ffff7dda000    140K r-x--  /lib/x86_64-linux-gnu/ld-2.17.so
00007ffff7fde000     12K rw---    [ anon ]
00007ffff7ff8000      8K rw---    [ anon ]
00007ffff7ffa000      8K r-x--    [ anon ]
00007ffff7ffc000      4K r----  /lib/x86_64-linux-gnu/ld-2.17.so
00007ffff7ffd000      8K rw---  /lib/x86_64-linux-gnu/ld-2.17.so
00007ffffffde000    132K rw---    [ stack ]
ffffffffff600000      4K r-x--    [ anon ]

How flexible is this layout? Which parts can be moved (statically or dynamically), and how? If I want the stack to start at 0x0000000001000000, how can I change this? Conversely, can I move up the DATA/TEXT segments, am I at liberty to do so?

If I manage to move the stack (perhaps via makecontext, or by fiddling with sp in asm), how can I re-use that space? Can I use map over it, or can I have to unmap it using munmap? You can find my motivation in this question.

Community
  • 1
  • 1
arvidj
  • 775
  • 5
  • 25

0 Answers0