6
6
// prolog when we run out.
7
7
8
8
#if defined(__APPLE__) || defined(_WIN32)
9
- #define RUST_NEW_STACK _rust_new_stack
9
+ #define RUST_NEW_STACK2 _rust_new_stack2
10
10
#define RUST_DEL_STACK _rust_del_stack
11
+ #define UPCALL_CALL_C _upcall_call_shim_on_c_stack
11
12
#define MORESTACK ___morestack
12
13
#else
13
- #define RUST_NEW_STACK rust_new_stack
14
+ #define RUST_NEW_STACK2 rust_new_stack2
14
15
#define RUST_DEL_STACK rust_del_stack
16
+ #define UPCALL_CALL_C upcall_call_shim_on_c_stack
15
17
#define MORESTACK __morestack
16
18
#endif
17
19
28
30
# define ARG2 %rdx
29
31
#endif
30
32
31
- .globl RUST_NEW_STACK
33
+ .globl RUST_NEW_STACK2
32
34
.globl RUST_DEL_STACK
33
-
35
+ .globl UPCALL_CALL_C
34
36
.globl MORESTACK
35
37
38
+ #ifdef __ELF__
39
+ .type MORESTACK,@function
40
+ #endif
41
+
36
42
MORESTACK:
37
- // Hastily and probably incorrectly ported from i386 version.
38
- // Actually this calling convention doens't make so much sense
39
- // for x86_64...
40
- mov %rcx , ARG0 // param 0: amount of space needed
41
- mov %rdx , ARG2 // param 2: size of arguments
42
- lea 8 (%rsp ),ARG1
43
- call rust_new_stack_sym
43
+ .cfi_startproc
44
+
45
+ # Set up a normal backtrace
46
+ pushq %rbp
47
+ .cfi_def_cfa_offset 16
48
+ .cfi_offset %rbp , -16
49
+ movq %rsp , %rbp
50
+ .cfi_def_cfa_register %rbp
44
51
52
+ // Save argument registers
53
+ pushq %rdi
54
+ pushq %rsi
55
+ pushq %rdx
56
+ pushq %rcx
57
+ pushq %r8
58
+ pushq %r9
59
+
60
+ // Calculate the address of the stack arguments
61
+ movq %rbp , %rcx
62
+ addq $16 , %rcx // Add the saved %rbp, and return address
63
+ addq %r11 , %rcx // Add the size of stack arguments
64
+
65
+ pushq %r10 // The amount of stack needed
66
+ pushq %rcx // Address of stack arguments
67
+ pushq %r11 // Size of stack arguments
68
+ pushq %rbp // Save the Rust stack pointer
69
+
70
+ // FIXME: Don't understand why I have to use the PLT here
71
+ lea RUST_NEW_STACK2@PLT(%rip ), %rsi
72
+ lea 24 (%rsp ), %rdi
73
+ call UPCALL_CALL_C@PLT
74
+
45
75
mov (%rsp ),%rdx // Grab the return pointer.
46
76
inc %rdx // Skip past the `ret`.
47
77
mov %rax ,%rsp // Switch to the new stack.
48
78
call *%rdx // Enter the new function.
49
79
50
- // Now the function that called us has returned, so we need to delete the
51
- // old stack space.
52
- call rust_new_stack_sym
53
- mov %rax ,%rsp // Switch back to the old stack.
54
- ret
55
-
56
- // This is totally broken
57
- rust_new_stack_sym:
58
- rust_del_stack_sym:
80
+ .cfi_endproc
0 commit comments