get pure wrappers approach running

This commit is contained in:
Niko Matsakis 2011-11-18 15:40:23 -08:00
parent 6072ddad33
commit 9fa44a41e6
8 changed files with 111 additions and 106 deletions

View file

@ -45,3 +45,20 @@ upcall_call_c_stack_shim:
movl %ebp,%esp // would like to use "leave" but it's slower
popl %ebp
ret
#if defined(__APPLE__) || defined(_WIN32)
.globl _asm_call_on_stack
_asm_call_on_stack:
#else
.globl asm_call_on_stack
asm_call_on_stack:
#endif
pushl %ebp
movl %esp,%ebp // save esp
movl 16(%ebp),%esp // load new esp
subl $12,%esp // maintain 16-byte alignment
pushl 8(%ebp) // push ptr to argument block
calll *12(%ebp)
movl %ebp,%esp // would like to use "leave" but it's slower
popl %ebp
ret

View file

@ -29,6 +29,8 @@ struct registers_t {
uint32_t eip;
};
extern "C" void asm_call_on_stack(void *args, void *fn_ptr, uintptr_t stack_ptr);
class context {
public:
registers_t regs;
@ -55,6 +57,10 @@ public:
return reinterpret_cast<void *>(top);
}
void call_shim_on_c_stack(void *args, void *fn_ptr) {
asm_call_on_stack(args, fn_ptr, regs.esp);
}
};
#endif

View file

@ -2,6 +2,7 @@
#define ARG0 RUSTRT_ARG0_S
#define ARG1 RUSTRT_ARG1_S
#define ARG2 RUSTRT_ARG2_S
.text
@ -72,3 +73,18 @@ upcall_call_c_stack_shim:
mov %rbp,%rsp
pop %rbp
ret
#if defined(__APPLE__) || defined(_WIN32)
.globl _asm_call_on_stack
_asm_call_on_stack:
#else
.globl asm_call_on_stack
asm_call_on_stack:
#endif
push %rbp
mov %rsp,%rbp // save rsp
mov ARG2,%rsp // switch stack
call *ARG1 // invoke target address
mov %rbp,%rsp
pop %rbp
ret

View file

@ -29,6 +29,8 @@ struct registers_t {
uint64_t data[RUSTRT_MAX];
};
extern "C" void asm_call_on_stack(void *args, void *fn_ptr, uintptr_t stack_ptr);
class context {
public:
registers_t regs;
@ -55,6 +57,10 @@ public:
return reinterpret_cast<void *>(top);
}
void call_shim_on_c_stack(void *args, void *fn_ptr) {
asm_call_on_stack(args, fn_ptr, regs.data[RUSTRT_RSP]);
}
};
#endif