Allocating a larger page buffer on the stack will cause memory corruption?

Windows implements a stack, followed by: the specified page should be fixed to the stack page. The protective flag is protected. Therefore, when thead refers to the address on a hidden page, a memory error occurs, due to which the memory manager pushes the protected page on the stack and clears the flag of the protected page, and then reserves the new page as protected.

when I allocate a buffer that is larger than one page (4 KB), however there was no expected error. Why?

+4
memory-management stack windows size
Nov 08 '10 at 12:00
source share
2 answers

Great question (+1).

There is a trick, and few know about it (besides the authors of the drivers).

When you allocate a large buffer on the stack, the compiler automatically adds the so-called stack probes . This is additional code (commonly used in CRT) that requests the selected area, per page in the desired order.

EDIT:

_chkstk function.

+6
Nov 08 '10 at
source share
— -

The error does not reach your program - it is processed by the operating system. A similar situation happens when your program tries to read the memory that is written to the page file - a trap occurs, and the operating system discards the page and your program continues.

0
Nov 08 '10 at 12:16
source share



All Articles