[DISKPART] Fix magic values in CreateLogicalPartition() and CreatePrimaryPartition()
[reactos.git] / sdk / lib / crt / except / i386 / chkstk_asm.s
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Stack checker
5 * FILE: lib/sdk/crt/except/i386/chkstk_asm.s
6 * PROGRAMER: KJK::Hyperion <noog@libero.it>
7 */
8
9 #include <asm.inc>
10 #include <ks386.inc>
11
12 #define PAGE_SIZE 4096
13
14 PUBLIC __chkstk
15 PUBLIC __alloca_probe
16 PUBLIC __alloca_probe_16
17 .code
18
19 /* 16 byte aligned alloca probe
20 * EAX = size to be allocated */
21 __alloca_probe_16:
22 /* save the ECX register */
23 push ecx
24
25 /* ecx = top of the previous stack frame */
26 lea ecx, [esp + 8]
27
28 /* Calculate end of allocation */
29 sub ecx, eax
30
31 /* Get the misalignment */
32 and ecx, 15
33
34 /* Add the misalignment to the original alloc size */
35 add eax, ecx
36
37 /* Check for overflow */
38 jnc l1
39
40 /* Set maximum value */
41 mov eax, HEX(0ffffffff)
42 l1:
43 /* Restore ecx */
44 pop ecx
45 /* Fall through to __chkstk */
46
47 /*
48 _chkstk() is called by all stack allocations of more than 4 KB. It grows the
49 stack in areas of 4 KB each, trying to access each area. This ensures that the
50 guard page for the stack is hit, and the stack growing triggered
51 */
52 __chkstk:
53 __alloca_probe:
54
55 /* EAX = size to be allocated */
56 /* save the ECX register */
57 push ecx
58
59 /* ECX = top of the previous stack frame */
60 lea ecx, [esp + 8]
61
62 /* probe the desired memory, page by page */
63 cmp eax, PAGE_SIZE
64 jl .l_LessThanAPage
65
66 .l_MoreThanAPage:
67
68 /* raise the top of the stack by a page and probe */
69 sub ecx, PAGE_SIZE
70 test [ecx], eax
71
72 /* loop if still more than a page must be probed */
73 sub eax, PAGE_SIZE
74 cmp eax, PAGE_SIZE
75 jge .l_MoreThanAPage
76
77 .l_LessThanAPage:
78
79 /* raise the top of the stack by EAX bytes (size % 4096) and probe */
80 sub ecx, eax
81 test [ecx], eax
82
83 /* EAX = top of the stack */
84 mov eax, esp
85
86 /* allocate the memory */
87 mov esp, ecx
88
89 /* restore ECX */
90 mov ecx, [eax]
91
92 /* restore the return address */
93 mov eax, [eax + 4]
94 push eax
95
96 /* return */
97 ret
98
99 /* EOF */
100 END