Skip to content

Commit dd798fc

Browse files
committed
---
yaml --- r: 6486 b: refs/heads/master c: a996742 h: refs/heads/master v: v3
1 parent cf2c3b4 commit dd798fc

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
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: 5461c61af241e75892eb5c78f2f1c2c584013b10
2+
refs/heads/master: a9967423f80dfb48001fe28b7c2e3ac7e0566f72

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

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
#if defined(__APPLE__) || defined(_WIN32)
99
#define RUST_NEW_STACK2 _rust_new_stack2
1010
#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
1113
#define UPCALL_CALL_C _upcall_call_shim_on_c_stack
1214
#define MORESTACK ___morestack
1315
#else
1416
#define RUST_NEW_STACK2 rust_new_stack2
1517
#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
1620
#define UPCALL_CALL_C upcall_call_shim_on_c_stack
1721
#define MORESTACK __morestack
1822
#endif
@@ -59,6 +63,11 @@ MORESTACK:
5963
movq %rsp, %rbp
6064
.cfi_def_cfa_register %rbp
6165

66+
// Alignment
67+
pushq $0
68+
69+
// FIXME: libgcc also saves rax. not sure if we need to
70+
6271
// Save argument registers
6372
pushq %rdi
6473
pushq %rsi
@@ -77,15 +86,46 @@ MORESTACK:
7786
pushq %rcx // Address of stack arguments
7887
pushq %r10 // The amount of stack needed
7988

80-
lea RUST_NEW_STACK2@PLT(%rip), %rsi
81-
mov %rsp, %rdi
89+
leaq RUST_NEW_STACK2@PLT(%rip), %rsi
90+
movq %rsp, %rdi
8291
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
83103

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.
88107

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+
89129
.cfi_endproc
90130
#else
91131
MORESTACK:

trunk/src/rt/arch/x86_64/record_sp.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#if defined(__linux__)
1212
RECORD_SP:
1313
movq %rdi, %fs:112
14+
ret
1415
#else
1516
RECORD_SP:
1617
ret

trunk/src/rt/rust_internal.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ static size_t const BUF_BYTES = 2048;
9595
#define PROC_FAIL_CODE 101;
9696

9797
// FIXME: We want this to be 128 but need to slim the red zone calls down
98-
#define RED_ZONE_SIZE 256
98+
#ifdef __i386__
99+
#define RED_ZONE_SIZE 256
100+
#endif
101+
102+
#ifdef __x86_64__
103+
#define RED_ZONE_SIZE 2048
104+
#endif
99105

100106
// Every reference counted object should use this macro and initialize
101107
// ref_count.

0 commit comments

Comments
 (0)