wasmtime/runtime/vm/
unwind.rs1#[cfg(has_host_compiler_backend)]
4use crate::runtime::vm::arch;
5
6pub unsafe trait Unwind {
8 fn next_older_fp_from_fp_offset(&self) -> usize;
11
12 unsafe fn get_next_older_pc_from_fp(&self, fp: usize) -> usize;
15
16 fn assert_fp_is_aligned(&self, fp: usize);
18}
19
20#[cfg(has_host_compiler_backend)]
23pub struct UnwindHost;
24
25#[cfg(has_host_compiler_backend)]
26unsafe impl Unwind for UnwindHost {
27 fn next_older_fp_from_fp_offset(&self) -> usize {
28 arch::NEXT_OLDER_FP_FROM_FP_OFFSET
29 }
30 unsafe fn get_next_older_pc_from_fp(&self, fp: usize) -> usize {
31 arch::get_next_older_pc_from_fp(fp)
32 }
33 fn assert_fp_is_aligned(&self, fp: usize) {
34 arch::assert_fp_is_aligned(fp)
35 }
36}
37
38pub struct UnwindPulley;
41
42unsafe impl Unwind for UnwindPulley {
43 fn next_older_fp_from_fp_offset(&self) -> usize {
44 0
45 }
46 unsafe fn get_next_older_pc_from_fp(&self, fp: usize) -> usize {
47 *(fp as *mut usize).offset(1)
50 }
51 fn assert_fp_is_aligned(&self, fp: usize) {
52 let expected = if cfg!(target_pointer_width = "32") {
53 8
54 } else {
55 16
56 };
57 assert_eq!(fp % expected, 0, "stack should always be aligned");
58 }
59}