renamed .S files so msvc does not try to compile the .c files with the same name...
[reactos.git] / reactos / lib / rtl / i386 / chkstk_asm.s
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * PURPOSE: Stack checker
6 * FILE: lib/ntdll/rtl/i386/chkstk.s
7 * PROGRAMER: KJK::Hyperion <noog@libero.it>
8 */
9
10 .globl __chkstk
11 .globl __alloca_probe
12
13 /*
14 _chkstk() is called by all stack allocations of more than 4 KB. It grows the
15 stack in areas of 4 KB each, trying to access each area. This ensures that the
16 guard page for the stack is hit, and the stack growing triggered
17 */
18 __chkstk:
19 __alloca_probe:
20
21 /* EAX = size to be allocated */
22 /* save the ECX register */
23 pushl %ecx
24
25 /* ECX = top of the previous stack frame */
26 leal 8(%esp), %ecx
27
28 /* probe the desired memory, page by page */
29 cmpl $0x1000, %eax
30 jge .l_MoreThanAPage
31 jmp .l_LessThanAPage
32
33 .l_MoreThanAPage:
34
35 /* raise the top of the stack by a page and probe */
36 subl $0x1000, %ecx
37 testl %eax, 0(%ecx)
38
39 /* loop if still more than a page must be probed */
40 subl $0x1000, %eax
41 cmpl $0x1000, %eax
42 jge .l_MoreThanAPage
43
44 .l_LessThanAPage:
45
46 /* raise the top of the stack by EAX bytes (size % 4096) and probe */
47 subl %eax, %ecx
48 testl %eax, 0(%ecx)
49
50 /* EAX = top of the stack */
51 movl %esp, %eax
52
53 /* allocate the memory */
54 movl %ecx, %esp
55
56 /* restore ECX */
57 movl 0(%eax), %ecx
58
59 /* restore the return address */
60 movl 4(%eax), %eax
61 pushl %eax
62
63 /* return */
64 ret
65
66 /* EOF */