wasmtime/runtime/vm/arch/
x86.rs

1//! x86-specific (also x86-64) definitions of architecture-specific functions in
2//! Wasmtime.
3
4#[inline]
5#[allow(missing_docs)]
6pub fn get_stack_pointer() -> usize {
7    let stack_pointer: usize;
8    unsafe {
9        core::arch::asm!(
10            "mov {}, rsp",
11            out(reg) stack_pointer,
12            options(nostack,nomem),
13        );
14    }
15    stack_pointer
16}
17
18pub unsafe fn get_next_older_pc_from_fp(fp: usize) -> usize {
19    // The calling convention always pushes the return pointer (aka the PC of
20    // the next older frame) just before this frame.
21    *(fp as *mut usize).offset(1)
22}
23
24// And the current frame pointer points to the next older frame pointer.
25pub const NEXT_OLDER_FP_FROM_FP_OFFSET: usize = 0;
26
27/// Frame pointers are aligned if they're aligned to twice the size of a
28/// pointer.
29pub fn assert_fp_is_aligned(fp: usize) {
30    let align = 2 * size_of::<usize>();
31    assert_eq!(fp % align, 0, "stack should always be aligned to {align}");
32}