#include "context.h" #include "../../rust.h" #include #include #include extern "C" void CDECL swap_registers(registers_t *oregs, registers_t *regs) asm ("swap_registers"); context::context() { assert((void*)®s == (void*)this); } void context::swap(context &out) { swap_registers(&out.regs, ®s); } void context::call(void *f, void *arg, void *stack) { // Get the current context, which we will then modify to call the // given function. swap(*this); // set up the stack uint64_t *sp = (uint64_t *)stack; sp = align_down(sp); *--sp = 0xdeadbeef; // takes place of ret. addr. regs.data[RUSTRT_ARG0] = (uint64_t)arg; regs.data[RUSTRT_RSP] = (uint64_t)sp; regs.data[RUSTRT_IP] = (uint64_t)f; }