some topics below was a question about the default size of windows stack. I read there (and also in a book), that there is an initial size of 1MB. What happens, if I use more memory? Does windows swap it or will the allocation fail? What happens if it fails - which exception occurs? And two more questions - how generates windows the starting address of the esp register at start of program? Has it its own ss segment like under Win3.11? beaster.
1) At Stack overflow, it simply hangs (win95)... 2) I don't know excactly all the details but there are 2 records in the PE header that set the Minimum and the Maximum Stack size. I do not understand why 2 values instead of one, but there are... betov.
- The default stack size is 1 MB. But you can override that by specifying /STACK switch. Windows commits (by default) two pages initially to that stack space: the remaining stack space is reserved. So the stack initially has 4096*2 bytes. The second commited page has PAGE_GUARD attribute. The stack can grows up to 1 MB by default.
- If you use more memory *incrementally*,ie, by pushing values on the stack (or using recursive functions), when the memory in the guard page is used, Windows will be notified and it'll commit more memory to the stack and mark the last commited page as guard page.
- The problem occurs when you allocate MORE than the available committed stack memory such as my richedit control tutorial no.35. In effect, you "skip" over the guard page and try to use the reserved stack space. Windows, of course, is not notified that you are using more stack memory than is available so page fault occurs.
- The PE loader reserves/commits the stack so it knows where the stack begins. Since Windows uses flat memory model, the value in ss is irrelevant : you can use esp with any segment register, eg, ds, es etc.