wasmtime_runtime/traphandlers/backtrace/
x86_64.rs

1pub unsafe fn get_next_older_pc_from_fp(fp: usize) -> usize {
2    // The calling convention always pushes the return pointer (aka the PC of
3    // the next older frame) just before this frame.
4    *(fp as *mut usize).offset(1)
5}
6
7// And the current frame pointer points to the next older frame pointer.
8pub const NEXT_OLDER_FP_FROM_FP_OFFSET: usize = 0;
9
10pub fn reached_entry_sp(fp: usize, first_wasm_sp: usize) -> bool {
11    // When the FP is just below the SP (because we are in a function prologue
12    // where the `call` pushed the return pointer, but the callee hasn't pushed
13    // the frame pointer yet) we are done.
14    fp == first_wasm_sp - 8
15}
16
17pub fn assert_entry_sp_is_aligned(sp: usize) {
18    // The stack pointer should always be aligned to 16 bytes *except* inside
19    // function prologues where the return PC is pushed to the stack but before
20    // the old frame pointer has been saved to the stack via `push rbp`. And
21    // this happens to be exactly where we are inside of our host-to-Wasm
22    // trampoline that records the value of SP when we first enter
23    // Wasm. Therefore, the SP should *always* be 8-byte aligned but *never*
24    // 16-byte aligned.
25    assert_eq!(sp % 8, 0);
26    assert_eq!(sp % 16, 8);
27}
28
29pub fn assert_fp_is_aligned(fp: usize) {
30    assert_eq!(fp % 16, 0, "stack should always be aligned to 16");
31}