1abcd6accSChris Fallin //! ISA-specific stack-switching routines. 2abcd6accSChris Fallin 3abcd6accSChris Fallin // The bodies are defined in inline assembly in the conditionally 4abcd6accSChris Fallin // included modules below; their symbols are visible in the binary and 5abcd6accSChris Fallin // accessed via the `extern "C"` declarations below that. 6abcd6accSChris Fallin 7abcd6accSChris Fallin cfg_if::cfg_if! { 8abcd6accSChris Fallin if #[cfg(target_arch = "aarch64")] { 9abcd6accSChris Fallin mod aarch64; 104afa86b8SAlex Crichton pub(crate) use supported::*; 113e9eca8bSAlex Crichton pub(crate) use aarch64::*; 12abcd6accSChris Fallin } else if #[cfg(target_arch = "x86_64")] { 13abcd6accSChris Fallin mod x86_64; 144afa86b8SAlex Crichton pub(crate) use supported::*; 153e9eca8bSAlex Crichton pub(crate) use x86_64::*; 16abcd6accSChris Fallin } else if #[cfg(target_arch = "x86")] { 17abcd6accSChris Fallin mod x86; 184afa86b8SAlex Crichton pub(crate) use supported::*; 193e9eca8bSAlex Crichton pub(crate) use x86::*; 20abcd6accSChris Fallin } else if #[cfg(target_arch = "arm")] { 21abcd6accSChris Fallin mod arm; 224afa86b8SAlex Crichton pub(crate) use supported::*; 233e9eca8bSAlex Crichton pub(crate) use arm::*; 24abcd6accSChris Fallin } else if #[cfg(target_arch = "s390x")] { 253e9eca8bSAlex Crichton mod s390x; 264afa86b8SAlex Crichton pub(crate) use supported::*; 273e9eca8bSAlex Crichton pub(crate) use s390x::*; 28abcd6accSChris Fallin } else if #[cfg(target_arch = "riscv64")] { 29abcd6accSChris Fallin mod riscv64; 304afa86b8SAlex Crichton pub(crate) use supported::*; 313e9eca8bSAlex Crichton pub(crate) use riscv64::*; 323dc6b5ecSmax-dau } else if #[cfg(all(target_arch = "riscv32", not(target_feature = "f"), not(target_feature = "v")))] { 333dc6b5ecSmax-dau mod riscv32imac; 343dc6b5ecSmax-dau pub(crate) use supported::*; 353dc6b5ecSmax-dau pub(crate) use riscv32imac::*; 36abcd6accSChris Fallin } else { 374afa86b8SAlex Crichton // No support for this platform. Don't fail compilation though and 384afa86b8SAlex Crichton // instead defer the error to happen at runtime when a fiber is created. 394afa86b8SAlex Crichton // Should help keep compiles working and narrows the failure to only 404afa86b8SAlex Crichton // situations that need fibers on unsupported platforms. 414afa86b8SAlex Crichton pub(crate) use unsupported::*; 42abcd6accSChris Fallin } 43abcd6accSChris Fallin } 44abcd6accSChris Fallin 453dc6b5ecSmax-dau /// A helper module to get reexported above in each case that we actually have 464afa86b8SAlex Crichton /// stack-switching routines available in inline asm. The fall-through case 474afa86b8SAlex Crichton /// though reexports the `unsupported` module instead. 484afa86b8SAlex Crichton #[allow( 494afa86b8SAlex Crichton dead_code, 504afa86b8SAlex Crichton reason = "expected to have dead code in some configurations" 514afa86b8SAlex Crichton )] 524afa86b8SAlex Crichton mod supported { 534afa86b8SAlex Crichton pub const SUPPORTED_ARCH: bool = true; 544afa86b8SAlex Crichton } 554afa86b8SAlex Crichton 564afa86b8SAlex Crichton /// Helper module reexported in the fallback case above when the current host 574afa86b8SAlex Crichton /// architecture is not supported for stack switching. The `SUPPORTED_ARCH` 584afa86b8SAlex Crichton /// boolean here is set to `false` which causes `Fiber::new` to return `false`. 594afa86b8SAlex Crichton #[allow( 604afa86b8SAlex Crichton dead_code, 614afa86b8SAlex Crichton reason = "expected to have dead code in some configurations" 624afa86b8SAlex Crichton )] 634afa86b8SAlex Crichton mod unsupported { 644afa86b8SAlex Crichton pub const SUPPORTED_ARCH: bool = false; 654afa86b8SAlex Crichton wasmtime_fiber_init( _top_of_stack: *mut u8, _entry: extern "C" fn(*mut u8, *mut u8) -> *mut u8, _entry_arg0: *mut u8, )664afa86b8SAlex Crichton pub(crate) unsafe fn wasmtime_fiber_init( 674afa86b8SAlex Crichton _top_of_stack: *mut u8, 68*f3156fe0SAlex Crichton _entry: extern "C" fn(*mut u8, *mut u8) -> *mut u8, 694afa86b8SAlex Crichton _entry_arg0: *mut u8, 704afa86b8SAlex Crichton ) { 714afa86b8SAlex Crichton unreachable!(); 724afa86b8SAlex Crichton } 734afa86b8SAlex Crichton wasmtime_fiber_switch(_top_of_stack: *mut u8)744afa86b8SAlex Crichton pub(crate) unsafe fn wasmtime_fiber_switch(_top_of_stack: *mut u8) { 754afa86b8SAlex Crichton unreachable!(); 764afa86b8SAlex Crichton } 774afa86b8SAlex Crichton } 78