I learned default stack size for each process is limited to 8MB and mmap_base is calculated based on stack size in rlimit and random value. Code below is mmap_base function which calculates mmap_base address in x86(linux/include/uapi/asm-generic/resource.h).
static unsigned long mmap_base(unsigned long rnd)
{
unsigned long gap = rlimit(RLIMIT_STACK);
if (gap < MIN_GAP)
gap = MIN_GAP;
else if (gap > MAX_GAP)
gap = MAX_GAP;
return PAGE_ALIGN(TASK_SIZE - gap - rnd);
}
I am wondering what if program stack size is greater than 8MB+rnd value? I mean what if stack size grows above mmap_base ? If I allocate stack memory above 8MB is it just fail with segmentation fault? If kernel enlarge stack size automatically is it possible to move contents in mmap_base to other spaces?