1 //! ISA-specific stack-switching routines. 2 3 // The bodies are defined in inline assembly in the conditionally 4 // included modules below; their symbols are visible in the binary and 5 // accessed via the `extern "C"` declarations below that. 6 7 cfg_if::cfg_if! { 8 if #[cfg(target_arch = "aarch64")] { 9 mod aarch64; 10 pub(crate) use supported::*; 11 pub(crate) use aarch64::*; 12 } else if #[cfg(target_arch = "x86_64")] { 13 mod x86_64; 14 pub(crate) use supported::*; 15 pub(crate) use x86_64::*; 16 } else if #[cfg(target_arch = "x86")] { 17 mod x86; 18 pub(crate) use supported::*; 19 pub(crate) use x86::*; 20 } else if #[cfg(target_arch = "arm")] { 21 mod arm; 22 pub(crate) use supported::*; 23 pub(crate) use arm::*; 24 } else if #[cfg(target_arch = "s390x")] { 25 mod s390x; 26 pub(crate) use supported::*; 27 pub(crate) use s390x::*; 28 } else if #[cfg(target_arch = "riscv64")] { 29 mod riscv64; 30 pub(crate) use supported::*; 31 pub(crate) use riscv64::*; 32 } else { 33 // No support for this platform. Don't fail compilation though and 34 // instead defer the error to happen at runtime when a fiber is created. 35 // Should help keep compiles working and narrows the failure to only 36 // situations that need fibers on unsupported platforms. 37 pub(crate) use unsupported::*; 38 } 39 } 40 41 /// A helper module to get reeported above in each case that we actually have 42 /// stack-switching routines available in inline asm. The fall-through case 43 /// though reexports the `unsupported` module instead. 44 #[allow( 45 dead_code, 46 reason = "expected to have dead code in some configurations" 47 )] 48 mod supported { 49 pub const SUPPORTED_ARCH: bool = true; 50 } 51 52 /// Helper module reexported in the fallback case above when the current host 53 /// architecture is not supported for stack switching. The `SUPPORTED_ARCH` 54 /// boolean here is set to `false` which causes `Fiber::new` to return `false`. 55 #[allow( 56 dead_code, 57 reason = "expected to have dead code in some configurations" 58 )] 59 mod unsupported { 60 pub const SUPPORTED_ARCH: bool = false; 61 62 pub(crate) unsafe fn wasmtime_fiber_init( 63 _top_of_stack: *mut u8, 64 _entry: extern "C" fn(*mut u8, *mut u8), 65 _entry_arg0: *mut u8, 66 ) { 67 unreachable!(); 68 } 69 70 pub(crate) unsafe fn wasmtime_fiber_switch(_top_of_stack: *mut u8) { 71 unreachable!(); 72 } 73 } 74