Skip to content

Commit b63c25a

Browse files
fix(no_std)!: respect std feature when target is windows/unix (#11152)
* fix(no_std)!: respect `std` feature when target is windows/unix BREAKING CHANGE: the fix disables standard features for dependents that use wasmtime with `default-features = false`. * fix cargo check workflow * Don't require `std` feature for invalid faults Fill out the `compile_error!` to avoid failing a build. * addressing review comments * add `std` to `stack-switching` feature * remove `rustix/mm` from `std` feature dependencies * add `std` feature flag to `jit-icache-coherence` - The `std` feature gates the use of standard library for icache coherence in Windows; otherwise, defaults to the `libc` implementation. - The `std` feature of Wasmtime now depends on the `wasmtime-jit-icache-coherence/std` * Only include jit-icache-coherence on `std` builds prtest:full * Fix some idiom issues * More idiom issues * Require `std` for loading native code --------- Co-authored-by: Alex Crichton <[email protected]>
1 parent b221fca commit b63c25a

File tree

11 files changed

+40
-30
lines changed

11 files changed

+40
-30
lines changed

crates/jit-icache-coherence/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@
7474
//!
7575
//! [ARM Community - Caches and Self-Modifying Code]: https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/caches-and-self-modifying-code
7676
77-
#![no_std]
78-
79-
use core::ffi::c_void;
77+
use std::ffi::c_void;
8078

8179
cfg_if::cfg_if! {
8280
if #[cfg(target_os = "windows")] {

crates/jit-icache-coherence/src/libc.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use core::ffi::c_void;
1+
use std::ffi::c_void;
22

3-
#[cfg(any(target_os = "linux", target_os = "android"))]
4-
extern crate std;
53
#[cfg(any(target_os = "linux", target_os = "android"))]
64
pub use std::io::Result;
75

@@ -13,7 +11,6 @@ pub use anyhow::Result;
1311
any(target_os = "linux", target_os = "android")
1412
))]
1513
mod details {
16-
extern crate std;
1714

1815
use super::*;
1916
use libc::{EINVAL, EPERM, syscall};
@@ -107,15 +104,13 @@ mod details {
107104
fn riscv_flush_icache(start: u64, end: u64) -> Result<()> {
108105
cfg_if::cfg_if! {
109106
if #[cfg(feature = "one-core")] {
110-
use core::arch::asm;
107+
use std::arch::asm;
111108
let _ = (start, end);
112109
unsafe {
113110
asm!("fence.i");
114111
};
115112
Ok(())
116113
} else {
117-
extern crate std;
118-
119114
#[expect(non_upper_case_globals, reason = "matching C style")]
120115
match unsafe {
121116
libc::syscall(

crates/jit-icache-coherence/src/miri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub use anyhow::Result;
2-
use core::ffi::c_void;
2+
use std::ffi::c_void;
33

44
pub(crate) fn pipeline_flush_mt() -> Result<()> {
55
Ok(())

crates/jit-icache-coherence/src/win.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate std;
2-
31
use std::ffi::c_void;
42
use std::io::Error;
53
use windows_sys::Win32::System::Diagnostics::Debug::FlushInstructionCache;

crates/wasmtime/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,7 @@ runtime = [
254254
"dep:wasmtime-slab",
255255
"dep:wasmtime-versioned-export-macros",
256256
"dep:windows-sys",
257-
"dep:rustix",
258-
"rustix/mm",
259257
"pulley-interpreter/interp",
260-
"dep:wasmtime-jit-icache-coherence",
261258
"dep:wasmtime-unwinder",
262259
]
263260

@@ -309,6 +306,7 @@ threads = [
309306

310307
stack-switching = [
311308
"runtime",
309+
"std",
312310
"wasmtime-environ/stack-switching",
313311
"wasmtime-cranelift?/stack-switching",
314312
"wasmtime-winch?/stack-switching",
@@ -333,6 +331,8 @@ std = [
333331
'pulley-interpreter/std',
334332
'wasmtime-math/std',
335333
'addr2line?/std',
334+
"dep:rustix",
335+
"wasmtime-jit-icache-coherence",
336336
]
337337

338338
# Enables support for the `Store::call_hook` API which enables injecting custom

crates/wasmtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
#![expect(clippy::allow_attributes_without_reason, reason = "crate not migrated")]
296296
#![expect(unsafe_op_in_unsafe_fn, reason = "crate isn't migrated yet")]
297297

298-
#[cfg(any(feature = "std", unix, windows))]
298+
#[cfg(feature = "std")]
299299
#[macro_use]
300300
extern crate std;
301301
extern crate alloc;

crates/wasmtime/src/runtime.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub mod component;
6060
cfg_if::cfg_if! {
6161
if #[cfg(miri)] {
6262
// no extensions on miri
63+
} else if #[cfg(not(feature = "std"))] {
64+
// no extensions on no-std
6365
} else if #[cfg(unix)] {
6466
pub mod unix;
6567
} else if #[cfg(windows)] {

crates/wasmtime/src/runtime/code_memory.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,15 @@ impl CodeMemory {
319319
if !self.mmap.supports_virtual_memory() {
320320
bail!("this target requires virtual memory to be enabled");
321321
}
322+
if !cfg!(feature = "std") {
323+
bail!(
324+
"with the `std` feature disabled at compile time \
325+
there must be a custom implementation of publishing \
326+
code memory"
327+
);
328+
}
322329

323-
#[cfg(has_virtual_memory)]
330+
#[cfg(all(has_virtual_memory, feature = "std"))]
324331
{
325332
let text = self.text();
326333

crates/wasmtime/src/runtime/fiber.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ impl<T> StoreContextMut<'_, T> {
343343
self,
344344
f: impl FnOnce(StoreContextMut<'_, T>) -> Pin<Box<dyn Future<Output = R> + Send + '_>>,
345345
) -> Result<R> {
346-
BlockingContext::with(self.0, |store, cx| {
347-
cx.block_on(f(StoreContextMut(store)).as_mut())
348-
})
346+
self.with_blocking(|store, cx| cx.block_on(f(store).as_mut()))
349347
}
350348

351349
/// Creates a `BlockingContext` suitable for blocking on futures or

crates/wasmtime/src/runtime/store.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ impl StoreOpaque {
18471847
}
18481848

18491849
cfg_if::cfg_if! {
1850-
if #[cfg(any(feature = "std", unix, windows))] {
1850+
if #[cfg(feature = "std")] {
18511851
// With the standard library a rich error can be printed here
18521852
// to stderr and the native abort path is used.
18531853
eprintln!(
@@ -1879,14 +1879,23 @@ at https://bytecodealliance.org/security.
18791879
let _ = pc;
18801880
panic!("invalid fault");
18811881
} else {
1882-
// Without `std` and with `panic = "unwind"` there's no way to
1883-
// abort the process portably, so flag a compile time error.
1884-
//
1885-
// NB: if this becomes a problem in the future one option would
1886-
// be to extend the `capi.rs` module for no_std platforms, but
1887-
// it remains yet to be seen at this time if this is hit much.
1888-
compile_error!("either `std` or `panic=abort` must be enabled");
1889-
None
1882+
// Without `std` and with `panic = "unwind"` there's no
1883+
// dedicated API to abort the process portably, so manufacture
1884+
// this with a double-panic.
1885+
let _ = pc;
1886+
1887+
struct PanicAgainOnDrop;
1888+
1889+
impl Drop for PanicAgainOnDrop {
1890+
fn drop(&mut self) {
1891+
panic!("panicking again to trigger a process abort");
1892+
}
1893+
1894+
}
1895+
1896+
let _bomb = PanicAgainOnDrop;
1897+
1898+
panic!("invalid fault");
18901899
}
18911900
}
18921901
}

0 commit comments

Comments
 (0)