Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/fiber/src/stackswitch.rs
3050 views
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 if #[cfg(all(target_arch = "riscv32", not(target_feature = "f"), not(target_feature = "v")))] {
33
mod riscv32imac;
34
pub(crate) use supported::*;
35
pub(crate) use riscv32imac::*;
36
} else {
37
// No support for this platform. Don't fail compilation though and
38
// instead defer the error to happen at runtime when a fiber is created.
39
// Should help keep compiles working and narrows the failure to only
40
// situations that need fibers on unsupported platforms.
41
pub(crate) use unsupported::*;
42
}
43
}
44
45
/// A helper module to get reexported above in each case that we actually have
46
/// stack-switching routines available in inline asm. The fall-through case
47
/// though reexports the `unsupported` module instead.
48
#[allow(
49
dead_code,
50
reason = "expected to have dead code in some configurations"
51
)]
52
mod supported {
53
pub const SUPPORTED_ARCH: bool = true;
54
}
55
56
/// Helper module reexported in the fallback case above when the current host
57
/// architecture is not supported for stack switching. The `SUPPORTED_ARCH`
58
/// boolean here is set to `false` which causes `Fiber::new` to return `false`.
59
#[allow(
60
dead_code,
61
reason = "expected to have dead code in some configurations"
62
)]
63
mod unsupported {
64
pub const SUPPORTED_ARCH: bool = false;
65
66
pub(crate) unsafe fn wasmtime_fiber_init(
67
_top_of_stack: *mut u8,
68
_entry: extern "C" fn(*mut u8, *mut u8),
69
_entry_arg0: *mut u8,
70
) {
71
unreachable!();
72
}
73
74
pub(crate) unsafe fn wasmtime_fiber_switch(_top_of_stack: *mut u8) {
75
unreachable!();
76
}
77
}
78
79