Reputation: 1949
As we all know, memory layout has four segments as follows
Heap
Data Segment Read/Write permission
code segment Read/Execute permission
Stack
I would like to know the access permission for heap and stack segments.
Upvotes: 0
Views: 2238
Reputation: 606
I have written simple x86 OS to load elf image. Which the roughly layout of the four segment is as:
Code segment
Data segment
Heap
Stack
You can get the layout in linux by:
sudo pmap <pid>
0000000000400000 384K r-x-- /usr/local/bin/tmux
0000000000660000 8K rw--- /usr/local/bin/tmux
0000000000662000 108K rw--- [ anon ]
0000000001242000 132K rw--- [ anon ]
0000000001263000 2868K rw--- [ anon ]
00000037ba400000 128K r-x-- /lib64/ld-2.12.so
...
00007fff4f411000 84K rw--- [ stack ]
00007fff4f55c000 4K r-x-- [ anon ]
ffffffffff600000 4K r-x-- [ anon ]
The first segment is for executable image. Second is for the read only data. Then goes the heap. The heap in linux which allocated by malloc was called Anonymous segment. In the address near 00008000 00000000 is the stack addresses.
Which stack grow downside, and heap grow upside from the address after the data segment of program.
Then you could found the permission of the heap and stack are all read/write permission.
Ps. I'm not quite sure why there are so many Anonymous segment as I haven't go to so detail of linux for a long time. But in my x86 simple OS, heap start after data segment with alignment and padding.
Upvotes: 1