@@ -16,9 +16,10 @@ mod signals;
16
16
pub use self :: signals:: * ;
17
17
18
18
use crate :: prelude:: * ;
19
+ use crate :: runtime:: store:: StoreOpaque ;
19
20
use crate :: runtime:: vm:: sys:: traphandlers;
20
21
use crate :: runtime:: vm:: { Instance , VMContext , VMRuntimeLimits } ;
21
- use crate :: WasmBacktrace ;
22
+ use crate :: { StoreContextMut , WasmBacktrace } ;
22
23
use core:: cell:: { Cell , UnsafeCell } ;
23
24
use core:: mem:: MaybeUninit ;
24
25
use core:: ops:: Range ;
@@ -164,27 +165,16 @@ impl From<wasmtime_environ::Trap> for TrapReason {
164
165
/// returning them as a `Result`.
165
166
///
166
167
/// Highly unsafe since `closure` won't have any dtors run.
167
- pub unsafe fn catch_traps < F > (
168
- signal_handler : Option < * const SignalHandler > ,
169
- capture_backtrace : bool ,
170
- capture_coredump : bool ,
171
- async_guard_range : Range < * mut u8 > ,
172
- caller : * mut VMContext ,
168
+ pub unsafe fn catch_traps < T , F > (
169
+ store : & mut StoreContextMut < ' _ , T > ,
173
170
mut closure : F ,
174
171
) -> Result < ( ) , Box < Trap > >
175
172
where
176
173
F : FnMut ( * mut VMContext ) ,
177
174
{
178
- let limits = Instance :: from_vmctx ( caller, |i| i. runtime_limits ( ) ) ;
179
-
180
- let result = CallThreadState :: new (
181
- signal_handler,
182
- capture_backtrace,
183
- capture_coredump,
184
- * limits,
185
- async_guard_range,
186
- )
187
- . with ( |cx| {
175
+ let caller = store. 0 . default_caller ( ) ;
176
+
177
+ let result = CallThreadState :: new ( store. 0 , caller) . with ( |cx| {
188
178
traphandlers:: wasmtime_setjmp (
189
179
cx. jmp_buf . as_ptr ( ) ,
190
180
call_closure :: < F > ,
@@ -260,26 +250,24 @@ mod call_thread_state {
260
250
261
251
impl CallThreadState {
262
252
#[ inline]
263
- pub ( super ) fn new (
264
- signal_handler : Option < * const SignalHandler > ,
265
- capture_backtrace : bool ,
266
- capture_coredump : bool ,
267
- limits : * const VMRuntimeLimits ,
268
- async_guard_range : Range < * mut u8 > ,
269
- ) -> CallThreadState {
270
- let _ = ( capture_coredump, signal_handler, & async_guard_range) ;
253
+ pub ( super ) fn new ( store : & mut StoreOpaque , caller : * mut VMContext ) -> CallThreadState {
254
+ let limits = unsafe { * Instance :: from_vmctx ( caller, |i| i. runtime_limits ( ) ) } ;
255
+
256
+ // Don't try to plumb #[cfg] everywhere for this field, just pretend
257
+ // we're using it on miri/windows to silence compiler warnings.
258
+ let _: Range < _ > = store. async_guard_range ( ) ;
271
259
272
260
CallThreadState {
273
261
unwind : UnsafeCell :: new ( MaybeUninit :: uninit ( ) ) ,
274
262
jmp_buf : Cell :: new ( ptr:: null ( ) ) ,
275
263
#[ cfg( all( feature = "signals-based-traps" , not( miri) ) ) ]
276
- signal_handler,
277
- capture_backtrace,
264
+ signal_handler : store . signal_handler ( ) ,
265
+ capture_backtrace : store . engine ( ) . config ( ) . wasm_backtrace ,
278
266
#[ cfg( feature = "coredump" ) ]
279
- capture_coredump,
267
+ capture_coredump : store . engine ( ) . config ( ) . coredump_on_trap ,
280
268
limits,
281
269
#[ cfg( all( feature = "signals-based-traps" , unix, not( miri) ) ) ]
282
- async_guard_range,
270
+ async_guard_range : store . async_guard_range ( ) ,
283
271
prev : Cell :: new ( ptr:: null ( ) ) ,
284
272
old_last_wasm_exit_fp : Cell :: new ( unsafe { * ( * limits) . last_wasm_exit_fp . get ( ) } ) ,
285
273
old_last_wasm_exit_pc : Cell :: new ( unsafe { * ( * limits) . last_wasm_exit_pc . get ( ) } ) ,
0 commit comments