Address space layout for a multi-threaded Linux process

I want to know full information about the location of the address space of a multi-threaded Linux process for both 64-bit and 32-bit. A link to any article that describes it will be appreciated. And note that I need to know the full details, not just the overview, because I will be directly involved in this. Therefore, I need to know, for example, where are the stacks of threads, heap, personal data of threads, etc.

+6
source share
1 answer

Thread stacks are allocated using mmap when the thread starts (or even earlier - you can set the stack space in pthread_attr s). TLS data is stored at the beginning of the stream stack. The size of the stacks of streams is fixed, as a rule, from 2 to 8 MB. The stack size for each thread cannot be changed while the thread is active. (First thread - running main - still uses the main stack at the end of the address space, and this stack can grow and shrink.) The heap and code are shared between all threads. Mutexes can be anywhere in the data section - it's just a structure.

mmap stream 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 stream stack unlimited with SplitStacks function

+6
source

Source: https://habr.com/ru/post/892118/


All Articles