Skip to content

Commit 1bfc4e2

Browse files
committed
rt: Save and restore %rax/%eax in __morestack
This doesn't matter now since we use an out pointer for return values but it's sure to show up mysteriously someday.
1 parent c3569ab commit 1bfc4e2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/rt/arch/i386/morestack.S

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,17 @@ MORESTACK:
198198
// Realign stack - remember that __morestack was called misaligned
199199
subl $12, %esp
200200

201+
// Save the return value of the function we allocated space for
202+
movl %eax, (%esp)
203+
201204
// Now that we're on the return path we want to avoid
202205
// stomping on %eax. FIXME: Need to save and restore %eax to
203206
// actually preserve it across the call to delete the stack
204207
call UPCALL_DEL_STACK
205208

209+
// And restore it
210+
movl (%esp), %eax
211+
206212
addl $12,%esp
207213

208214
popl %ebp

src/rt/arch/x86_64/morestack.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ MORESTACK:
100100
// Switch back to the rust stack
101101
movq %rbp, %rsp
102102

103-
// Align the stack again
104-
pushq $0
103+
// Save the return value
104+
pushq %rax
105105

106106
// FIXME: Should preserve %rax here
107107
#ifdef __APPLE__
@@ -111,7 +111,7 @@ MORESTACK:
111111
call UPCALL_DEL_STACK@PLT
112112
#endif
113113

114-
addq $8, %rsp
114+
popq %rax // Restore the return value
115115
popq %rbp
116116
// FIXME: I don't think these rules are necessary
117117
// since the unwinder should never encounter an instruction

0 commit comments

Comments
 (0)