Allocating a buffer of more a page size on stack will corrupt memory? Allocating a buffer of more a page size on stack will corrupt memory? windows windows

Allocating a buffer of more a page size on stack will corrupt memory?


Excellent question (+1).

There's a trick, and few people know about it (besides driver writers).

When you allocate large buffer on the stack - the compiler automatically adds so-called stack probes. It's an extra code (implemented in CRT usually), which probes the allocated region, page-by-page, in the needed order.

EDIT:

The function is _chkstk.


The fault doesn't reach your program - it is handled by the operating system. Similar thing happens when your program tries to read memory that happens to be written into the swap file - a trap occurs and the operating system unswaps the page and your program continues.