A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Use `naked_asm!`, delete `asm_func!` (#11405)
Alex Crichton3e9eca8b23ac
diff --git a/Cargo.lock b/Cargo.lockindex b771352625..609c44c4eb 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4461,7 +4461,6 @@ dependencies = ["wasm-wave","wasmparser 0.239.0","wasmtime-environ",- "wasmtime-internal-asm-macros","wasmtime-internal-cache","wasmtime-internal-component-macro","wasmtime-internal-component-util",@@ -4715,13 +4714,6 @@ dependencies = ["wat",]-[[package]]-name = "wasmtime-internal-asm-macros"-version = "38.0.0"-dependencies = [- "cfg-if",-]-[[package]]name = "wasmtime-internal-c-api-macros"version = "38.0.0"@@ -4826,7 +4818,6 @@ dependencies = ["cfg-if","libc","rustix 1.0.3",- "wasmtime-internal-asm-macros","wasmtime-internal-versioned-export-macros","windows-sys 0.60.2",]diff --git a/Cargo.toml b/Cargo.tomlindex 22b70c8f5f..01917a3e23 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -259,7 +259,6 @@ wasmtime-fiber = { path = "crates/fiber", version = "=38.0.0", package = 'wasmtiwasmtime-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' }diff --git a/crates/asm-macros/Cargo.toml b/crates/asm-macros/Cargo.tomldeleted file mode 100644index 128140e7bd..0000000000--- a/crates/asm-macros/Cargo.toml+++ /dev/null@@ -1,14 +0,0 @@-[package]-authors = ["The Wasmtime Project Developers"]-description = "INTERNAL: Macros for defining asm functions in Wasmtime"-edition.workspace = true-rust-version.workspace = true-license = "Apache-2.0 WITH LLVM-exception"-name = "wasmtime-internal-asm-macros"-repository = "https://github.com/bytecodealliance/wasmtime"-version.workspace = true--# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html--[dependencies]-cfg-if = { workspace = true }diff --git a/crates/asm-macros/src/lib.rs b/crates/asm-macros/src/lib.rsdeleted file mode 100644index cea060e9fd..0000000000--- a/crates/asm-macros/src/lib.rs+++ /dev/null@@ -1,90 +0,0 @@-//! This crate defines a macro named `asm_func!` which is suitable for-//! generating a single `global_asm!`-defined function.-//!-//! This macro takes care of platform-specific directives to get the symbol-//! attributes correct (e.g. ELF symbols get a size and are flagged as a-//! function) and additionally handles visibility across platforms. All symbols-//! should be visible to Rust but not visible externally outside of a `*.so`.-//!-//! > **⚠️ Warning ⚠️**: this crate is an internal-only crate for the Wasmtime-//! > project and is not intended for general use. APIs are not strictly-//! > reviewed for safety and usage outside of Wasmtime may have bugs. If-//! > you're interested in using this feel free to file an issue on the-//! > Wasmtime repository to start a discussion about doing so, but otherwise-//! > be aware that your usage of this crate is not supported.--#![no_std]--cfg_if::cfg_if! {- if #[cfg(target_vendor = "apple")] {- #[macro_export]- macro_rules! asm_func {- ($name:expr, $body:expr $(, $($args:tt)*)?) => {- core::arch::global_asm!(- concat!(- ".p2align 4\n",- ".private_extern _", $name, "\n",- ".global _", $name, "\n",- "_", $name, ":\n",- $body,- ),- $($($args)*)?- );- };- }- } else if #[cfg(target_os = "windows")] {- #[macro_export]- macro_rules! asm_func {- ($name:expr, $body:expr $(, $($args:tt)*)?) => {- core::arch::global_asm!(- concat!(- ".def ", $name, "\n",- ".scl 2\n",- ".type 32\n",- ".endef\n",- ".global ", $name, "\n",- ".p2align 4\n",- $name, ":\n",- $body- ),- $($($args)*)?- );- };- }- } else {- // Note that for now this "else" clause just assumes that everything- // other than macOS is ELF and has the various directives here for- // that.- cfg_if::cfg_if! {- if #[cfg(target_arch = "arm")] {- #[macro_export]- macro_rules! elf_func_type_header {- ($name:tt) => (concat!(".type ", $name, ",%function\n"))- }- } else {- #[macro_export]- macro_rules! elf_func_type_header {- ($name:tt) => (concat!(".type ", $name, ",@function\n"))- }- }- }-- #[macro_export]- macro_rules! asm_func {- ($name:expr, $body:expr $(, $($args:tt)*)?) => {- core::arch::global_asm!(- concat!(- ".p2align 4\n",- ".hidden ", $name, "\n",- ".global ", $name, "\n",- $crate::elf_func_type_header!($name),- $name, ":\n",- $body,- ".size ", $name, ",.-", $name,- )- $(, $($args)*)?- );- };- }- }-}diff --git a/crates/fiber/Cargo.toml b/crates/fiber/Cargo.tomlindex b98542dc85..8c2692e0e8 100644--- a/crates/fiber/Cargo.toml+++ b/crates/fiber/Cargo.toml@@ -15,7 +15,6 @@ workspace = trueanyhow = { 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"] }diff --git a/crates/fiber/build.rs b/crates/fiber/build.rsindex d14343fc08..10ccd4ee19 100644--- a/crates/fiber/build.rs+++ b/crates/fiber/build.rs@@ -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 unsupporteddiff --git a/crates/fiber/src/lib.rs b/crates/fiber/src/lib.rsindex 268e88afce..c1b4b3e60d 100644--- a/crates/fiber/src/lib.rs+++ b/crates/fiber/src/lib.rs@@ -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;@@ -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);diff --git a/crates/fiber/src/stackswitch.rs b/crates/fiber/src/stackswitch.rsindex 57fbc5c559..d030536d5f 100644--- a/crates/fiber/src/stackswitch.rs+++ b/crates/fiber/src/stackswitch.rs@@ -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.@@ -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 hostdiff --git a/crates/fiber/src/stackswitch/aarch64.rs b/crates/fiber/src/stackswitch/aarch64.rsindex c0b9272f8e..3711e83920 100644--- a/crates/fiber/src/stackswitch/aarch64.rs+++ b/crates/fiber/src/stackswitch/aarch64.rs@@ -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")] {@@ -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",@@ -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:@@ -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_startprochint #34 // bti c@@ -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 */ \@@ -180,5 +179,6 @@ asm_func!(// codebase.brk 0xf1b3.cfi_endproc- ",-);+ ",+ );+}diff --git a/crates/fiber/src/stackswitch/arm.rs b/crates/fiber/src/stackswitch/arm.rsindex b47faefd53..44f88b4252 100644--- a/crates/fiber/src/stackswitch/arm.rs+++ b/crates/fiber/src/stackswitch/arm.rs@@ -8,12 +8,12 @@// Also at this time this file is heavily based off the x86_64 file, so you'll// probably want to read that one as well.-use wasmtime_asm_macros::asm_func;+use core::arch::naked_asm;-// fn(top_of_stack(%r0): *mut u8)-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_switch),- "+#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_switch(top_of_stack: *mut u8 /* r0 */) {+ naked_asm!(+ "// Save callee-saved registerspush {{r4-r11,lr}}@@ -25,17 +25,18 @@ asm_func!(// Restore and returnpop {{r4-r11,lr}}bx lr- ",-);+ ",+ );+}-// fn(-// top_of_stack(%r0): *mut u8,-// entry_point(%r1): extern fn(*mut u8, *mut u8),-// entry_arg0(%r2): *mut u8,-// )-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_init),- "+#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_init(+ top_of_stack: *mut u8, // r0+ entry_point: extern "C" fn(*mut u8, *mut u8), // r1+ entry_arg0: *mut u8, // r2+) {+ naked_asm!(+ "adr r3, {start}str r3, [r0, #-0x0c] // => lrstr r0, [r0, #-0x10] // => r11@@ -45,13 +46,15 @@ asm_func!(add r3, r0, #-0x2cstr r3, [r0, #-0x08]bx lr- ",- start = sym super::wasmtime_fiber_start,-);+ ",+ start = sym wasmtime_fiber_start,+ );+}-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// See the x86_64 file for more commentary on what these CFI directives@@ -82,5 +85,6 @@ asm_func!(mov r0, r9blx r10.cfi_endproc- ",-);+ ",+ );+}diff --git a/crates/fiber/src/stackswitch/riscv64.rs b/crates/fiber/src/stackswitch/riscv64.rsindex 61966f7b3f..4267dfc149 100644--- a/crates/fiber/src/stackswitch/riscv64.rs+++ b/crates/fiber/src/stackswitch/riscv64.rs@@ -5,12 +5,12 @@// all the other bits. Documentation tries to reference various bits here and// there but try to make sure to read over everything before tweaking things!-use wasmtime_asm_macros::asm_func;+use core::arch::naked_asm;-// fn(top_of_stack(rdi): *mut u8)-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_switch),- "+#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_switch(top_of_stack: *mut u8 /* a0 */) {+ naked_asm!(+ "// See https://github.com/rust-lang/rust/issues/80608..attribute arch, \"rv64gc\"@@ -80,18 +80,18 @@ asm_func!(ld ra,0xc8(sp)addi sp , sp , 0xd0jr ra- ",-);+ ",+ );+}-// fn(-// top_of_stack(a0): *mut u8,-// entry_point(a1): extern fn(*mut u8, *mut u8),-// entry_arg0(a2): *mut u8,-// )-#[rustfmt::skip]-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_init),- "+#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_init(+ top_of_stack: *mut u8, // a0+ entry_point: extern "C" fn(*mut u8, *mut u8), // a1+ entry_arg0: *mut u8, // a2+) {+ naked_asm!(+ "lla t0,{}sd t0,-0x18(a0) // ra,first should be wasmtime_fiber_start.sd a0,-0x20(a0) // fp pointer.@@ -103,12 +103,14 @@ asm_func!(sd t0,-0x10(a0)ret",- sym super::wasmtime_fiber_start,-);+ sym wasmtime_fiber_start,+ );+}-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@@ -155,4 +157,5 @@ asm_func!(.4byte 0.cfi_endproc",-);+ );+}diff --git a/crates/fiber/src/stackswitch/s390x.S b/crates/fiber/src/stackswitch/s390x.Sdeleted file mode 100644index 4207fcb70c..0000000000--- a/crates/fiber/src/stackswitch/s390x.S+++ /dev/null@@ -1,123 +0,0 @@-// A WORD OF CAUTION-//-// This entire file basically needs to be kept in sync with itself. It's not-// really possible to modify just one bit of this file without understanding-// all the other bits. Documentation tries to reference various bits here and-// there but try to make sure to read over everything before tweaking things!-//-// Also at this time this file is heavily based off the x86_64 file, so you'll-// probably want to read that one as well.--.text--#define CONCAT2(a, b) a ## b-#define CONCAT(a, b) CONCAT2(a , b)-#define VERSIONED_SYMBOL(a) CONCAT(a, VERSIONED_SUFFIX)-#define GLOBL(fnname) .globl VERSIONED_SYMBOL(fnname)-#define HIDDEN(fnname) .hidden VERSIONED_SYMBOL(fnname)-#define TYPE(fnname) .type VERSIONED_SYMBOL(fnname),@function-#define FUNCTION(fnname) VERSIONED_SYMBOL(fnname)-#define SIZE(fnname) .size VERSIONED_SYMBOL(fnname),.-VERSIONED_SYMBOL(fnname)--// fn(top_of_stack(%x0): *mut u8)-HIDDEN(wasmtime_fiber_switch)-GLOBL(wasmtime_fiber_switch)-.p2align 2-TYPE(wasmtime_fiber_switch)-FUNCTION(wasmtime_fiber_switch):- // Save all callee-saved registers on the stack since we're assuming- // they're clobbered as a result of the stack switch.- stmg %r6, %r15, 48(%r15)- aghi %r15, -64- std %f8, 0(%r15)- std %f9, 8(%r15)- std %f10, 16(%r15)- std %f11, 24(%r15)- std %f12, 32(%r15)- std %f13, 40(%r15)- std %f14, 48(%r15)- std %f15, 56(%r15)-- // Load our previously saved stack pointer to resume to, and save off our- // current stack pointer on where to come back to eventually.- lg %r1, -16(%r2)- stg %r15, -16(%r2)-- // Switch to the new stack and restore all our callee-saved registers after- // the switch and return to our new stack.- ld %f8, 0(%r1)- ld %f9, 8(%r1)- ld %f10, 16(%r1)- ld %f11, 24(%r1)- ld %f12, 32(%r1)- ld %f13, 40(%r1)- ld %f14, 48(%r1)- ld %f15, 56(%r1)- lmg %r6, %r15, 112(%r1)- br %r14-SIZE(wasmtime_fiber_switch)--// fn(-// top_of_stack(%x0): *mut u8,-// entry_point(%x1): extern fn(*mut u8, *mut u8),-// entry_arg0(%x2): *mut u8,-// )-HIDDEN(wasmtime_fiber_init)-GLOBL(wasmtime_fiber_init)-.p2align 2-TYPE(wasmtime_fiber_init)-FUNCTION(wasmtime_fiber_init):- larl %r1, FUNCTION(wasmtime_fiber_start)- stg %r1, -48(%r2) // wasmtime_fiber_start - restored into %r14- stg %r2, -112(%r2) // top_of_stack - restored into %r6- stg %r3, -104(%r2) // entry_point - restored into %r7- stg %r4, -96(%r2) // entry_arg0 - restored into %r8- aghi %r2, -160 // 160 bytes register save area- stg %r2, 120(%r2) // bottom of register save area - restored into %r15-- // `wasmtime_fiber_switch` has a 64 byte stack.- aghi %r2, -64- stg %r2, 208(%r2)- br %r14-SIZE(wasmtime_fiber_init)--.p2align 2-TYPE(wasmtime_fiber_start)-FUNCTION(wasmtime_fiber_start):-.cfi_startproc simple-.cfi_def_cfa_offset 0-- // 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`.- .cfi_escape 0x0f, /* DW_CFA_def_cfa_expression */ \- 7, /* the byte length of this expression */ \- 0x7f, 0x90, 0x1, /* DW_OP_breg15 0x90 */ \- 0x06, /* DW_OP_deref */ \- 0x23, 0xe0, 0x1 /* DW_OP_plus_uconst 0xe0 */-- .cfi_rel_offset 6, -112- .cfi_rel_offset 7, -104- .cfi_rel_offset 8, -96- .cfi_rel_offset 9, -88- .cfi_rel_offset 10, -80- .cfi_rel_offset 11, -72- .cfi_rel_offset 12, -64- .cfi_rel_offset 13, -56- .cfi_rel_offset 14, -48- .cfi_rel_offset 15, -40-- // Load our two arguments prepared by `wasmtime_fiber_init`.- lgr %r2, %r8 // entry_arg0- lgr %r3, %r6 // top_of_stack-- // ... and then we call the function! Note that this is a function call so- // our frame stays on the stack to backtrace through.- basr %r14, %r7 // entry_point- // .. technically we shouldn't get here, so just trap.- .word 0x0000- .cfi_endproc-SIZE(wasmtime_fiber_start)--// Mark that we don't need executable stack.-.section .note.GNU-stack,"",%progbitsdiff --git a/crates/fiber/src/stackswitch/s390x.rs b/crates/fiber/src/stackswitch/s390x.rsnew file mode 100644index 0000000000..b284ee2b7b--- /dev/null+++ b/crates/fiber/src/stackswitch/s390x.rs@@ -0,0 +1,112 @@+// A WORD OF CAUTION+//+// This entire file basically needs to be kept in sync with itself. It's not+// really possible to modify just one bit of this file without understanding+// all the other bits. Documentation tries to reference various bits here and+// there but try to make sure to read over everything before tweaking things!++use core::arch::naked_asm;++#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_switch(top_of_stack: *mut u8 /* x0 */) {+ naked_asm!(+ "+ // Save all callee-saved registers on the stack since we're assuming+ // they're clobbered as a result of the stack switch.+ stmg %r6, %r15, 48(%r15)+ aghi %r15, -64+ std %f8, 0(%r15)+ std %f9, 8(%r15)+ std %f10, 16(%r15)+ std %f11, 24(%r15)+ std %f12, 32(%r15)+ std %f13, 40(%r15)+ std %f14, 48(%r15)+ std %f15, 56(%r15)++ // Load our previously saved stack pointer to resume to, and save off our+ // current stack pointer on where to come back to eventually.+ lg %r1, -16(%r2)+ stg %r15, -16(%r2)++ // Switch to the new stack and restore all our callee-saved registers after+ // the switch and return to our new stack.+ ld %f8, 0(%r1)+ ld %f9, 8(%r1)+ ld %f10, 16(%r1)+ ld %f11, 24(%r1)+ ld %f12, 32(%r1)+ ld %f13, 40(%r1)+ ld %f14, 48(%r1)+ ld %f15, 56(%r1)+ lmg %r6, %r15, 112(%r1)+ br %r14+ ",+ );+}++#[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!(+ "+ larl %r1, {}+ stg %r1, -48(%r2) // wasmtime_fiber_start - restored into %r14+ stg %r2, -112(%r2) // top_of_stack - restored into %r6+ stg %r3, -104(%r2) // entry_point - restored into %r7+ stg %r4, -96(%r2) // entry_arg0 - restored into %r8+ aghi %r2, -160 // 160 bytes register save area+ stg %r2, 120(%r2) // bottom of register save area - restored into %r15++ // `wasmtime_fiber_switch` has a 64 byte stack.+ aghi %r2, -64+ stg %r2, 208(%r2)+ br %r14+ ",+ sym wasmtime_fiber_start,+ );+}++#[unsafe(naked)]+unsafe extern "C" fn wasmtime_fiber_start() -> ! {+ naked_asm!(+ "+ .cfi_startproc simple+ .cfi_def_cfa_offset 0++ // 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`.+ .cfi_escape 0x0f, /* DW_CFA_def_cfa_expression */ \+ 7, /* the byte length of this expression */ \+ 0x7f, 0x90, 0x1, /* DW_OP_breg15 0x90 */ \+ 0x06, /* DW_OP_deref */ \+ 0x23, 0xe0, 0x1 /* DW_OP_plus_uconst 0xe0 */++ .cfi_rel_offset 6, -112+ .cfi_rel_offset 7, -104+ .cfi_rel_offset 8, -96+ .cfi_rel_offset 9, -88+ .cfi_rel_offset 10, -80+ .cfi_rel_offset 11, -72+ .cfi_rel_offset 12, -64+ .cfi_rel_offset 13, -56+ .cfi_rel_offset 14, -48+ .cfi_rel_offset 15, -40++ // Load our two arguments prepared by `wasmtime_fiber_init`.+ lgr %r2, %r8 // entry_arg0+ lgr %r3, %r6 // top_of_stack++ // ... and then we call the function! Note that this is a function call so+ // our frame stays on the stack to backtrace through.+ basr %r14, %r7 // entry_point+ // .. technically we shouldn't get here, so just trap.+ .word 0x0000+ .cfi_endproc+ ",+ );+}diff --git a/crates/fiber/src/stackswitch/x86.rs b/crates/fiber/src/stackswitch/x86.rsindex a6a3b82c96..ec20a3d045 100644--- a/crates/fiber/src/stackswitch/x86.rs+++ b/crates/fiber/src/stackswitch/x86.rs@@ -10,12 +10,12 @@// different so the reserved space at the top of the stack is 8 bytes, not 16// bytes. Still two pointers though.-use wasmtime_asm_macros::asm_func;+use core::arch::naked_asm;-// fn(top_of_stack: *mut u8)-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_switch),- "+#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_switch(top_of_stack: *mut u8) {+ naked_asm!(+ "// Load our stack-to-usemov eax, 0x4[esp]mov ecx, -0x8[eax]@@ -36,17 +36,18 @@ asm_func!(pop ebxpop ebpret- ",-);+ ",+ )+}-// fn(-// top_of_stack: *mut u8,-// entry_point: extern fn(*mut u8, *mut u8),-// entry_arg0: *mut u8,-// )-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_init),- "+#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_init(+ top_of_stack: *mut u8,+ entry_point: extern "C" fn(*mut u8, *mut u8),+ entry_arg0: *mut u8,+) {+ naked_asm!(+ "mov eax, 4[esp]// move top_of_stack to the 2nd argument@@ -79,13 +80,15 @@ asm_func!(lea ecx, -0x24[eax]mov -0x08[eax], ecxret- ",- start = sym super::wasmtime_fiber_start,-);+ ",+ start = sym wasmtime_fiber_start,+ );+}-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 */ \@@ -105,5 +108,6 @@ asm_func!(call ebpud2.cfi_endproc- ",-);+ ",+ );+}diff --git a/crates/fiber/src/stackswitch/x86_64.rs b/crates/fiber/src/stackswitch/x86_64.rsindex 15e4fd57a9..4a826bf9a0 100644--- a/crates/fiber/src/stackswitch/x86_64.rs+++ b/crates/fiber/src/stackswitch/x86_64.rs@@ -5,12 +5,12 @@// all the other bits. Documentation tries to reference various bits here and// there but try to make sure to read over everything before tweaking things!-use wasmtime_asm_macros::asm_func;+use core::arch::naked_asm;-// fn(top_of_stack(rdi): *mut u8)-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_switch),- "+#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_switch(top_of_stack: *mut u8 /* rdi */) {+ naked_asm!(+ "// We're switching to arbitrary code somewhere else, so pessimistically// assume that all callee-save register are clobbered. This means we need// to save/restore all of them.@@ -40,17 +40,17 @@ asm_func!(pop rbpret",-);+ );+}-// fn(-// top_of_stack(rdi): *mut u8,-// entry_point(rsi): extern fn(*mut u8, *mut u8),-// entry_arg0(rdx): *mut u8,-// )-#[rustfmt::skip]-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_init),- "+#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_fiber_init(+ top_of_stack: *mut u8, // rdi+ entry_point: extern "C" fn(*mut u8, *mut u8), // rsi+ entry_arg0: *mut u8, // rdx+) {+ naked_asm!(+ "// Here we're going to set up a stack frame as expected by// `wasmtime_fiber_switch`. The values we store here will get restored into// registers by that function and the `wasmtime_fiber_start` function will@@ -72,9 +72,10 @@ asm_func!(lea rax, -0x48[rdi]mov -0x10[rdi], raxret- ",- start = sym super::wasmtime_fiber_start,-);+ ",+ start = sym wasmtime_fiber_start,+ );+}// This is a pretty special function that has no real signature. Its use is to// be the "base" function of all fibers. This entrypoint is used in@@ -88,9 +89,10 @@ asm_func!(//// If you're curious a decent introduction to CFI things and unwinding is at// https://www.imperialviolet.org/2017/01/18/cfi.html-asm_func!(- wasmtime_versioned_export_macros::versioned_stringify_ident!(wasmtime_fiber_start),- "+#[unsafe(naked)]+unsafe extern "C" fn wasmtime_fiber_start() -> ! {+ naked_asm!(+ "// Use the `simple` directive on the startproc here which indicates that// some default settings for the platform are omitted, since this// function is so nonstandard@@ -156,5 +158,6 @@ asm_func!(call rbxud2.cfi_endproc- ",-);+ ",+ );+}diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.tomlindex b55310ca77..81ccc0e508 100644--- a/crates/wasmtime/Cargo.toml+++ b/crates/wasmtime/Cargo.toml@@ -17,7 +17,6 @@ workspace = trueall-features = true[dependencies]-wasmtime-asm-macros = { workspace = true, optional = true }wasmtime-environ = { workspace = true }wasmtime-jit-debug = { workspace = true, optional = true }wasmtime-jit-icache-coherence = { workspace = true, optional = true }@@ -258,7 +257,6 @@ runtime = ["dep:smallvec","dep:mach2","dep:memfd",- "dep:wasmtime-asm-macros","dep:wasmtime-slab","dep:wasmtime-versioned-export-macros","dep:windows-sys",diff --git a/crates/wasmtime/src/runtime/vm/stack_switching/stack/unix.rs b/crates/wasmtime/src/runtime/vm/stack_switching/stack/unix.rsindex 074a43d0fb..300af997d9 100644--- a/crates/wasmtime/src/runtime/vm/stack_switching/stack/unix.rs+++ b/crates/wasmtime/src/runtime/vm/stack_switching/stack/unix.rs@@ -293,10 +293,6 @@ impl Drop for VMContinuationStack {}}-unsafe extern "C" {- fn wasmtime_continuation_start();-}-/// This function is responsible for actually running a wasm function inside a/// continuation. It is only ever called from `wasmtime_continuation_start`.unsafe extern "C" fn fiber_start(@@ -344,6 +340,7 @@ unsafe extern "C" fn fiber_start(cfg_if::cfg_if! {if #[cfg(target_arch = "x86_64")] {mod x86_64;+ use x86_64::*;} else {// Note that this should be unreachable: In stack.rs, we currently select// the module defined in the current file only if we are on unix ANDdiff --git a/crates/wasmtime/src/runtime/vm/stack_switching/stack/unix/x86_64.rs b/crates/wasmtime/src/runtime/vm/stack_switching/stack/unix/x86_64.rsindex 3a2292dd8e..8591a933f0 100644--- a/crates/wasmtime/src/runtime/vm/stack_switching/stack/unix/x86_64.rs+++ b/crates/wasmtime/src/runtime/vm/stack_switching/stack/unix/x86_64.rs@@ -5,7 +5,7 @@// all the other bits. Documentation tries to reference various bits here and// there but try to make sure to read over everything before tweaking things!-use wasmtime_asm_macros::asm_func;+use core::arch::naked_asm;// This is a pretty special function that has no real signature. Its use is to// be the "base" function of all fibers. This entrypoint is used in@@ -30,9 +30,11 @@ use wasmtime_asm_macros::asm_func;//// RSP: TOS - 0x40 - (16 * `args_capacity`)// RBP: TOS - 0x10-asm_func!(- "wasmtime_continuation_start",- "++#[unsafe(naked)]+pub(crate) unsafe extern "C" fn wasmtime_continuation_start() {+ naked_asm!(+ "// TODO(frank-emrich): Restore DWARF information for this function. In// the meantime, debugging is possible using frame pointer walking.@@ -72,9 +74,10 @@ asm_func!(mov rdi, 0jmp rsi- ",- fiber_start = sym super::fiber_start,-);+ ",+ fiber_start = sym super::fiber_start,+ );+}#[test]fn test_return_payload() {diff --git a/scripts/publish.rs b/scripts/publish.rsindex 230039fded..c9f8feea64 100644--- a/scripts/publish.rs+++ b/scripts/publish.rs@@ -53,7 +53,6 @@ const CRATES_TO_PUBLISH: &[&str] = &[// winch"winch",// wasmtime- "wasmtime-internal-asm-macros","wasmtime-internal-versioned-export-macros","wasmtime-internal-slab","wasmtime-internal-component-util",diff --git a/supply-chain/config.toml b/supply-chain/config.tomlindex f0a889ab93..2f76e3588e 100644--- a/supply-chain/config.toml+++ b/supply-chain/config.toml@@ -127,9 +127,6 @@ criteria = [][policy.wasmtime-fuzzing]criteria = []-[policy.wasmtime-internal-asm-macros]-audit-as-crates-io = true-[policy.wasmtime-internal-c-api-macros]audit-as-crates-io = truediff --git a/supply-chain/imports.lock b/supply-chain/imports.lockindex 72917e274b..bf1119cc1f 100644--- a/supply-chain/imports.lock+++ b/supply-chain/imports.lock@@ -1411,12 +1411,6 @@ when = "2025-08-26"user-id = 73222user-login = "wasmtime-publish"-[[publisher.wasmtime-internal-asm-macros]]-version = "36.0.2"-when = "2025-08-26"-user-id = 73222-user-login = "wasmtime-publish"-[[publisher.wasmtime-internal-c-api-macros]]version = "36.0.2"when = "2025-08-26"