8
8
#if defined(__APPLE__) || defined(_WIN32)
9
9
#define RUST_NEW_STACK2 _rust_new_stack2
10
10
#define RUST_DEL_STACK _rust_del_stack
11
+ #define RUST_DEL_STACK _rust_del_stack
12
+ #define RUST_GET_PREV_STACK _rust_get_prev_stack
11
13
#define UPCALL_CALL_C _upcall_call_shim_on_c_stack
12
14
#define MORESTACK ___morestack
13
15
#else
14
16
#define RUST_NEW_STACK2 rust_new_stack2
15
17
#define RUST_DEL_STACK rust_del_stack
18
+ #define RUST_DEL_STACK rust_del_stack
19
+ #define RUST_GET_PREV_STACK rust_get_prev_stack
16
20
#define UPCALL_CALL_C upcall_call_shim_on_c_stack
17
21
#define MORESTACK __morestack
18
22
#endif
@@ -59,6 +63,11 @@ MORESTACK:
59
63
movq %rsp , %rbp
60
64
.cfi_def_cfa_register %rbp
61
65
66
+ // Alignment
67
+ pushq $0
68
+
69
+ // FIXME: libgcc also saves rax. not sure if we need to
70
+
62
71
// Save argument registers
63
72
pushq %rdi
64
73
pushq %rsi
@@ -77,15 +86,46 @@ MORESTACK:
77
86
pushq %rcx // Address of stack arguments
78
87
pushq %r10 // The amount of stack needed
79
88
80
- lea RUST_NEW_STACK2@PLT(%rip ), %rsi
81
- mov %rsp , %rdi
89
+ leaq RUST_NEW_STACK2@PLT(%rip ), %rsi
90
+ movq %rsp , %rdi
82
91
call UPCALL_CALL_C@PLT
92
+
93
+ // Pop the new_stack_args struct
94
+ addq $32 , %rsp
95
+
96
+ // Pop the saved arguments
97
+ popq %r9
98
+ popq %r8
99
+ popq %rcx
100
+ popq %rdx
101
+ popq %rsi
102
+ popq %rdi
83
103
84
- mov (%rsp ),%rdx // Grab the return pointer.
85
- inc %rdx // Skip past the `ret`.
86
- mov %rax ,%rsp // Switch to the new stack.
87
- call *%rdx // Enter the new function.
104
+ movq 8 (%rbp ),%r10 // Grab the return pointer.
105
+ incq %r10 // Skip past the `ret` in our parent frame
106
+ movq %rax ,%rsp // Switch to the new stack.
88
107
108
+ call *%r10 // Reenter the caller function
109
+
110
+ leaq RUST_GET_PREV_STACK@PLT(%rip ), %rsi
111
+ movq $0 , %rdi
112
+ call UPCALL_CALL_C@PLT
113
+
114
+ // Switch back to the rust stack, positioned
115
+ // where we pushed %ebp
116
+ movq %rax , %rsp
117
+
118
+ // Align the stack again
119
+ pushq $0
120
+
121
+ leaq RUST_DEL_STACK@PLT(%rip ), %rsi
122
+ movq $0 , %rdi
123
+ call UPCALL_CALL_C@PLT
124
+
125
+ addq $8 , %rsp
126
+ popq %rbp
127
+ ret
128
+
89
129
.cfi_endproc
90
130
#else
91
131
MORESTACK:
0 commit comments