Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/fiber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ backtrace = "0.3.68"
# Assume presence of the standard library. Allows propagating
# panic-unwinds across fiber invocations.
std = []

# Use embedder-provided stack-switching routines on unsupported architectures.
# See `src/stackswitch/custom.rs` for the C ABI the embedder must implement.
custom = []
4 changes: 3 additions & 1 deletion crates/fiber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ cfg_if::cfg_if! {
use unix as imp;
mod stackswitch;
} else {
compile_error!("fibers are not supported on this platform");
mod nostd;
use nostd as imp;
mod stackswitch;
Comment on lines +37 to +39

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this should be gated by custom feature, but the comment in stackswitch states:

   // No support for this platform. Don't fail compilation though and
   // instead defer the error to happen at runtime when a fiber is created.
   // Should help keep compiles working and narrows the failure to only
   // situations that need fibers on unsupported platforms.

so this seems consistent

}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/fiber/src/stackswitch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ cfg_if::cfg_if! {
mod riscv32imac;
pub(crate) use supported::*;
pub(crate) use riscv32imac::*;
} else if #[cfg(feature = "custom")] {
mod custom;
pub(crate) use supported::*;
pub(crate) use custom::*;
} else {
// No support for this platform. Don't fail compilation though and
// instead defer the error to happen at runtime when a fiber is created.
Expand Down
18 changes: 18 additions & 0 deletions crates/fiber/src/stackswitch/custom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Embedder-provided stack-switching routines.
//!
//! This module is used when the `custom` feature is enabled and the target
//! architecture has no built-in inline-assembly implementation. It is the
//! stack-switching analogue of Wasmtime's `custom-virtual-memory` feature:
//! rather than relying on inline assembly for a known architecture, the
//! routines below are declared as `extern "C"` imports which the embedder is
//! expected to supply.

unsafe extern "C" {
pub(crate) fn wasmtime_fiber_init(
top_of_stack: *mut u8,
entry: extern "C" fn(*mut u8, *mut u8) -> *mut u8,
entry_arg0: *mut u8,
);

pub(crate) fn wasmtime_fiber_switch(top_of_stack: *mut u8);
}
3 changes: 3 additions & 0 deletions crates/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ custom-native-signals = []
# Same as `custom-virtual-memory` above, but for custom sync primitive APIs.
custom-sync-primitives = []

# Same as `custom-virtual-memory` above, but for custom fiber APIs.
custom-fiber = ["wasmtime-fiber?/custom"]

# Off-by-default support to profile the Pulley interpreter. This has a
# performance hit, even when not profiling, so it's disabled by default at
# compile time.
Expand Down
Loading