#include #include #include #include void stack_overflow(int n) { // Silence warnings about infinite recursion if (n == 0xdeadbeef) return; // Allocate more than 4k bytes on the stack. std::array blob; // Repeat... stack_overflow(n + 1); // Prevent blob from being optimized away std::memcpy(blob.data(), blob.data(), n); std::cout << blob.data(); } int main(int argc, char* argv[]) { using namespace boost::context; // Calling stack_overflow outside of Boost context results in a regular stack // overflow exception. // stack_overflow(0); execution_context source([](execution_context sink, int) { // Calling stack_overflow inside results in a memory access violation caused // by the compiler generated _chkstk function. stack_overflow(0); return sink; }); source(0); return EXIT_SUCCESS; }