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