Each thread has its own stack space, which is specified when CreateThread, while the main thread stack is specified by XP when creating the process, setting a breakpoint under vs2008, interrupting the execution of the program, and seeing the value of the main thread esp as 0x00124914, This pointer falls in the following area:
The upper limit of this space is 0x0013 0000, which is consistent with the value of the stackbase in the NT_TIB structure we read, which means that the stack space of the main thread grows from 0x0013 0000. But the Stacklimit value inside the NT_TIB is only 0x00000 a000, it is obvious that the available stack space is more than that.
Note that the allocated base address for the memory area above is not the same as the start of this memory area, and look at the complete block of memory:
In other words, Windows allocates this space when it is from 0x0003 0000 ~ 0x0013 0000, just 1M, which is also by default the main thread of the stack space size. But since we have not actually used such a large stack space, the state of this space 0x0003 0000 begins is mem_reserve.
Looking at this memory area in the middle, it's protected by a page_guard,msdn that explains this sign bit:
Pages in the region become guard pages. Any attempt to access a guard page causes the system to raise a status_guard_page_violation exception and turn off the Gua Rd page status. Guard pages Thus act as a one-time access alarm. For more information, creating Guard Pages.
When a access attempt leads the system to turn off guard page status, the underlying page protection takes.
As you can probably tell, when ESP goes down more than it is currently allocated, an exception is triggered, and Windows adjusts the properties of the pages of memory. Of course, ESP cannot grow beyond the size of the entire stack, otherwise the program cannot continue.
Under the guidance of Page_guard, we can easily find other stacks from these memory blocks: