@@ -5,7 +5,7 @@ use core::ptr::{self, NonNull};
5
5
use core:: slice;
6
6
7
7
use crate :: environment:: Environment ;
8
- use crate :: error:: { Error , Result } ;
8
+ use crate :: error:: { Error , Result , Trap } ;
9
9
use crate :: function:: { CallContext , Function , NNM3Function , RawCall } ;
10
10
use crate :: runtime:: Runtime ;
11
11
use crate :: utils:: { cstr_to_str, eq_cstr_str} ;
@@ -123,7 +123,7 @@ impl<'rt> Module<'rt> {
123
123
where
124
124
Args : crate :: WasmArgs ,
125
125
Ret : crate :: WasmType ,
126
- F : for < ' cc > FnMut ( CallContext < ' cc > , Args ) -> Ret + ' static ,
126
+ F : for < ' cc > FnMut ( CallContext < ' cc > , Args ) -> core :: result :: Result < Ret , Trap > + ' static ,
127
127
{
128
128
let func = self . find_import_function ( module_name, function_name) ?;
129
129
Function :: < ' _ , Args , Ret > :: validate_sig ( func) ?;
@@ -234,7 +234,7 @@ impl<'rt> Module<'rt> {
234
234
where
235
235
Args : crate :: WasmArgs ,
236
236
Ret : crate :: WasmType ,
237
- F : for < ' cc > FnMut ( CallContext < ' cc > , Args ) -> Ret + ' static ,
237
+ F : for < ' cc > FnMut ( CallContext < ' cc > , Args ) -> core :: result :: Result < Ret , Trap > + ' static ,
238
238
{
239
239
unsafe extern "C" fn _impl < Args , Ret , F > (
240
240
runtime : ffi:: IM3Runtime ,
@@ -245,7 +245,7 @@ impl<'rt> Module<'rt> {
245
245
where
246
246
Args : crate :: WasmArgs ,
247
247
Ret : crate :: WasmType ,
248
- F : for < ' cc > FnMut ( CallContext < ' cc > , Args ) -> Ret + ' static ,
248
+ F : for < ' cc > FnMut ( CallContext < ' cc > , Args ) -> core :: result :: Result < Ret , Trap > + ' static ,
249
249
{
250
250
// use https://doc.rust-lang.org/std/primitive.pointer.html#method.offset_from once stable
251
251
let stack_base = ( * runtime) . stack as ffi:: m3stack_t ;
@@ -258,9 +258,14 @@ impl<'rt> Module<'rt> {
258
258
259
259
let args = Args :: pop_from_stack ( stack) ;
260
260
let context = CallContext :: from_rt ( NonNull :: new_unchecked ( runtime) ) ;
261
- let ret = ( & mut * closure. cast :: < F > ( ) ) ( context, args) ;
262
- ret. push_on_stack ( stack. cast ( ) ) ;
263
- ffi:: m3Err_none as _
261
+ let res = ( & mut * closure. cast :: < F > ( ) ) ( context, args) ;
262
+ match res {
263
+ Ok ( ret) => {
264
+ ret. push_on_stack ( stack. cast ( ) ) ;
265
+ ffi:: m3Err_none as _
266
+ }
267
+ Err ( err) => err. as_ptr ( ) as _ ,
268
+ }
264
269
}
265
270
266
271
let page = wasm3_priv:: AcquireCodePageWithCapacity ( self . rt . as_ptr ( ) , 3 ) ;
0 commit comments