Path: blob/main/crates/unwinder/src/arch/x86.rs
1693 views
//! x86-specific (also x86-64) definitions of architecture-specific functions in1//! Wasmtime.23#[inline]4pub fn get_stack_pointer() -> usize {5let stack_pointer: usize;6unsafe {7core::arch::asm!(8"mov {}, rsp",9out(reg) stack_pointer,10options(nostack,nomem),11);12}13stack_pointer14}1516pub unsafe fn get_next_older_pc_from_fp(fp: usize) -> usize {17// The calling convention always pushes the return pointer (aka the PC of18// the next older frame) just before this frame.19unsafe { *(fp as *mut usize).offset(1) }20}2122pub unsafe fn resume_to_exception_handler(23pc: usize,24sp: usize,25fp: usize,26payload1: usize,27payload2: usize,28) -> ! {29unsafe {30core::arch::asm!(31"mov rsp, rcx",32"mov rbp, rsi",33"jmp rdi",34in("rax") payload1,35in("rdx") payload2,36in("rcx") sp,37in("rsi") fp,38in("rdi") pc,39options(nostack, nomem, noreturn),40);41}42}4344// And the current frame pointer points to the next older frame pointer.45pub const NEXT_OLDER_FP_FROM_FP_OFFSET: usize = 0;4647// SP of caller is FP in callee plus size of FP/return address pair.48pub const NEXT_OLDER_SP_FROM_FP_OFFSET: usize = 16;4950/// Frame pointers are aligned if they're aligned to twice the size of a51/// pointer.52pub fn assert_fp_is_aligned(fp: usize) {53let align = 2 * size_of::<usize>();54assert_eq!(fp % align, 0, "stack should always be aligned to {align}");55}565758