Conversation

"When you enter a function (VC++ with the stack checking enabled), it will call the _chkstk located in CHKSTK.ASM. This function does a stack page probing and causes the necessary pages of memory to be allocated using the guard page scheme, if possible."
1
1
Nowhere in these three quotes does it say it catches anything. "increases the stack", "causes the necessary pages of memory to be allocated". That is because it does not catch anything. It causes exceptions that are caught and memory allocated in place of the guard pages.
1
1
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/
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/
1
1
Show replies