@@ -5,7 +5,7 @@ use core::ptr::NonNull;
55use wasmtime_environ:: { TagIndex , Trap } ;
66use wasmtime_unwinder:: { Frame , ThrowAction } ;
77
8- use super :: { InstanceAndStore , VMContext , VMExnRef } ;
8+ use super :: { VMContext , VMExnRef } ;
99use crate :: {
1010 store:: AutoAssertNoGc ,
1111 vm:: { TrapReason , catch_unwind_and_record_trap, raise_preexisting_trap} ,
@@ -70,15 +70,21 @@ pub unsafe fn throw(nogc: &mut AutoAssertNoGc, exnref: VMExnRef) -> ! {
7070 let frame_vmctx =
7171 NonNull :: new ( frame_vmctx as * mut VMContext ) . expect ( "null vmctx in frame" ) ;
7272
73+ // SAFETY: we use `instance_from_vmctx` to get an
74+ // `&Instance` from a raw vmctx we read off the
75+ // stack frame. That method's safety requirements
76+ // are that the `vmctx` is a valid vmctx belonging
77+ // to an instance in the store (`nogc`). This is
78+ // satisfied because every Wasm frame in this
79+ // activation must belong to an instance in this
80+ // store: we do not permit cross-store calls
81+ // without exiting through host code.
7382 let ( handler_tag_instance, handler_tag_index) = unsafe {
74- InstanceAndStore :: from_vmctx ( frame_vmctx, |instance| {
75- let ( instance, store) = instance. unpack_mut ( ) ;
76- let tag = instance. get_exported_tag (
77- store. id ( ) ,
78- TagIndex :: from_u32 ( module_local_tag_index) ,
79- ) ;
80- tag. to_raw_indices ( )
81- } )
83+ let store_id = nogc. id ( ) ;
84+ let instance = nogc. instance_from_vmctx ( frame_vmctx) ;
85+ let tag = instance
86+ . get_exported_tag ( store_id, TagIndex :: from_u32 ( module_local_tag_index) ) ;
87+ tag. to_raw_indices ( )
8288 } ;
8389 log:: trace!(
8490 "-> handler's tag {module_local_tag_index:?} resolves to instance {handler_tag_instance:?} defined-tag {handler_tag_index:?}"
0 commit comments