Path: blob/master/libs/compiler-rt/lib/builtins/x86_64/chkstk2.S
12348 views
// This file is dual licensed under the MIT and the University of Illinois Open1// Source Licenses. See LICENSE.TXT for details.23#include "../assembly.h"45#ifdef __x86_64__67// _chkstk (_alloca) routine - probe stack between %rsp and (%rsp-%rax) in 4k increments,8// then decrement %rsp by %rax. Preserves all registers except %rsp and flags.9// This routine is windows specific10// http://msdn.microsoft.com/en-us/library/ms648426.aspx1112.text13.balign 414DEFINE_COMPILERRT_FUNCTION(__alloca)15mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx16// fallthrough17DEFINE_COMPILERRT_FUNCTION(___chkstk)18push %rcx19cmp $0x1000,%rax20lea 16(%rsp),%rcx // rsp before calling this routine -> rcx21jb 1f222:23sub $0x1000,%rcx24test %rcx,(%rcx)25sub $0x1000,%rax26cmp $0x1000,%rax27ja 2b281:29sub %rax,%rcx30test %rcx,(%rcx)3132lea 8(%rsp),%rax // load pointer to the return address into rax33mov %rcx,%rsp // install the new top of stack pointer into rsp34mov -8(%rax),%rcx // restore rcx35push (%rax) // push return address onto the stack36sub %rsp,%rax // restore the original value in rax37ret38END_COMPILERRT_FUNCTION(___chkstk)39END_COMPILERRT_FUNCTION(__alloca)4041#endif // __x86_64__424344