I'm a bit confused on where an exe stack is located.. I know that the CRT before the program runs initializes the heap by allocating an amount of heap (which in turn is allocated by the OS that allocates pages), but where's the stack? Is it on a page too? Or is it shared by all programs in user mode (ring3) by using a ring3 descriptor on the GDT (I think not but I'm not sure) ?
Windows will reserve a contiguous area of virtual memory (1MB by default) per thread. It then commits a few top-most pages of that memory region and marks a couple below that as guard pages. As the thread's stack grows downward, if a guard page is accessed an exception occurs and Windows commits the guard page and marks pages below that as guard.
You can explore this behavior with the excellent SysInternals utility VMMap. Below is a snippet from that tool:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With