@@ -22,11 +22,11 @@ pub struct FuncRefs {
2222
2323 /// Pointers into `self.bump` for entries that need `wasm_call` field filled
2424 /// in.
25- with_holes : Vec < SendSyncPtr < VMFuncRef > > ,
25+ with_holes : TryVec < SendSyncPtr < VMFuncRef > > ,
2626
2727 /// General-purpose storage of "function things" that need to live as long
2828 /// as the entire store.
29- storage : Vec < Storage > ,
29+ storage : TryVec < Storage > ,
3030}
3131
3232/// Various items to place in `FuncRefs::storage`
@@ -90,17 +90,17 @@ impl FuncRefs {
9090 & mut self ,
9191 func_ref : VMFuncRef ,
9292 modules : & ModuleRegistry ,
93- ) -> NonNull < VMFuncRef > {
93+ ) -> Result < NonNull < VMFuncRef > , OutOfMemory > {
9494 debug_assert ! ( func_ref. wasm_call. is_none( ) ) ;
9595 let func_ref = self . bump . get_mut ( ) . alloc ( func_ref) ;
9696 // SAFETY: it's a contract of this function itself that `func_ref` has a
9797 // valid vmctx field to read.
9898 let has_hole = unsafe { !try_fill ( func_ref, modules) } ;
9999 let unpatched = SendSyncPtr :: from ( func_ref) ;
100100 if has_hole {
101- self . with_holes . push ( unpatched) ;
101+ self . with_holes . push ( unpatched) ? ;
102102 }
103- unpatched. as_non_null ( )
103+ Ok ( unpatched. as_non_null ( ) )
104104 }
105105
106106 /// Patch any `VMFuncRef::wasm_call`s that need filling in.
@@ -110,25 +110,31 @@ impl FuncRefs {
110110 }
111111
112112 /// Reserves `amt` space for extra items in "storage" for this store.
113- pub fn reserve_storage ( & mut self , amt : usize ) {
114- self . storage . reserve ( amt) ;
113+ pub fn reserve_storage ( & mut self , amt : usize ) -> Result < ( ) , OutOfMemory > {
114+ self . storage . reserve ( amt)
115115 }
116116
117117 /// Push pre-patched `VMFuncRef`s from an `InstancePre`.
118118 ///
119119 /// This is used to ensure that the store itself persists the entire list of
120120 /// `funcs` for the entire lifetime of the store.
121- pub fn push_instance_pre_func_refs ( & mut self , funcs : Arc < TryVec < VMFuncRef > > ) {
122- self . storage . push ( Storage :: InstancePreFuncRefs { funcs } ) ;
121+ pub fn push_instance_pre_func_refs (
122+ & mut self ,
123+ funcs : Arc < TryVec < VMFuncRef > > ,
124+ ) -> Result < ( ) , OutOfMemory > {
125+ self . storage . push ( Storage :: InstancePreFuncRefs { funcs } )
123126 }
124127
125128 /// Push linker definitions into storage, keeping them alive for the entire
126129 /// lifetime of the store.
127130 ///
128131 /// This is used to keep linker-defined functions' vmctx values alive, for
129132 /// example.
130- pub fn push_instance_pre_definitions ( & mut self , defs : Arc < TryVec < Definition > > ) {
131- self . storage . push ( Storage :: InstancePreDefinitions { defs } ) ;
133+ pub fn push_instance_pre_definitions (
134+ & mut self ,
135+ defs : Arc < TryVec < Definition > > ,
136+ ) -> Result < ( ) , OutOfMemory > {
137+ self . storage . push ( Storage :: InstancePreDefinitions { defs } )
132138 }
133139
134140 /// Pushes a shared host function into this store.
@@ -147,25 +153,25 @@ impl FuncRefs {
147153 & mut self ,
148154 func : Arc < HostFunc > ,
149155 modules : & ModuleRegistry ,
150- ) -> NonNull < VMFuncRef > {
156+ ) -> Result < NonNull < VMFuncRef > , OutOfMemory > {
151157 debug_assert ! ( func. func_ref( ) . wasm_call. is_none( ) ) ;
152158 // SAFETY: the vmctx field in the funcref of `HostFunc` is safe to read.
153- let ret = unsafe { self . push ( func. func_ref ( ) . clone ( ) , modules) } ;
154- self . storage . push ( Storage :: ArcHost { func } ) ;
155- ret
159+ let ret = unsafe { self . push ( func. func_ref ( ) . clone ( ) , modules) ? } ;
160+ self . storage . push ( Storage :: ArcHost { func } ) ? ;
161+ Ok ( ret)
156162 }
157163
158164 /// Same as `push_arc_host`, but for owned host functions.
159165 pub fn push_box_host (
160166 & mut self ,
161167 func : Box < HostFunc > ,
162168 modules : & ModuleRegistry ,
163- ) -> NonNull < VMFuncRef > {
169+ ) -> Result < NonNull < VMFuncRef > , OutOfMemory > {
164170 debug_assert ! ( func. func_ref( ) . wasm_call. is_none( ) ) ;
165171 // SAFETY: the vmctx field in the funcref of `HostFunc` is safe to read.
166- let ret = unsafe { self . push ( func. func_ref ( ) . clone ( ) , modules) } ;
167- self . storage . push ( Storage :: BoxHost { func } ) ;
168- ret
172+ let ret = unsafe { self . push ( func. func_ref ( ) . clone ( ) , modules) ? } ;
173+ self . storage . push ( Storage :: BoxHost { func } ) ? ;
174+ Ok ( ret)
169175 }
170176}
171177
0 commit comments