Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack on Windows - where is it?

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) ?

like image 521
Johnny Pauling Avatar asked Jan 15 '23 13:01

Johnny Pauling


1 Answers

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:

enter image description here

like image 65
Mark Tolonen Avatar answered Jan 24 '23 13:01

Mark Tolonen