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
2 changes: 1 addition & 1 deletion .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ runs:
elif [ "${{ inputs.toolchain }}" = "msrv" ]; then
echo "version=1.$msrv.0" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.toolchain }}" = "wasmtime-ci-pinned-nightly" ]; then
echo "version=nightly-2024-06-13" >> "$GITHUB_OUTPUT"
echo "version=nightly-2024-07-25" >> "$GITHUB_OUTPUT"
else
echo "version=${{ inputs.toolchain }}" >> "$GITHUB_OUTPUT"
fi
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ authors = ["The Wasmtime Project Developers"]
edition = "2021"
# Wasmtime's current policy is that this number can be no larger than the
# current stable release of Rust minus 2.
rust-version = "1.77.0"
rust-version = "1.78.0"

[workspace.lints.rust]
# Turn on some lints which are otherwise allow-by-default in rustc.
Expand Down
31 changes: 12 additions & 19 deletions crates/wasmtime/src/runtime/vm/sys/miri/traphandlers.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
// For MIRI, set up just enough of a setjmp/longjmp with catching panics
// to get a few tests working that use this.
// For MIRI, there's no way to implement longjmp/setjmp. The only possible way
// to implement this is with panic/catch_panic, but the entrypoint into Rust
// from wasm is defined as `extern "C"` which isn't allowed to panic. That
// means that panicking here triggers UB which gets routed to `libc::abort()`.
//
// This maens that on MIRI all tests which trap are configured to be skipped at
// this time.
//
// Note that no actual JIT code runs in MIRI so this is purely here for
// host-to-host calls.

use crate::runtime::vm::VMContext;

struct WasmtimeLongjmp;

pub fn wasmtime_setjmp(
_jmp_buf: *mut *const u8,
callback: extern "C" fn(*mut u8, *mut VMContext),
payload: *mut u8,
callee: *mut VMContext,
) -> i32 {
use std::panic::{self, AssertUnwindSafe};
let result = panic::catch_unwind(AssertUnwindSafe(|| {
callback(payload, callee);
}));
match result {
Ok(()) => 1,
Err(e) => {
if e.is::<WasmtimeLongjmp>() {
0
} else {
panic::resume_unwind(e)
}
}
}
callback(payload, callee);
1
}

pub fn wasmtime_longjmp(_jmp_buf: *const u8) -> ! {
std::panic::panic_any(WasmtimeLongjmp)
unsafe {
libc::abort();
}
}

#[allow(missing_docs)]
Expand Down
2 changes: 1 addition & 1 deletion tests/all/call_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ async fn drop_suspended_async_hook() -> Result<(), Error> {
assert_eq!(*state, 0);
*state += 1;
let _dec = Decrement(state);
loop {
for _ in 0.. {
tokio::task::yield_now().await;
}
})
Expand Down
1 change: 1 addition & 0 deletions tests/all/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ fn import_works() -> Result<()> {
}

#[test]
#[cfg_attr(miri, ignore)]
fn trap_smoke() -> Result<()> {
let mut store = Store::<()>::default();
let f = Func::wrap(&mut store, || -> Result<()> { bail!("test") });
Expand Down
1 change: 1 addition & 0 deletions tests/all/host_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ fn call_wasm_many_args() -> Result<()> {
}

#[test]
#[cfg_attr(miri, ignore)]
fn trap_smoke() -> Result<()> {
let engine = Engine::default();
let mut linker = Linker::<()>::new(&engine);
Expand Down
10 changes: 5 additions & 5 deletions tests/all/traps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ fn rust_panic_import() -> Result<()> {
let module = Module::new(store.engine(), &binary)?;
let sig = FuncType::new(store.engine(), None, None);
let func = Func::new(&mut store, sig, |_, _, _| panic!("this is a panic"));
let func2 = Func::wrap(&mut store, || panic!("this is another panic"));
let func2 = Func::wrap(&mut store, || -> () { panic!("this is another panic") });
let instance = Instance::new(&mut store, &module, &[func.into(), func2.into()])?;
let func = instance.get_typed_func::<(), ()>(&mut store, "foo")?;
let err =
Expand Down Expand Up @@ -501,7 +501,7 @@ fn rust_panic_start_function() -> Result<()> {
.unwrap_err();
assert_eq!(err.downcast_ref::<&'static str>(), Some(&"this is a panic"));

let func = Func::wrap(&mut store, || panic!("this is another panic"));
let func = Func::wrap(&mut store, || -> () { panic!("this is another panic") });
let err = panic::catch_unwind(AssertUnwindSafe(|| {
drop(Instance::new(&mut store, &module, &[func.into()]));
}))
Expand Down Expand Up @@ -1007,7 +1007,7 @@ async fn async_then_sync_trap() -> Result<()> {
let sync_module = Module::new(sync_store.engine(), wat)?;

let mut sync_linker = Linker::new(sync_store.engine());
sync_linker.func_wrap("", "b", |_caller: Caller<_>| unreachable!())?;
sync_linker.func_wrap("", "b", |_caller: Caller<_>| -> () { unreachable!() })?;

let sync_instance = sync_linker.instantiate(&mut sync_store, &sync_module)?;

Expand Down Expand Up @@ -1085,7 +1085,7 @@ async fn sync_then_async_trap() -> Result<()> {
let async_module = Module::new(async_store.engine(), wat)?;

let mut async_linker = Linker::new(async_store.engine());
async_linker.func_wrap("", "b", |_caller: Caller<_>| unreachable!())?;
async_linker.func_wrap("", "b", |_caller: Caller<_>| -> () { unreachable!() })?;

let async_instance = async_linker
.instantiate_async(&mut async_store, &async_module)
Expand Down Expand Up @@ -1643,7 +1643,7 @@ fn same_module_multiple_stores() -> Result<()> {
let instance1 = Instance::new(&mut store1, &module, &[f1.into(), call_ref1.into()])?;

instance1
.get_typed_func(&mut store1, "a")?
.get_typed_func::<(), ()>(&mut store1, "a")?
.call(&mut store1, ())?;

let expected_stacks = vec![
Expand Down
10 changes: 7 additions & 3 deletions tests/host_segfault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn main() {
let engine = Engine::default();
let mut store = Store::new(&engine, ());
let module = Module::new(&engine, r#"(import "" "" (func)) (start 0)"#).unwrap();
let segfault = Func::wrap(&mut store, || segfault());
let segfault = Func::wrap(&mut store, || -> () { segfault() });
Instance::new(&mut store, &module, &[segfault.into()]).unwrap();
unreachable!();
},
Expand All @@ -140,7 +140,9 @@ fn main() {
let mut store = Store::new(&engine, ());
let f = Func::wrap_async(&mut store, |_, _: ()| {
Box::new(async {
overrun_the_stack();
if true {
overrun_the_stack();
}
})
});
run_future(f.call_async(&mut store, &[], &mut [])).unwrap();
Expand Down Expand Up @@ -172,7 +174,9 @@ fn main() {
let mut store = Store::new(&engine, ());
let f = Func::wrap_async(&mut store, |_, _: ()| {
Box::new(async {
overrun_the_stack();
if true {
overrun_the_stack();
}
})
});
run_future(f.call_async(&mut store, &[], &mut [])).unwrap();
Expand Down