- Implement __chkstk_ms for x86 and amd64
- amd64 code is based on code by Kai Tietz and Richard Henderson
- x86 code is based on old __chkstk implementation and code by Kai Tietz and Richard Henderson
- Function is required by newer gcc versions

svn path=/trunk/; revision=51747
This commit is contained in:
Timo Kreuzer 2011-05-14 19:12:09 +00:00
parent 75b8d216e2
commit c016e5d41e
4 changed files with 112 additions and 0 deletions

View file

@ -6,6 +6,7 @@
<if property="ARCH" value="i386">
<directory name="i386">
<file>chkstk_asm.s</file>
<file>chkstk_ms.s</file>
</directory>
</if>
<if property="ARCH" value="powerpc">

View file

@ -0,0 +1,51 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* PURPOSE: Implementation of _chkstk and _alloca_probe
* PROGRAMMERS Richard Henderson <rth@redhat.com>
* Kai Tietz <kai.tietz@onevision.com>
* Timo Kreuzer (timo.kreuzer@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include <asm.inc>
#define PAGE_SIZE 4096
/* CODE **********************************************************************/
.code64
PUBLIC ___chkstk_ms
//cfi_startproc()
___chkstk_ms:
push rcx /* save temps */
//cfi_push(%rcx)
push rax
//cfi_push(%rax)
cmp rax, PAGE_SIZE /* > 4k ?*/
lea rcx, [rsp + 24] /* point past return addr */
jb l_LessThanAPage
.l_MoreThanAPage:
sub rcx, PAGE_SIZE /* yes, move pointer down 4k */
or rcx, 0 /* probe there */
sub rax, PAGE_SIZE /* decrement count */
cmp rax, PAGE_SIZE
ja l_MoreThanAPage /* and do it again */
.l_LessThanAPage:
sub rcx, rax
or [rcx], 0 /* less than 4k, just peek here */
pop rax
//cfi_pop(%rax)
pop rcx
//cfi_pop(%rcx)
ret
//cfi_endproc()
END
/* EOF */

View file

@ -0,0 +1,59 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Stack checker
* PROGRAMERS: KJK::Hyperion <noog@libero.it>
* Richard Henderson <rth@redhat.com>
* Kai Tietz <kai.tietz@onevision.com>
* Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <asm.inc>
#include <ks386.inc>
#define PAGE_SIZE 4096
PUBLIC ___chkstk_ms
.code
/* Special version, that does only probe and not allocate */
___chkstk_ms:
/* EAX = size to be allocated */
/* save the ECX and EAX register */
push ecx
push eax
/* ECX = top of the previous stack frame */
lea ecx, [esp + 12]
/* probe the desired memory, page by page */
cmp eax, PAGE_SIZE
jl .l_LessThanAPage
.l_MoreThanAPage:
/* raise the top of the stack by a page and probe */
sub ecx, PAGE_SIZE
test [ecx], eax
/* loop if still more than a page must be probed */
sub eax, PAGE_SIZE
cmp eax, PAGE_SIZE
jge .l_MoreThanAPage
.l_LessThanAPage:
/* raise the top of the stack by EAX bytes (size % 4096) and probe */
sub ecx, eax
test [ecx], eax
/* restore ECX and EAX */
pop eax
pop ecx
/* return */
ret
/* EOF */
END

View file

@ -33,6 +33,7 @@
<if property="ARCH" value="i386">
<directory name="i386">
<file>chkstk_asm.s</file>
<file>chkstk_ms.s</file>
<file>seh.s</file>
</directory>
</if>