dusk_wasmtime_runtime/arch/
x86_64.rs

1//! x86_64-specific definitions of architecture-specific functions in Wasmtime.
2
3/// x86 vectors are represented with XMM registers which are represented
4/// with the `__m128i` type. This type is considered a vector type for
5/// ABI purposes which is implemented by Cranelift.
6pub type V128Abi = std::arch::x86_64::__m128i;
7
8#[inline]
9#[allow(missing_docs)]
10pub fn get_stack_pointer() -> usize {
11    let stack_pointer: usize;
12    unsafe {
13        std::arch::asm!(
14            "mov {}, rsp",
15            out(reg) stack_pointer,
16            options(nostack,nomem),
17        );
18    }
19    stack_pointer
20}
21
22pub unsafe fn get_next_older_pc_from_fp(fp: usize) -> usize {
23    // The calling convention always pushes the return pointer (aka the PC of
24    // the next older frame) just before this frame.
25    *(fp as *mut usize).offset(1)
26}
27
28// And the current frame pointer points to the next older frame pointer.
29pub const NEXT_OLDER_FP_FROM_FP_OFFSET: usize = 0;
30
31pub fn reached_entry_sp(fp: usize, entry_sp: usize) -> bool {
32    fp >= entry_sp
33}
34
35pub fn assert_entry_sp_is_aligned(sp: usize) {
36    assert_eq!(sp % 16, 0, "stack should always be aligned to 16");
37}
38
39pub fn assert_fp_is_aligned(fp: usize) {
40    assert_eq!(fp % 16, 0, "stack should always be aligned to 16");
41}