get pure wrappers approach running
This commit is contained in:
parent
6072ddad33
commit
9fa44a41e6
8 changed files with 111 additions and 106 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue