Which part of process virtual memory layout does mmap() uses?

人走茶凉 提交于 2019-12-10 15:28:09

问题


The mmap() function shall establish a mapping between a process virtual address space and a device file or physical memory region.

A process virtual memory layout has the following sections:

Which region of Process Virtual Address Space does mmap() use for mapping?


回答1:


Mmap uses "unallocated memory".

Please note that the picture you drew is unlikely to be used on any UNIX system that is younger than about 30 years. UNIX used do have that memory layout in the early 70s, but the picture is much more complicated nowdays, especially when using shared libraries.




回答2:


To get an insight of what is happenning today, try (on Linux) the following command

cat /proc/self/maps

on my machine, it gives now

00400000-0040c000 r-xp 00000000 08:01 1850896                            /bin/cat
0060c000-0060d000 rw-p 0000c000 08:01 1850896                            /bin/cat
00adc000-00afd000 rw-p 00000000 00:00 0                                  [heap]
7ffe843ef000-7ffe84569000 r-xp 00000000 08:01 787567                     /lib/x86_64-linux-gnu/libc-2.13.so
7ffe84569000-7ffe84769000 ---p 0017a000 08:01 787567                     /lib/x86_64-linux-gnu/libc-2.13.so
7ffe84769000-7ffe8476d000 r--p 0017a000 08:01 787567                     /lib/x86_64-linux-gnu/libc-2.13.so
7ffe8476d000-7ffe8476e000 rw-p 0017e000 08:01 787567                     /lib/x86_64-linux-gnu/libc-2.13.so
7ffe8476e000-7ffe84773000 rw-p 00000000 00:00 0 
7ffe84773000-7ffe84792000 r-xp 00000000 08:01 790578                     /lib/x86_64-linux-gnu/ld-2.13.so
7ffe8495e000-7ffe84961000 rw-p 00000000 00:00 0 
7ffe84990000-7ffe84992000 rw-p 00000000 00:00 0 
7ffe84992000-7ffe84993000 r--p 0001f000 08:01 790578                     /lib/x86_64-linux-gnu/ld-2.13.so
7ffe84993000-7ffe84994000 rw-p 00020000 08:01 790578                     /lib/x86_64-linux-gnu/ld-2.13.so
7ffe84994000-7ffe84995000 rw-p 00000000 00:00 0 
7fffdbaac000-7fffdbacd000 rw-p 00000000 00:00 0                          [stack]
7fffdbb66000-7fffdbb67000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

It shows the memory map of the process executing the cat command.



来源:https://stackoverflow.com/questions/8295510/which-part-of-process-virtual-memory-layout-does-mmap-uses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!