Skip to content

Commit fabfe8b

Browse files
committed
WIP.
1 parent ea49772 commit fabfe8b

File tree

5 files changed

+32
-38
lines changed

5 files changed

+32
-38
lines changed

crates/wasmtime/src/runtime/func.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,11 +2410,9 @@ impl HostContext {
24102410
//
24112411
// SAFETY: this is an entrypoint of wasm which requires correct type
24122412
// ascription of `T` itself, meaning that this should be safe to call.
2413-
crate::runtime::vm::catch_unwind_and_record_trap(
2414-
caller_vmctx,
2415-
|caller| unsafe { Caller::with(caller_vmctx, run) },
2416-
|caller| unsafe { Caller::with(caller_vmctx, |caller| AutoAssertNoGc::new(caller)) },
2417-
)
2413+
crate::runtime::vm::catch_unwind_and_record_trap(move || unsafe {
2414+
Caller::with(caller_vmctx, run)
2415+
})
24182416
}
24192417
}
24202418

crates/wasmtime/src/runtime/gc/enabled/exnref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl ExnRef {
557557
Ok(store.require_gc_store()?.header(gc_ref))
558558
}
559559

560-
pub(crate) fn exnref<'a>(&self, store: &'a AutoAssertNoGc<'_>) -> Result<&'a VMExnRef> {
560+
fn exnref<'a>(&self, store: &'a AutoAssertNoGc<'_>) -> Result<&'a VMExnRef> {
561561
assert!(self.comes_from_same_store(&store));
562562
let gc_ref = self.inner.try_gc_ref(store)?;
563563
debug_assert!(self.header(store)?.kind().matches(VMGcKind::ExnRef));

crates/wasmtime/src/runtime/trampoline/func.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use crate::prelude::*;
44
use crate::runtime::vm::{StoreBox, VMArrayCallHostFuncContext, VMContext, VMOpaqueContext};
55
use crate::type_registry::RegisteredType;
6-
use crate::vm::InstanceAndStore;
76
use crate::{FuncType, ValRaw};
87
use core::ptr::NonNull;
98

@@ -35,32 +34,30 @@ unsafe extern "C" fn array_call_shim<F>(
3534
where
3635
F: Fn(NonNull<VMContext>, &mut [ValRaw]) -> Result<()> + 'static,
3736
{
38-
InstanceAndStore::from_vmctx(vmctx, |pair| {
39-
// Be sure to catch Rust panics to manually shepherd them across the wasm
40-
// boundary, and then otherwise delegate as normal.
41-
crate::runtime::vm::catch_unwind_and_record_trap(pair, |_| {
42-
// SAFETY: this function itself requires that the `vmctx` is valid to
43-
// use here.
44-
let state = unsafe {
45-
let vmctx = VMArrayCallHostFuncContext::from_opaque(vmctx);
46-
vmctx.as_ref().host_state()
47-
};
37+
// Be sure to catch Rust panics to manually shepherd them across the wasm
38+
// boundary, and then otherwise delegate as normal.
39+
crate::runtime::vm::catch_unwind_and_record_trap(|| {
40+
// SAFETY: this function itself requires that the `vmctx` is valid to
41+
// use here.
42+
let state = unsafe {
43+
let vmctx = VMArrayCallHostFuncContext::from_opaque(vmctx);
44+
vmctx.as_ref().host_state()
45+
};
4846

49-
// Double-check ourselves in debug mode, but we control
50-
// the `Any` here so an unsafe downcast should also
51-
// work.
52-
//
53-
// SAFETY: this function is only usable with `TrampolineState<F>`.
54-
let state = unsafe {
55-
debug_assert!(state.is::<TrampolineState<F>>());
56-
&*(state as *const _ as *const TrampolineState<F>)
57-
};
58-
let mut values_vec = NonNull::slice_from_raw_parts(values_vec, values_vec_len);
59-
// SAFETY: it's a contract of this function itself that the values
60-
// provided are valid to view as a slice.
61-
let values_vec = unsafe { values_vec.as_mut() };
62-
(state.func)(caller_vmctx, values_vec)
63-
})
47+
// Double-check ourselves in debug mode, but we control
48+
// the `Any` here so an unsafe downcast should also
49+
// work.
50+
//
51+
// SAFETY: this function is only usable with `TrampolineState<F>`.
52+
let state = unsafe {
53+
debug_assert!(state.is::<TrampolineState<F>>());
54+
&*(state as *const _ as *const TrampolineState<F>)
55+
};
56+
let mut values_vec = NonNull::slice_from_raw_parts(values_vec, values_vec_len);
57+
// SAFETY: it's a contract of this function itself that the values
58+
// provided are valid to view as a slice.
59+
let values_vec = unsafe { values_vec.as_mut() };
60+
(state.func)(caller_vmctx, values_vec)
6461
})
6562
}
6663

crates/wasmtime/src/runtime/vm/libcalls.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ pub mod raw {
121121
) $(-> libcall!(@ty $result))? {
122122
$(#[cfg($attr)])?
123123
{
124-
InstanceAndStore::from_vmctx(vmctx, |pair| {
125-
crate::runtime::vm::traphandlers::catch_unwind_and_record_trap(pair, |pair| unsafe {
124+
crate::runtime::vm::traphandlers::catch_unwind_and_record_trap(|| unsafe {
125+
InstanceAndStore::from_vmctx(vmctx, |pair| {
126126
let (instance, store) = pair.unpack_mut();
127-
128127
super::$name(store, instance, $($pname),*)
129128
})
130129
})

crates/wasmtime/src/runtime/vm/traphandlers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub(super) unsafe fn raise_preexisting_trap() -> ! {
107107
///
108108
/// * `Result<(), E>` - this represents an ABI return value of `bool` which
109109
/// indicates whether the call succeeded. This return value will catch panics
110-
/// and record trap or exception information as `E`.
110+
/// and record trap information as `E`.
111111
///
112112
/// * `Result<u32, E>` - the ABI return value here is `u64` where on success
113113
/// the 32-bit result is zero-extended and `u64::MAX` as a return value
@@ -125,7 +125,7 @@ where
125125
// return value is always provided and if unwind information is provided
126126
// (e.g. `ret` is a "false"-y value) then it's recorded in TLS for the
127127
// unwind operation that's about to happen from Cranelift-generated code.
128-
let (ret, unwind) = R::maybe_catch_unwind(|| f());
128+
let (ret, unwind) = R::maybe_catch_unwind(f);
129129
if let Some(unwind) = unwind {
130130
tls::with(|info| info.unwrap().record_unwind(unwind));
131131
}
@@ -218,7 +218,7 @@ impl HostResult for NonNull<u8> {
218218
impl<T, E> HostResult for Result<T, E>
219219
where
220220
T: HostResultHasUnwindSentinel,
221-
E: Into<UnwindReason>,
221+
E: Into<TrapReason>,
222222
{
223223
type Abi = T::Abi;
224224

0 commit comments

Comments
 (0)