开发者

Address Space Layout for a Multithreaded Linux Process

I want to know the full detail of the address space layout of a multithreaded Linux Process for both 64 bit and 32 bit. Link to any article th开发者_运维问答at describes it will be appreciated. And note that I need to know full details, not just an overview, because I will be directly dealing with it. So I need to know for example, where are the thread stacks located, the heap, thread private data etc...


Thread stacks are allocated with mmap at thread start (or even before - you can set the stack space in pthread_attrs). TLS data is stored in the beginning of thread's stack. Size of thread's stacks is fixed, typically it is from 2 to 8 MB. Stack size of each thread can't be changed while the thread is live. (First thread - running main - is still uses main stack at the end of address space and this stack may grow and shrink.) Heap and code is shared between all threads. Mutexes can be anywhere in data section - it is just a struct.

The mmap of thread's stack is not fixed at any address:

Glibc sources

 mem = mmap (NULL, size, prot,
                  MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);

PS modern GCC allows threads stack to be unlimited with SplitStacks feature

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