rt: Remove the stack pointer field of stk_seg
This commit is contained in:
parent
408d4ec0ef
commit
e6ef4d929c
@ -8,14 +8,12 @@
|
||||
#if defined(__APPLE__) || defined(_WIN32)
|
||||
#define RUST_NEW_STACK2 _rust_new_stack2
|
||||
#define RUST_DEL_STACK _rust_del_stack
|
||||
#define RUST_GET_PREV_STACK _rust_get_prev_stack
|
||||
#define RUST_GET_TASK _rust_get_task
|
||||
#define UPCALL_CALL_C _upcall_call_shim_on_c_stack
|
||||
#define MORESTACK ___morestack
|
||||
#else
|
||||
#define RUST_NEW_STACK2 rust_new_stack2
|
||||
#define RUST_DEL_STACK rust_del_stack
|
||||
#define RUST_GET_PREV_STACK rust_get_prev_stack
|
||||
#define RUST_GET_TASK rust_get_task
|
||||
#define UPCALL_CALL_C upcall_call_shim_on_c_stack
|
||||
#define MORESTACK __morestack
|
||||
@ -59,7 +57,6 @@ MORESTACK:
|
||||
jz .L$bail
|
||||
|
||||
// The arguments to rust_new_stack2
|
||||
movl %esp, 20(%esp) // Save the stack pointer
|
||||
movl 36(%esp),%eax // Size of stack arguments
|
||||
movl %eax,16(%esp)
|
||||
leal 44+ALIGNMENT(%esp),%eax // Address of stack arguments
|
||||
@ -81,21 +78,14 @@ MORESTACK:
|
||||
// Now the function that called us has returned, so we need to delete the
|
||||
// old stack space.
|
||||
|
||||
// NB: This is assuming we already have at least 2 words
|
||||
// pushed onto the C stack. This is always true because
|
||||
// Rust functions have implicit arguments.
|
||||
movl $RUST_GET_PREV_STACK,4(%esp)
|
||||
movl $0, (%esp)
|
||||
call UPCALL_CALL_C
|
||||
|
||||
// Switch back to the rust stack
|
||||
movl %eax, %esp
|
||||
movl %ebp, %esp
|
||||
|
||||
movl $RUST_DEL_STACK,4(%esp)
|
||||
movl $0, (%esp)
|
||||
pushl $RUST_DEL_STACK
|
||||
pushl $0
|
||||
call UPCALL_CALL_C
|
||||
|
||||
addl $24,%esp
|
||||
addl $8,%esp
|
||||
popl %ebp
|
||||
retl $8
|
||||
|
||||
|
@ -9,14 +9,12 @@
|
||||
#define RUST_NEW_STACK2 _rust_new_stack2
|
||||
#define RUST_DEL_STACK _rust_del_stack
|
||||
#define RUST_DEL_STACK _rust_del_stack
|
||||
#define RUST_GET_PREV_STACK _rust_get_prev_stack
|
||||
#define UPCALL_CALL_C _upcall_call_shim_on_c_stack
|
||||
#define MORESTACK ___morestack
|
||||
#else
|
||||
#define RUST_NEW_STACK2 rust_new_stack2
|
||||
#define RUST_DEL_STACK rust_del_stack
|
||||
#define RUST_DEL_STACK rust_del_stack
|
||||
#define RUST_GET_PREV_STACK rust_get_prev_stack
|
||||
#define UPCALL_CALL_C upcall_call_shim_on_c_stack
|
||||
#define MORESTACK __morestack
|
||||
#endif
|
||||
@ -63,9 +61,6 @@ MORESTACK:
|
||||
movq %rsp, %rbp
|
||||
.cfi_def_cfa_register %rbp
|
||||
|
||||
// Alignment
|
||||
pushq $0
|
||||
|
||||
// FIXME: libgcc also saves rax. not sure if we need to
|
||||
|
||||
// Save argument registers
|
||||
@ -82,7 +77,6 @@ MORESTACK:
|
||||
movq %rbp, %rcx
|
||||
addq $24, %rcx // Base pointer, return address x2
|
||||
|
||||
pushq %rbp // Save the Rust stack pointer
|
||||
pushq %r11 // Size of stack arguments
|
||||
pushq %rcx // Address of stack arguments
|
||||
pushq %r10 // The amount of stack needed
|
||||
@ -92,7 +86,7 @@ MORESTACK:
|
||||
call UPCALL_CALL_C@PLT
|
||||
|
||||
// Pop the new_stack_args struct
|
||||
addq $32, %rsp
|
||||
addq $24, %rsp
|
||||
|
||||
// Pop the saved arguments
|
||||
popq %r9
|
||||
@ -108,13 +102,8 @@ MORESTACK:
|
||||
|
||||
call *%r10 // Reenter the caller function
|
||||
|
||||
leaq RUST_GET_PREV_STACK@PLT(%rip), %rsi
|
||||
movq $0, %rdi
|
||||
call UPCALL_CALL_C@PLT
|
||||
|
||||
// Switch back to the rust stack, positioned
|
||||
// where we pushed %ebp
|
||||
movq %rax, %rsp
|
||||
// Switch back to the rust stack
|
||||
movq %rbp, %rsp
|
||||
|
||||
// Align the stack again
|
||||
pushq $0
|
||||
|
@ -67,14 +67,11 @@ record_sp(void *limit);
|
||||
|
||||
// Entry points for `__morestack` (see arch/*/morestack.S).
|
||||
extern "C" void *
|
||||
rust_new_stack(size_t stk_sz, void *args_addr, size_t args_sz,
|
||||
uintptr_t current_sp) {
|
||||
rust_new_stack(size_t stk_sz, void *args_addr, size_t args_sz) {
|
||||
rust_task *task = rust_scheduler::get_task();
|
||||
|
||||
stk_seg *stk_seg = new_stk(task->sched, task, stk_sz + args_sz);
|
||||
|
||||
// Save the previous stack pointer so it can be restored later
|
||||
stk_seg->return_sp = current_sp;
|
||||
uint8_t *new_sp = (uint8_t*)stk_seg->limit;
|
||||
size_t sizeof_retaddr = sizeof(void*);
|
||||
// Make enough room on the new stack to hold the old stack pointer
|
||||
@ -90,7 +87,6 @@ struct rust_new_stack2_args {
|
||||
size_t stk_sz;
|
||||
void *args_addr;
|
||||
size_t args_sz;
|
||||
uintptr_t current_sp;
|
||||
};
|
||||
|
||||
// A new stack function suitable for calling through
|
||||
@ -98,7 +94,7 @@ struct rust_new_stack2_args {
|
||||
extern "C" void *
|
||||
rust_new_stack2(struct rust_new_stack2_args *args) {
|
||||
return rust_new_stack(args->stk_sz, args->args_addr,
|
||||
args->args_sz, args->current_sp);
|
||||
args->args_sz);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
@ -108,12 +104,6 @@ rust_del_stack() {
|
||||
record_sp(task->stk->data + RED_ZONE_SIZE);
|
||||
}
|
||||
|
||||
extern "C" uintptr_t
|
||||
rust_get_prev_stack() {
|
||||
rust_task *task = rust_scheduler::get_task();
|
||||
return task->stk->return_sp;
|
||||
}
|
||||
|
||||
extern "C" rust_task *
|
||||
rust_get_task() {
|
||||
return rust_scheduler::get_task();
|
||||
|
@ -26,7 +26,6 @@ struct rust_box;
|
||||
struct stk_seg {
|
||||
stk_seg *next;
|
||||
uintptr_t limit;
|
||||
uintptr_t return_sp;
|
||||
unsigned int valgrind_id;
|
||||
#ifndef _LP64
|
||||
uint32_t pad;
|
||||
|
@ -30,7 +30,6 @@ refcount
|
||||
rust_del_stack
|
||||
rust_file_is_dir
|
||||
rust_getcwd
|
||||
rust_get_prev_stack
|
||||
rust_get_stdin
|
||||
rust_get_stdout
|
||||
rust_get_stderr
|
||||
|
Loading…
Reference in New Issue
Block a user