简体   繁体   中英

Segments up to heap in /proc/self/maps output

My program, at a certain point in its execution, reads its own /proc/self/maps line by line until (and including) the heap. The program's path is "/home/t4". Here is the output:

00400000-00403000 r-xp 00000000 68:06 21629911 /home/t4
00602000-00603000 r--p 00002000 68:06 21629911 /home/t4
00603000-00604000 rw-p 00003000 68:06 21629911 /home/t4
00604000-00608000 rw-p 00000000 00:00 0
01905000-01926000 rw-p 00000000 00:00 0 [heap]

I was expecting only four segments: code, constants, static variables, heap; but here, there are five. The first one clearly must be code, and the last is the heap. Perhaps the second one is constants--but then what are the other two? Thanks!

初始化的静态变量后跟未初始化的静态变量(.BSS)-不需要存储在二进制文件中。

The first is the executable part itself (due to the x bit), the second is likely .rodata (absence of w bit), the third is everything else ( .bss and .data ). The fourth is the result of some mmap call using MAP_ANONYMOUS . Note that malloc (3) may very well be implemented using mmap (2) rather than sbrk (2). The [heap] object there is the classic sbrk-heap (and only that), and does not cover private writable regions obtained using mmap. Traditional stack would be listed as [stack] , but stacks of subthreads can use any memory region to store their stack, usually something malloc'd, so you will not see multiple [stack] s either...

Confusion complete? :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM