Is it possible to allocate a memory buffer of about 64KB size with Win32 API and have some kind of a "guard zone" (I do not know the correct term for that) after that buffer so C++ code will write to the buffer and throw a SEH exception if the buffer is full and it attempts to write to the "guard zone"?
Yes. Use VirtualAlloc
. With VirutalProtect
used in conjunction, you can even make this guard zone only memory page sized (4096 bytes, not whole 64KB).
Note that for stack it is handled by OS, you can only control this by SetThreadStackGuarantee
to set the amount of buffer before stack overflow, and _resetstkoflw
to fix (restore) guard after stack overflow exception is hadnled.