Skip to content

Commit 32087f5

Browse files
committed
rt: Don't clobber fastcc argument registers in __morestack
1 parent be33529 commit 32087f5

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/rt/arch/i386/morestack.S

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ MORESTACK:
6161
.cfi_def_cfa_register %ebp
6262
#endif
6363

64+
// NB: This can be called with the fastcc convention so we
65+
// have to preserve any argument registers we want to use
66+
6467
// FIXME (1226): main is compiled with the split-stack prologue,
6568
// causing it to call __morestack, so we have to jump back out
6669
subl $28,%esp
@@ -94,9 +97,9 @@ MORESTACK:
9497

9598
#ifdef __APPLE__
9699
call 1f
97-
1: popl %ebx
98-
movl L_upcall_new_stack$non_lazy_ptr-1b(%ebx),%ecx
99-
movl %ecx, 4(%esp)
100+
1: popl %eax
101+
movl L_upcall_new_stack$non_lazy_ptr-1b(%eax),%eax
102+
movl %eax, 4(%esp)
100103
#else
101104
movl $UPCALL_NEW_STACK,4(%esp)
102105
#endif
@@ -105,11 +108,11 @@ MORESTACK:
105108
movl %eax,(%esp)
106109
call UPCALL_CALL_C
107110

108-
movl 32(%esp),%edx // Grab the return pointer.
109-
inc %edx // Skip past the ret instruction in the parent fn
111+
movl 32(%esp),%eax // Grab the return pointer.
112+
inc %eax // Skip past the ret instruction in the parent fn
110113

111114
movl 8(%esp),%esp // Switch stacks.
112-
call *%edx // Re-enter the function that called us.
115+
call *%eax // Re-enter the function that called us.
113116

114117
// Now the function that called us has returned, so we need to delete the
115118
// old stack space.
@@ -121,9 +124,9 @@ MORESTACK:
121124

122125
#ifdef __APPLE__
123126
call 1f
124-
1: popl %ebx
125-
movl L_upcall_del_stack$non_lazy_ptr-1b(%ebx),%ecx
126-
pushl %ecx
127+
1: popl %eax
128+
movl L_upcall_del_stack$non_lazy_ptr-1b(%eax),%eax
129+
pushl %eax
127130
#else
128131
pushl $UPCALL_DEL_STACK
129132
#endif
@@ -141,14 +144,14 @@ MORESTACK:
141144
retl $8
142145

143146
.L$bail:
144-
movl 32(%esp),%edx
145-
inc %edx
147+
movl 32(%esp),%eax
148+
inc %eax
146149

147150
addl $28, %esp
148151
popl %ebp
149152
addl $4+8,%esp
150153

151-
jmpl *%edx
154+
jmpl *%eax
152155

153156
#if defined(__linux__) || defined(__APPLE__)
154157
.cfi_endproc

0 commit comments

Comments
 (0)