1 // Mark stack as non-executable
2 #if defined(__linux__) && defined(__ELF__)
3 .section .note.GNU-stack, "", @progbits
9 See i386/morestack.S for the lengthy, general explanation.
14 #if defined(__APPLE__)
15 #define UPCALL_NEW_STACK _upcall_new_stack
16 #define UPCALL_DEL_STACK _upcall_del_stack
17 #define MORESTACK ___morestack
19 #define UPCALL_NEW_STACK upcall_new_stack
20 #define UPCALL_DEL_STACK upcall_del_stack
21 #define MORESTACK __morestack
24 .globl UPCALL_NEW_STACK
25 .globl UPCALL_DEL_STACK
28 #if defined(__linux__) || defined(__FreeBSD__)
31 #if defined(__APPLE__)
32 .private_extern MORESTACK
37 .type MORESTACK,@function
41 #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
46 // The CFA is 24 bytes above the register that it will
47 // be associated with for this frame (%rbp). That is 8
48 // bytes greater than a normal frame, to allow the unwinder
49 // to skip the partial frame of the original function.
50 .cfi_def_cfa_offset 24
51 // %rbp is -24 bytes from the CFA
54 // Calculate the CFA as on offset from %ebp
55 .cfi_def_cfa_register %rbp
59 // Save argument registers of the original function
67 // Calculate the address of the stack arguments.
68 // We have the base pointer, __morestack's return address,
69 // and __morestack's caller's return address to skip
71 addq $24, %rax // Base pointer, return address x2
73 // The arguments to __morestack are passed in %r10 & %r11
75 movq %r11, %rdx // Size of stack arguments
76 movq %rax, %rsi // Address of stack arguments
77 movq %r10, %rdi // The amount of stack needed
83 call UPCALL_NEW_STACK@PLT
86 call UPCALL_NEW_STACK@PLT
89 // Pop the saved arguments
99 movq 8(%rbp),%r10 // Grab the return pointer.
100 incq %r10 // Skip past the `ret` in our parent frame
101 movq %rax,%rsp // Switch to the new stack.
103 call *%r10 // Reenter the caller function
105 // Switch back to the rust stack
108 // Save the return value
112 call UPCALL_DEL_STACK
115 call UPCALL_DEL_STACK@PLT
118 call UPCALL_DEL_STACK@PLT
121 popq %rax // Restore the return value