|
3 | 3 | use crate::prelude::*; |
4 | 4 | use crate::runtime::vm::{StoreBox, VMArrayCallHostFuncContext, VMContext, VMOpaqueContext}; |
5 | 5 | use crate::type_registry::RegisteredType; |
6 | | -use crate::vm::InstanceAndStore; |
7 | 6 | use crate::{FuncType, ValRaw}; |
8 | 7 | use core::ptr::NonNull; |
9 | 8 |
|
@@ -35,32 +34,30 @@ unsafe extern "C" fn array_call_shim<F>( |
35 | 34 | where |
36 | 35 | F: Fn(NonNull<VMContext>, &mut [ValRaw]) -> Result<()> + 'static, |
37 | 36 | { |
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 | + }; |
48 | 46 |
|
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) |
64 | 61 | }) |
65 | 62 | } |
66 | 63 |
|
|
0 commit comments