Skip to content
Merged
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
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ wasmtime-fiber = { path = "crates/fiber", version = "=38.0.0", package = 'wasmti
wasmtime-jit-debug = { path = "crates/jit-debug", version = "=38.0.0", package = 'wasmtime-internal-jit-debug' }
wasmtime-component-util = { path = "crates/component-util", version = "=38.0.0", package = 'wasmtime-internal-component-util' }
wasmtime-component-macro = { path = "crates/component-macro", version = "=38.0.0", package = 'wasmtime-internal-component-macro' }
wasmtime-asm-macros = { path = "crates/asm-macros", version = "=38.0.0", package = 'wasmtime-internal-asm-macros' }
wasmtime-versioned-export-macros = { path = "crates/versioned-export-macros", version = "=38.0.0", package = 'wasmtime-internal-versioned-export-macros' }
wasmtime-slab = { path = "crates/slab", version = "=38.0.0", package = 'wasmtime-internal-slab' }
wasmtime-jit-icache-coherence = { path = "crates/jit-icache-coherence", version = "=38.0.0", package = 'wasmtime-internal-jit-icache-coherence' }
Expand Down
14 changes: 0 additions & 14 deletions crates/asm-macros/Cargo.toml

This file was deleted.

90 changes: 0 additions & 90 deletions crates/asm-macros/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/fiber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ workspace = true
anyhow = { workspace = true }
cfg-if = { workspace = true }
wasmtime-versioned-export-macros = { workspace = true }
wasmtime-asm-macros = { workspace = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true, features = ["mm"] }
Expand Down
4 changes: 0 additions & 4 deletions crates/fiber/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ fn main() {
println!("cargo:rerun-if-changed=src/windows.c");
build.file("src/windows.c");
build.define("VERSIONED_SUFFIX", Some(versioned_suffix!()));
} else if arch == "s390x" {
println!("cargo:rerun-if-changed=src/stackswitch/s390x.S");
build.file("src/stackswitch/s390x.S");
build.define("VERSIONED_SUFFIX", Some(versioned_suffix!()));
} else {
// assume that this is included via inline assembly in the crate itself,
// and the crate will otherwise have a `compile_error!` for unsupported
Expand Down
7 changes: 2 additions & 5 deletions crates/fiber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cfg_if::cfg_if! {
if #[cfg(not(feature = "std"))] {
mod nostd;
use nostd as imp;
mod stackswitch;
} else if #[cfg(miri)] {
mod miri;
use miri as imp;
Expand All @@ -31,16 +32,12 @@ cfg_if::cfg_if! {
} else if #[cfg(unix)] {
mod unix;
use unix as imp;
mod stackswitch;
} else {
compile_error!("fibers are not supported on this platform");
}
}

// Our own stack switcher routines are used on Unix and no_std
// platforms, but not on Windows (it has its own fiber API).
#[cfg(any(unix, not(feature = "std")))]
pub(crate) mod stackswitch;

/// Represents an execution stack to use for a fiber.
pub struct FiberStack(imp::FiberStack);

