Skip to content

Commit 438ff96

Browse files
committed
---
yaml --- r: 6574 b: refs/heads/master c: 52d7dc5 h: refs/heads/master v: v3
1 parent 9e6f5fe commit 438ff96

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a69eab16ec3435bd505a7dafcb9a82b5eace49a2
2+
refs/heads/master: 52d7dc5e0a218f1495da2057ac064811853a4c9c

trunk/src/rt/arch/i386/morestack.S

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
#endif
2626
#endif
2727

28-
// FIXME: Future LLVM patches remove these 8 alignment bytes from
29-
// the function prologue in order to match gcc's behavior
30-
#define ALIGNMENT 8
31-
#define RETURN_OFFSET 7
32-
3328
.globl UPCALL_NEW_STACK
3429
.globl UPCALL_DEL_STACK
3530
.globl RUST_GET_TASK
@@ -57,17 +52,17 @@ MORESTACK:
5752

5853
// FIXME (1226): main is compiled with the split-stack prologue,
5954
// causing it to call __morestack, so we have to jump back out
60-
subl $20,%esp
55+
subl $28,%esp
6156
calll RUST_GET_TASK
6257
testl %eax,%eax
6358
jz .L$bail
6459

6560
// The arguments to rust_new_stack2
66-
movl 32(%esp),%eax // Size of stack arguments
61+
movl 40(%esp),%eax // Size of stack arguments
6762
movl %eax,16(%esp)
68-
leal 40+ALIGNMENT(%esp),%eax // Address of stack arguments
63+
leal 48(%esp),%eax // Address of stack arguments
6964
movl %eax,12(%esp)
70-
movl 28(%esp),%eax // The amount of stack needed
65+
movl 36(%esp),%eax // The amount of stack needed
7166
movl %eax,8(%esp)
7267

7368
#ifdef __APPLE__
@@ -83,8 +78,8 @@ MORESTACK:
8378
movl %eax,(%esp)
8479
call UPCALL_CALL_C
8580

86-
movl 24(%esp),%edx // Grab the return pointer.
87-
addl $RETURN_OFFSET,%edx // Skip past the `add esp,4` and the `ret`.
81+
movl 32(%esp),%edx // Grab the return pointer.
82+
inc %edx // Skip past the ret instruction in the parent fn
8883

8984
movl %eax,%esp // Switch stacks.
9085
call *%edx // Re-enter the function that called us.
@@ -95,6 +90,8 @@ MORESTACK:
9590
// Switch back to the rust stack
9691
movl %ebp, %esp
9792

93+
subl $8, %esp // Alignment
94+
9895
#ifdef __APPLE__
9996
call 1f
10097
1: popl %ebx
@@ -107,17 +104,17 @@ MORESTACK:
107104
pushl $0
108105
call UPCALL_CALL_C
109106

110-
addl $8,%esp
107+
addl $16,%esp
111108
popl %ebp
112109
retl $8
113110

114111
.L$bail:
115-
movl 24(%esp),%edx
116-
addl $RETURN_OFFSET,%edx
112+
movl 32(%esp),%edx
113+
inc %edx
117114

118-
addl $20, %esp
115+
addl $28, %esp
119116
popl %ebp
120-
addl $4+8+ALIGNMENT,%esp
117+
addl $4+8,%esp
121118

122119
jmpl *%edx
123120

trunk/src/rt/rust_task.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,17 @@ rust_task::del_stack() {
598598

599599
void
600600
rust_task::record_stack_limit() {
601-
// FIXME: Future LLVM patches expect us to add an additional 256 bytes
602-
// here so that, if the frame size is < 256 it can generate the
603-
// comparison against esp directly, instead of some offset from esp
604-
record_sp(stk->data + RED_ZONE_SIZE);
601+
// The function prolog compares the amount of stack needed to the end of
602+
// the stack. As an optimization, when the frame size is less than 256
603+
// bytes, it will simply compare %esp to to the stack limit instead of
604+
// subtracting the frame size. As a result we need our stack limit to
605+
// account for those 256 bytes.
606+
const unsigned LIMIT_OFFSET = 256;
607+
A(sched,
608+
(uintptr_t)stk->limit - RED_ZONE_SIZE
609+
- (uintptr_t)stk->data >= LIMIT_OFFSET,
610+
"Stack size must be greater than LIMIT_OFFSET");
611+
record_sp(stk->data + LIMIT_OFFSET + RED_ZONE_SIZE);
605612
}
606613
//
607614
// Local Variables:

0 commit comments

Comments
 (0)