Conversation

So while your supposedly source materials are correct, you interpreted it wrong, and your statement ("This exception is usually caught by the _chkstk routine") is simply just wrong. Nothing in those links and quotes says anything equivalent to that.
1
1
In case you're wondering where the magic *actually* happens, check nt!MiCheckForUserStackOverflow
1
1
That is not what your article states. It states that _chkstk catches exceptions. Can you provide a source to that?
1
1
Neither does any catching, and both relies on the OS (MiCheckForUserStackOverflow) to do the catching and allocation
Image
1
Thinking that _chkstk catches anything, or that it directly allocates pages is a complete misunderstanding of how stack growing works. Stack pages are allocated by the kernel, whenever the guard pages are hit. Probing is necessary so that a single logical allocation can't skip 1/
1
1
over enough memory without touching anything that would result in an address past the guard pages. For small stack functions, it is not needed exactly because when they're called, the call instruction will touch the stack page when pushing the return address. 2/
1
1
Ultimately, it does not matter how one does the stack probe. Some do the allocation inside, some do it outside the probe function. Gcc can inline it too. You can also use your own probing function. It does not matter how the pages are touched, they just need to be written. 3/
The reason it does not matter is that the OS is doing the heavy lifting. All you need to care about is not skipping too much on the stack without touching the memory inbetween. 4/4
1
1
* just to clarify, two meanings of allocation are mentioned here: logical allocation (sub rsp) and page allocation (what the kernel is doing). Should be obvious which is referring to which.
1
2
Show replies