#include struct thread_ctx { uint64_t r15, r14, r13, r12, r11, r10, r9, r8; uint64_t rdi, rsi, rbp, unused_rsp, rbx, rdx, rcx, rax; uint64_t rfl; } __packed; void prepare_stack(uintptr_t ip, uintptr_t *sp) { (*sp) -= sizeof(uintptr_t); uintptr_t *dest_ip = (uintptr_t *)(*sp); *dest_ip = ip; (*sp) -= sizeof(struct thread_ctx); struct thread_ctx *ctx = (struct thread_ctx *)(*sp); memset(ctx, 0x0, sizeof *ctx); ctx->rfl = 0x202; }