This commit is contained in:
Jessie
2024-01-29 02:22:04 -05:00
parent b083ff2789
commit 7b5d0a799b

View File

@@ -2,8 +2,9 @@
pub unsafe extern "C" fn __chkstk() {
core::arch::asm!(
"push %rcx",
"push %rax",
"cmp $0x1000,%rax",
"lea 16(%rsp),%rcx", // rsp before calling this routine -> rcx
"lea 24(%rsp),%rcx",
"jb 1f",
"2:",
"sub $0x1000,%rcx",
@@ -14,11 +15,8 @@ pub unsafe extern "C" fn __chkstk() {
"1:",
"sub %rax,%rcx",
"test %rcx,(%rcx)",
"lea 8(%rsp),%rax", // load pointer to the return address into rax
"mov %rcx,%rsp", // install the new top of stack pointer into rsp
"mov -8(%rax),%rcx", // restore rcx
"push (%rax)", // push return address onto the stack
"sub %rsp,%rax", // restore the original value in rax
"pop %rax",
"pop %rcx",
"ret",
options(noreturn, att_syntax)
);