How `alloca` Allocates Stack Memory Without Skipping the Guard Page
How do functions like alloca allocate memory from the stack?
Raymond Chen explains how `_alloca` and similar functions allocate memory from the stack while ensuring the guard page is properly probed. Using a concrete x86-64 example, he shows that `_alloca` calls the same `__chkstk` function used for local frame setup, which probes the stack in pages to avoid skipping over the guard page. This prevents potential stack overflow issues.
Observe that the same `__chkstk` function is used both for performing the initial stack probe when creating the local frame as well as for the `alloca()`.