Path: blob/main/crates/unwinder/src/arch/riscv64.rs
1693 views
//! Riscv64-specific definitions of architecture-specific functions in Wasmtime.12#[inline]3pub fn get_stack_pointer() -> usize {4let stack_pointer: usize;5unsafe {6core::arch::asm!(7"mv {}, sp",8out(reg) stack_pointer,9options(nostack,nomem),10);11}12stack_pointer13}1415pub unsafe fn get_next_older_pc_from_fp(fp: usize) -> usize {16unsafe { *(fp as *mut usize).offset(1) }17}1819pub unsafe fn resume_to_exception_handler(20pc: usize,21sp: usize,22fp: usize,23payload1: usize,24payload2: usize,25) -> ! {26unsafe {27core::arch::asm!(28"mv sp, a2",29"mv fp, a3",30"jr a4",31in("a0") payload1,32in("a1") payload2,33in("a2") sp,34in("a3") fp,35in("a4") pc,36options(nostack, nomem, noreturn),37);38}39}4041// And the current frame pointer points to the next older frame pointer.42pub const NEXT_OLDER_FP_FROM_FP_OFFSET: usize = 0;4344// SP of caller is FP in callee plus size of FP/return address pair.45pub const NEXT_OLDER_SP_FROM_FP_OFFSET: usize = 16;4647pub fn assert_fp_is_aligned(fp: usize) {48assert_eq!(fp % 16, 0, "stack should always be aligned to 16");49}505152