File tree 5 files changed +88
-4
lines changed
5 files changed +88
-4
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,7 @@ if (NOT MSVC)
177
177
set (x86_64_SOURCES
178
178
${x86_64_SOURCES}
179
179
x86_64/chkstk.S)
180
+ x86_64/chkstk2.S)
180
181
endif ()
181
182
182
183
set (i386_SOURCES
@@ -200,6 +201,7 @@ if (NOT MSVC)
200
201
set (i386_SOURCES
201
202
${i386_SOURCES}
202
203
i386/chkstk.S)
204
+ i386/chkstk2.S)
203
205
endif ()
204
206
205
207
set (i686_SOURCES
Original file line number Diff line number Diff line change @@ -19,13 +19,13 @@ DEFINE_COMPILERRT_FUNCTION(__chkstk_ms)
19
19
jb 1f
20
20
2 :
21
21
sub $ 0x1000 , % ecx
22
- orl $ 0 , (% ecx )
22
+ test % ecx , (% ecx )
23
23
sub $ 0x1000 , % eax
24
24
cmp $ 0x1000 , % eax
25
25
ja 2b
26
26
1 :
27
27
sub % eax , % ecx
28
- orl $ 0 , (% ecx )
28
+ test % ecx , (% ecx )
29
29
pop % eax
30
30
pop % ecx
31
31
ret
Original file line number Diff line number Diff line change
1
+ // This file is dual licensed under the MIT and the University of Illinois Open
2
+ // Source Licenses. See LICENSE.TXT for details.
3
+
4
+ #include "../assembly.h"
5
+
6
+ #ifdef __i386__
7
+
8
+ // _chkstk (_alloca) routine - probe stack between %esp and (%esp-%eax) in 4k increments,
9
+ // then decrement %esp by %eax. Preserves all registers except %esp and flags.
10
+ // This routine is windows specific
11
+ // http://msdn.microsoft.com/en-us/library/ms648426.aspx
12
+
13
+ .text
14
+ .balign 4
15
+ DEFINE_COMPILERRT_FUNCTION(_alloca) // _chkstk and _alloca are the same function
16
+ DEFINE_COMPILERRT_FUNCTION(__chkstk)
17
+ push %ecx
18
+ cmp $0x1000 ,%eax
19
+ lea 8 (%esp ),%ecx // esp before calling this routine -> ecx
20
+ jb 1f
21
+ 2:
22
+ sub $0x1000 ,%ecx
23
+ test %ecx ,(%ecx )
24
+ sub $0x1000 ,%eax
25
+ cmp $0x1000 ,%eax
26
+ ja 2b
27
+ 1:
28
+ sub %eax ,%ecx
29
+ test %ecx ,(%ecx )
30
+
31
+ lea 4 (%esp ),%eax // load pointer to the return address into eax
32
+ mov %ecx ,%esp // install the new top of stack pointer into esp
33
+ mov -4 (%eax ),%ecx // restore ecx
34
+ push (%eax ) // push return address onto the stack
35
+ sub %esp ,%eax // restore the original value in eax
36
+ ret
37
+ END_COMPILERRT_FUNCTION(__chkstk)
38
+ END_COMPILERRT_FUNCTION(_alloca)
39
+
40
+ #endif // __i386__
Original file line number Diff line number Diff line change @@ -24,13 +24,13 @@ DEFINE_COMPILERRT_FUNCTION(___chkstk_ms)
24
24
jb 1f
25
25
2 :
26
26
sub $ 0x1000 , % rcx
27
- orl $ 0 , (% rcx )
27
+ test % rcx , (% rcx )
28
28
sub $ 0x1000 , % rax
29
29
cmp $ 0x1000 , % rax
30
30
ja 2b
31
31
1 :
32
32
sub % rax , % rcx
33
- orl $ 0 , (% rcx )
33
+ test % rcx , (% rcx )
34
34
pop % rax
35
35
pop % rcx
36
36
ret
Original file line number Diff line number Diff line change
1
+ // This file is dual licensed under the MIT and the University of Illinois Open
2
+ // Source Licenses. See LICENSE.TXT for details.
3
+
4
+ #include "../assembly.h"
5
+
6
+ #ifdef __x86_64__
7
+
8
+ // _chkstk (_alloca) routine - probe stack between %rsp and (%rsp-%rax) in 4k increments,
9
+ // then decrement %rsp by %rax. Preserves all registers except %rsp and flags.
10
+ // This routine is windows specific
11
+ // http://msdn.microsoft.com/en-us/library/ms648426.aspx
12
+
13
+ .text
14
+ .balign 4
15
+ DEFINE_COMPILERRT_FUNCTION(__alloca)
16
+ mov %rcx ,%rax // x64 _alloca is a normal function with parameter in rcx
17
+ // fallthrough
18
+ DEFINE_COMPILERRT_FUNCTION(___chkstk)
19
+ push %rcx
20
+ cmp $0x1000 ,%rax
21
+ lea 16 (%rsp ),%rcx // rsp before calling this routine -> rcx
22
+ jb 1f
23
+ 2:
24
+ sub $0x1000 ,%rcx
25
+ test %rcx ,(%rcx )
26
+ sub $0x1000 ,%rax
27
+ cmp $0x1000 ,%rax
28
+ ja 2b
29
+ 1:
30
+ sub %rax ,%rcx
31
+ test %rcx ,(%rcx )
32
+
33
+ lea 8 (%rsp ),%rax // load pointer to the return address into rax
34
+ mov %rcx ,%rsp // install the new top of stack pointer into rsp
35
+ mov -8 (%rax ),%rcx // restore rcx
36
+ push (%rax ) // push return address onto the stack
37
+ sub %rsp ,%rax // restore the original value in rax
38
+ ret
39
+ END_COMPILERRT_FUNCTION(___chkstk)
40
+ END_COMPILERRT_FUNCTION(__alloca)
41
+
42
+ #endif // __x86_64__
You can’t perform that action at this time.
0 commit comments