Skip to content

Commit 956812b

Browse files
committed
rt: Have __morestack conform to the calling convention that LLVM generates on x86
1 parent 151aaf8 commit 956812b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/rt/arch/i386/morestack.S

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,34 @@
88
#if defined(__APPLE__) || defined(_WIN32)
99
#define RUST_NEW_STACK _rust_new_stack
1010
#define RUST_DEL_STACK _rust_del_stack
11+
#define MORESTACK ___morestack
1112
#else
1213
#define RUST_NEW_STACK rust_new_stack
1314
#define RUST_DEL_STACK rust_del_stack
15+
#define MORESTACK __morestack
1416
#endif
1517

1618
.globl RUST_NEW_STACK
1719
.globl RUST_DEL_STACK
1820

19-
.globl __morestack
21+
.globl MORESTACK
2022

21-
__morestack:
22-
pushl %edx // param 2: size of arguments
23-
leal 8(%esp),%eax
24-
pushl %eax // param 1: starting addr of arguments
25-
pushl %ecx // param 0: amount of space needed
23+
MORESTACK:
24+
pushl 8(%esp) // argsz > ra stksz argsz x x ra args
25+
leal 28(%esp),%eax // argsz ra stksz argsz x x ra args
26+
pushl %eax // argp > argsz ra stksz argsz x x ra args
27+
pushl 12(%esp) // stksz > argp argsz ra stksz argsz x x ra args
2628
calll RUST_NEW_STACK
29+
addl $12,%esp // ra stksz argsz x x ra args
2730

2831
movl (%esp),%edx // Grab the return pointer.
2932
incl %edx // Skip past the `ret`.
3033
movl %eax,%esp // Switch to the new stack.
31-
calll *%edx // Enter the new function.
34+
calll *%edx // Re-enter the function that called us.
3235

3336
// Now the function that called us has returned, so we need to delete the
3437
// old stack space.
3538
calll RUST_DEL_STACK
36-
movl %eax,%esp // Switch back to the old stack.
37-
retl
39+
movl %eax,%esp
40+
retl $8 // ra stksz argsz x x ra args
3841

0 commit comments

Comments
 (0)