diff --git a/reactos/lib/sdk/crt/crt.rbuild b/reactos/lib/sdk/crt/crt.rbuild index dfa2df664e0..eb4a65895ab 100644 --- a/reactos/lib/sdk/crt/crt.rbuild +++ b/reactos/lib/sdk/crt/crt.rbuild @@ -6,6 +6,7 @@ chkstk_asm.s + chkstk_ms.s diff --git a/reactos/lib/sdk/crt/except/amd64/chkstk_ms.s b/reactos/lib/sdk/crt/except/amd64/chkstk_ms.s new file mode 100644 index 00000000000..7db1e7b366c --- /dev/null +++ b/reactos/lib/sdk/crt/except/amd64/chkstk_ms.s @@ -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 + * Kai Tietz + * Timo Kreuzer (timo.kreuzer@reactos.org) + */ + +/* INCLUDES ******************************************************************/ + +#include +#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 */ diff --git a/reactos/lib/sdk/crt/except/i386/chkstk_ms.s b/reactos/lib/sdk/crt/except/i386/chkstk_ms.s new file mode 100644 index 00000000000..dac2ae799d9 --- /dev/null +++ b/reactos/lib/sdk/crt/except/i386/chkstk_ms.s @@ -0,0 +1,59 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * PURPOSE: Stack checker + * PROGRAMERS: KJK::Hyperion + * Richard Henderson + * Kai Tietz + * Timo Kreuzer + */ + +#include +#include + +#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 diff --git a/reactos/lib/sdk/crt/libcntpr.rbuild b/reactos/lib/sdk/crt/libcntpr.rbuild index 69dd60474b1..ca472b54487 100644 --- a/reactos/lib/sdk/crt/libcntpr.rbuild +++ b/reactos/lib/sdk/crt/libcntpr.rbuild @@ -33,6 +33,7 @@ chkstk_asm.s + chkstk_ms.s seh.s