@@ -7,6 +7,7 @@ pub use crate::instance::execution::{KillError, KillState, KillSuccess, KillSwit
77pub use crate :: instance:: signals:: { signal_handler_none, SignalBehavior , SignalHandler } ;
88pub use crate :: instance:: state:: State ;
99
10+ use crate :: alloc:: Alloc ;
1011use crate :: context:: Context ;
1112use crate :: embed_ctx:: CtxMap ;
1213use crate :: error:: Error ;
@@ -17,13 +18,13 @@ use crate::region::RegionInternal;
1718use crate :: sysdeps:: HOST_PAGE_SIZE_EXPECTED ;
1819use crate :: val:: { UntypedRetVal , Val } ;
1920use crate :: WASM_PAGE_SIZE ;
20- use crate :: { alloc:: Alloc , future:: AsyncContext } ;
2121use libc:: { c_void, pthread_self, siginfo_t, uintptr_t} ;
2222use lucet_module:: InstanceRuntimeData ;
2323use memoffset:: offset_of;
2424use std:: any:: Any ;
2525use std:: cell:: { BorrowError , BorrowMutError , Ref , RefCell , RefMut , UnsafeCell } ;
2626use std:: convert:: TryFrom ;
27+ use std:: marker:: PhantomData ;
2728use std:: mem;
2829use std:: ops:: { Deref , DerefMut } ;
2930use std:: ptr:: { self , NonNull } ;
@@ -514,7 +515,7 @@ impl Instance {
514515 /// in the future.
515516 pub fn run ( & mut self , entrypoint : & str , args : & [ Val ] ) -> Result < RunResult , Error > {
516517 let func = self . module . get_export_func ( entrypoint) ?;
517- Ok ( self . run_func ( func, & args, None , None ) ?. unwrap ( ) )
518+ Ok ( self . run_func ( func, & args, false , None ) ?. unwrap ( ) )
518519 }
519520
520521 /// Run a function with arguments in the guest context from the [WebAssembly function
@@ -530,7 +531,7 @@ impl Instance {
530531 args : & [ Val ] ,
531532 ) -> Result < RunResult , Error > {
532533 let func = self . module . get_func_from_idx ( table_idx, func_idx) ?;
533- Ok ( self . run_func ( func, & args, None , None ) ?. unwrap ( ) )
534+ Ok ( self . run_func ( func, & args, false , None ) ?. unwrap ( ) )
534535 }
535536
536537 /// Resume execution of an instance that has yielded without providing a value to the guest.
@@ -561,21 +562,19 @@ impl Instance {
561562 /// The foreign code safety caveat of [`Instance::run()`](struct.Instance.html#method.run)
562563 /// applies.
563564 pub fn resume_with_val < A : Any + ' static > ( & mut self , val : A ) -> Result < RunResult , Error > {
564- Ok ( self
565- . resume_with_val_impl ( Box :: new ( val) , None , None ) ?
566- . unwrap ( ) )
565+ Ok ( self . resume_with_val_impl ( val, false , None ) ?. unwrap ( ) )
567566 }
568567
569- pub ( crate ) fn resume_with_val_impl (
568+ pub ( crate ) fn resume_with_val_impl < A : Any + ' static > (
570569 & mut self ,
571- val : Box < dyn Any + ' static > ,
572- async_context : Option < AsyncContext > ,
570+ val : A ,
571+ async_context : bool ,
573572 max_insn_count : Option < u64 > ,
574573 ) -> Result < InternalRunResult , Error > {
575574 match & self . state {
576575 State :: Yielded { expecting, .. } => {
577576 // make sure the resumed value is of the right type
578- if & ( * val ) . type_id ( ) != expecting {
577+ if !expecting . is :: < PhantomData < A > > ( ) {
579578 return Err ( Error :: InvalidArgument (
580579 "type mismatch between yielded instance expected value and resumed value" ,
581580 ) ) ;
@@ -584,7 +583,7 @@ impl Instance {
584583 _ => return Err ( Error :: InvalidArgument ( "can only resume a yielded instance" ) ) ,
585584 }
586585
587- self . resumed_val = Some ( val) ;
586+ self . resumed_val = Some ( Box :: new ( val) as Box < dyn Any + ' static > ) ;
588587
589588 self . set_instruction_bound_delta ( max_insn_count) ;
590589 self . swap_and_return ( async_context)
@@ -603,7 +602,6 @@ impl Instance {
603602 /// applies.
604603 pub ( crate ) fn resume_bounded (
605604 & mut self ,
606- async_context : AsyncContext ,
607605 max_insn_count : u64 ,
608606 ) -> Result < InternalRunResult , Error > {
609607 if !self . state . is_bound_expired ( ) {
@@ -612,7 +610,7 @@ impl Instance {
612610 ) ) ;
613611 }
614612 self . set_instruction_bound_delta ( Some ( max_insn_count) ) ;
615- self . swap_and_return ( Some ( async_context ) )
613+ self . swap_and_return ( true )
616614 }
617615
618616 /// Run the module's [start function][start], if one exists.
@@ -650,7 +648,7 @@ impl Instance {
650648 if !self . is_not_started ( ) {
651649 return Err ( Error :: StartAlreadyRun ) ;
652650 }
653- self . run_func ( start, & [ ] , None , None ) ?;
651+ self . run_func ( start, & [ ] , false , None ) ?;
654652 }
655653 Ok ( ( ) )
656654 }
@@ -1092,7 +1090,7 @@ impl Instance {
10921090 & mut self ,
10931091 func : FunctionHandle ,
10941092 args : & [ Val ] ,
1095- async_context : Option < AsyncContext > ,
1093+ async_context : bool ,
10961094 inst_count_bound : Option < u64 > ,
10971095 ) -> Result < InternalRunResult , Error > {
10981096 let needs_start = self . state . is_not_started ( ) && !func. is_start_func ;
@@ -1193,10 +1191,7 @@ impl Instance {
11931191 /// This must only be called for an instance in a ready, non-fatally faulted, or yielded state,
11941192 /// or in the not-started state on the start function. The public wrappers around this function
11951193 /// should make sure the state is appropriate.
1196- fn swap_and_return < ' a > (
1197- & mut self ,
1198- async_context : Option < AsyncContext > ,
1199- ) -> Result < InternalRunResult , Error > {
1194+ fn swap_and_return ( & mut self , async_context : bool ) -> Result < InternalRunResult , Error > {
12001195 let is_start_func = self
12011196 . entrypoint
12021197 . expect ( "we always have an entrypoint by now" )
@@ -1208,10 +1203,7 @@ impl Instance {
12081203 || self . state. is_yielded( )
12091204 || self . state. is_bound_expired( )
12101205 ) ;
1211-
1212- self . state = State :: Running {
1213- async_context : async_context. map ( |cx| Arc :: new ( cx) ) ,
1214- } ;
1206+ self . state = State :: Running { async_context } ;
12151207
12161208 let res = self . with_current_instance ( |i| {
12171209 i. with_signals_on ( |i| {
0 commit comments