Expand Down
21 changes: 7 additions & 14 deletions crates/fiber/src/stackswitch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@ cfg_if::cfg_if! {
if #[cfg(target_arch = "aarch64")] {
mod aarch64;
pub(crate) use supported::*;
pub(crate) use aarch64::*;
} else if #[cfg(target_arch = "x86_64")] {
mod x86_64;
pub(crate) use supported::*;
pub(crate) use x86_64::*;
} else if #[cfg(target_arch = "x86")] {
mod x86;
pub(crate) use supported::*;
pub(crate) use x86::*;
} else if #[cfg(target_arch = "arm")] {
mod arm;
pub(crate) use supported::*;
pub(crate) use arm::*;
} else if #[cfg(target_arch = "s390x")] {
// currently `global_asm!` isn't stable on s390x so this is an external
// assembler file built with the `build.rs`.
mod s390x;
pub(crate) use supported::*;
pub(crate) use s390x::*;
} else if #[cfg(target_arch = "riscv64")] {
mod riscv64;
pub(crate) use supported::*;
pub(crate) use riscv64::*;
} 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 All @@ -42,18 +47,6 @@ cfg_if::cfg_if! {
)]
mod supported {
pub const SUPPORTED_ARCH: bool = true;
unsafe extern "C" {
#[wasmtime_versioned_export_macros::versioned_link]
pub(crate) fn wasmtime_fiber_init(
top_of_stack: *mut u8,
entry: extern "C" fn(*mut u8, *mut u8),
entry_arg0: *mut u8,
);
#[wasmtime_versioned_export_macros::versioned_link]
pub(crate) fn wasmtime_fiber_switch(top_of_stack: *mut u8);
#[wasmtime_versioned_export_macros::versioned_link]
pub(crate) fn wasmtime_fiber_start();
}
}

/// Helper module reexported in the fallback case above when the current host
Expand Down
50 changes: 25 additions & 25 deletions crates/fiber/src/stackswitch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
// `DW_CFA_AARCH64_negate_ra_state` DWARF operation (aliased with the
// `.cfi_window_save` assembler directive) informs an unwinder about this

use super::wasmtime_fiber_start;
use wasmtime_asm_macros::asm_func;
use core::arch::naked_asm;

cfg_if::cfg_if! {
if #[cfg(target_vendor = "apple")] {
Expand All @@ -37,10 +36,9 @@ cfg_if::cfg_if! {
}
}

// fn(top_of_stack(%x0): *mut u8)
asm_func!(
wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_switch),
concat!(
#[unsafe(naked)]
pub(crate) unsafe extern "C" fn wasmtime_fiber_switch(top_of_stack: *mut u8 /* x0 */) {
naked_asm!(concat!(
"
.cfi_startproc
",
Expand Down Expand Up @@ -87,14 +85,9 @@ asm_func!(
ret
.cfi_endproc
",
),
);
));
}

// fn(
// top_of_stack(%x0): *mut u8,
// entry_point(%x1): extern fn(*mut u8, *mut u8),
// entry_arg0(%x2): *mut u8,
// )
// We set up the newly initialized fiber, so that it resumes execution
// from wasmtime_fiber_start(). As a result, we need a signed address
// of this function, so there are 2 requirements:
Expand All @@ -112,10 +105,14 @@ asm_func!(
// TODO: Use the PACGA instruction to authenticate the saved register
// state, which avoids creating signed pointers to
// wasmtime_fiber_start(), and provides wider coverage.
#[rustfmt::skip]
asm_func!(
wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_init),
concat!(
#[unsafe(naked)]
pub(crate) unsafe extern "C" fn wasmtime_fiber_init(
top_of_stack: *mut u8, // x0
entry_point: extern "C" fn(*mut u8, *mut u8), // x1
entry_arg0: *mut u8, // x2
) {
naked_asm!(
concat!(
"
.cfi_startproc
hint #34 // bti c
Expand All @@ -136,16 +133,18 @@ asm_func!(
ret
.cfi_endproc
",
),
fiber = sym wasmtime_fiber_start,
);
),
fiber = sym wasmtime_fiber_start,
);
}

// See the x86_64 file for more commentary on what these CFI directives are
// doing. Like over there note that the relative offsets to registers here
// match the frame layout in `wasmtime_fiber_switch`.
asm_func!(
wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_start),
"
#[unsafe(naked)]
unsafe extern "C" fn wasmtime_fiber_start() -> ! {
naked_asm!(
"
.cfi_startproc simple
.cfi_def_cfa_offset 0
.cfi_escape 0x0f, /* DW_CFA_def_cfa_expression */ \
Expand Down Expand Up @@ -180,5 +179,6 @@ asm_func!(
// codebase.
brk 0xf1b3
.cfi_endproc
",
);
",
);
}
Loading
Loading