5353use crate :: component:: func:: { self , Func } ;
5454use crate :: component:: { HasData , HasSelf , Instance , Resource , ResourceTable , ResourceTableError } ;
5555use crate :: fiber:: { self , StoreFiber , StoreFiberYield } ;
56+ use crate :: rr:: { RRWasmFuncType , component_hooks} ;
5657use crate :: store:: { Store , StoreId , StoreInner , StoreOpaque , StoreToken } ;
5758use crate :: vm:: component:: { CallContext , ComponentInstance , InstanceFlags , ResourceTables } ;
5859use crate :: vm:: { AlwaysMut , SendSyncPtr , VMFuncRef , VMMemoryDefinition , VMStore } ;
@@ -1715,7 +1716,8 @@ impl Instance {
17151716 ///
17161717 /// SAFETY: The raw pointer arguments must be valid references to guest
17171718 /// functions (with the appropriate signatures) when the closures queued by
1718- /// this function are called.
1719+ /// this function are called. For RR, the rr_handle must be a valid `Func`
1720+ /// corresponding to `callee` if provided
17191721 unsafe fn queue_call < T : ' static > (
17201722 self ,
17211723 mut store : StoreContextMut < T > ,
@@ -1727,6 +1729,7 @@ impl Instance {
17271729 async_ : bool ,
17281730 callback : Option < SendSyncPtr < VMFuncRef > > ,
17291731 post_return : Option < SendSyncPtr < VMFuncRef > > ,
1732+ rr_handle : Option < Func > ,
17301733 ) -> Result < ( ) > {
17311734 /// Return a closure which will call the specified function in the scope
17321735 /// of the specified task.
@@ -1741,14 +1744,16 @@ impl Instance {
17411744 /// nothing.
17421745 ///
17431746 /// SAFETY: `callee` must be a valid `*mut VMFuncRef` at the time when
1744- /// the returned closure is called.
1747+ /// the returned closure is called. For RR, the handle must be a valid `Func`
1748+ /// corresponding to `callee` if provided
17451749 unsafe fn make_call < T : ' static > (
17461750 store : StoreContextMut < T > ,
17471751 guest_thread : QualifiedThreadId ,
17481752 callee : SendSyncPtr < VMFuncRef > ,
17491753 param_count : usize ,
17501754 result_count : usize ,
17511755 flags : Option < InstanceFlags > ,
1756+ rr_handle : Option < Func > ,
17521757 ) -> impl FnOnce ( & mut dyn VMStore ) -> Result < [ MaybeUninit < ValRaw > ; MAX_FLAT_PARAMS ] >
17531758 + Send
17541759 + Sync
@@ -1766,6 +1771,14 @@ impl Instance {
17661771 let may_enter_after_call = task. call_post_return_automatically ( ) ;
17671772 let lower = task. lower_params . take ( ) . unwrap ( ) ;
17681773
1774+ if let Some ( func) = rr_handle {
1775+ component_hooks:: record_wasm_func_begin (
1776+ func. instance ( ) . id ( ) . instance ( ) ,
1777+ func. index ( ) ,
1778+ store. store_opaque_mut ( ) ,
1779+ ) ?;
1780+ }
1781+
17691782 lower ( store, & mut storage[ ..param_count] ) ?;
17701783
17711784 let mut store = token. as_context_mut ( store) ;
@@ -1776,15 +1789,31 @@ impl Instance {
17761789 if let Some ( mut flags) = flags {
17771790 flags. set_may_enter ( false ) ;
17781791 }
1779- crate :: Func :: call_unchecked_raw (
1792+
1793+ let rr_type = if let Some ( func) = rr_handle {
1794+ let type_idx = func. abi_info ( store. 0 ) . 2 ;
1795+ let types = func
1796+ . instance ( )
1797+ . id ( )
1798+ . get ( store. 0 )
1799+ . component ( )
1800+ . types ( )
1801+ . clone ( ) ;
1802+ RRWasmFuncType :: Component { type_idx, types }
1803+ } else {
1804+ RRWasmFuncType :: None
1805+ } ;
1806+ crate :: Func :: call_unchecked_raw_with_rr (
17801807 & mut store,
17811808 callee. as_non_null ( ) ,
17821809 NonNull :: new (
17831810 & mut storage[ ..param_count. max ( result_count) ]
17841811 as * mut [ MaybeUninit < ValRaw > ] as _ ,
17851812 )
17861813 . unwrap ( ) ,
1814+ rr_type,
17871815 ) ?;
1816+
17881817 if let Some ( mut flags) = flags {
17891818 flags. set_may_enter ( may_enter_after_call) ;
17901819 }
@@ -1805,6 +1834,7 @@ impl Instance {
18051834 param_count,
18061835 result_count,
18071836 flags,
1837+ rr_handle,
18081838 )
18091839 } ;
18101840
@@ -2330,6 +2360,7 @@ impl Instance {
23302360 ( flags & START_FLAG_ASYNC_CALLEE ) != 0 ,
23312361 NonNull :: new ( callback) . map ( SendSyncPtr :: new) ,
23322362 NonNull :: new ( post_return) . map ( SendSyncPtr :: new) ,
2363+ None ,
23332364 ) ?;
23342365 }
23352366
@@ -5047,6 +5078,7 @@ fn queue_call0<T: 'static>(
50475078 is_concurrent,
50485079 callback,
50495080 post_return. map ( SendSyncPtr :: new) ,
5081+ Some ( handle) ,
50505082 )
50515083 }
50525084}
0 commit comments