Path: blob/main/crates/fiber/src/stackswitch.rs
1692 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::*;10} else if #[cfg(target_arch = "x86_64")] {11mod x86_64;12pub(crate) use supported::*;13} else if #[cfg(target_arch = "x86")] {14mod x86;15pub(crate) use supported::*;16} else if #[cfg(target_arch = "arm")] {17mod arm;18pub(crate) use supported::*;19} else if #[cfg(target_arch = "s390x")] {20// currently `global_asm!` isn't stable on s390x so this is an external21// assembler file built with the `build.rs`.22pub(crate) use supported::*;23} else if #[cfg(target_arch = "riscv64")] {24mod riscv64;25pub(crate) use supported::*;26} else {27// No support for this platform. Don't fail compilation though and28// instead defer the error to happen at runtime when a fiber is created.29// Should help keep compiles working and narrows the failure to only30// situations that need fibers on unsupported platforms.31pub(crate) use unsupported::*;32}33}3435/// A helper module to get reeported above in each case that we actually have36/// stack-switching routines available in in line asm. The fall-through case37/// though reexports the `unsupported` module instead.38#[allow(39dead_code,40reason = "expected to have dead code in some configurations"41)]42mod supported {43pub const SUPPORTED_ARCH: bool = true;44unsafe extern "C" {45#[wasmtime_versioned_export_macros::versioned_link]46pub(crate) fn wasmtime_fiber_init(47top_of_stack: *mut u8,48entry: extern "C" fn(*mut u8, *mut u8),49entry_arg0: *mut u8,50);51#[wasmtime_versioned_export_macros::versioned_link]52pub(crate) fn wasmtime_fiber_switch(top_of_stack: *mut u8);53#[wasmtime_versioned_export_macros::versioned_link]54pub(crate) fn wasmtime_fiber_start();55}56}5758/// Helper module reexported in the fallback case above when the current host59/// architecture is not supported for stack switching. The `SUPPORTED_ARCH`60/// boolean here is set to `false` which causes `Fiber::new` to return `false`.61#[allow(62dead_code,63reason = "expected to have dead code in some configurations"64)]65mod unsupported {66pub const SUPPORTED_ARCH: bool = false;6768pub(crate) unsafe fn wasmtime_fiber_init(69_top_of_stack: *mut u8,70_entry: extern "C" fn(*mut u8, *mut u8),71_entry_arg0: *mut u8,72) {73unreachable!();74}7576pub(crate) unsafe fn wasmtime_fiber_switch(_top_of_stack: *mut u8) {77unreachable!();78}79}808182