xref: /reactos/sdk/lib/crt/except/stack.c (revision 5100859e)
1 #include <precomp.h>
2 
3 /*********************************************************************
4 *              _chkesp (MSVCRT.@)
5 *
6 * Trap to a debugger if the value of the stack pointer has changed.
7 *
8 * PARAMS
9 *  None.
10 *
11 * RETURNS
12 *  Does not return.
13 *
14 * NOTES
15 *  This function is available for iX86 only.
16 *
17 *  When VC++ generates debug code, it stores the value of the stack pointer
18 *  before calling any external function, and checks the value following
19 *  the call. It then calls this function, which will trap if the values are
20 *  not the same. Usually this means that the prototype used to call
21 *  the function is incorrect.  It can also mean that the .spec entry has
22 *  the wrong calling convention or parameters.
23 */
24 
25 #ifdef __i386__
26 
27 void _chkesp_failed(void)
28 {
29     ERR("stack got corrupted!\n");
30     __debugbreak();
31 }
32 
33 #endif  /* __i386__ */
34 
35 /*********************************************************************
36  * _resetstkoflw (MSVCRT.@)
37  */
38 int CDECL _resetstkoflw(void)
39 {
40     int stack_addr;
41     DWORD oldprot;
42 
43     /* causes stack fault that updates NtCurrentTeb()->Tib.StackLimit */
44     return VirtualProtect(&stack_addr, 1, PAGE_GUARD|PAGE_READWRITE, &oldprot);
45 }
46