MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / wasmtime_func_call

Function wasmtime_func_call

crates/c-api/src/func.rs:347–392  ·  view source on GitHub ↗
(
    mut store: WasmtimeStoreContextMut<'_>,
    func: &Func,
    args: *const wasmtime_val_t,
    nargs: usize,
    results: *mut MaybeUninit<wasmtime_val_t>,
    nresults: usize,
    trap_ret: &mut

Source from the content-addressed store, hash-verified

345
346#[unsafe(no_mangle)]
347pub unsafe extern "C" fn wasmtime_func_call(
348 mut store: WasmtimeStoreContextMut<'_>,
349 func: &Func,
350 args: *const wasmtime_val_t,
351 nargs: usize,
352 results: *mut MaybeUninit<wasmtime_val_t>,
353 nresults: usize,
354 trap_ret: &mut *mut wasm_trap_t,
355) -> Option<Box<wasmtime_error_t>> {
356 #[cfg(feature = "gc")]
357 let mut store = RootScope::new(&mut store);
358 let mut params = mem::take(&mut store.as_context_mut().data_mut().wasm_val_storage);
359
360 let (wt_params, wt_results) = translate_args(
361 &mut params,
362 crate::slice_from_raw_parts(args, nargs)
363 .iter()
364 .map(|i| i.to_val(&mut store)),
365 nresults,
366 );
367
368 // We're calling arbitrary code here most of the time, and we in general
369 // want to try to insulate callers against bugs in wasmtime/wasi/etc if we
370 // can. As a result we catch panics here and transform them to traps to
371 // allow the caller to have any insulation possible against Rust panics.
372 let result = panic::catch_unwind(AssertUnwindSafe(|| {
373 func.call(&mut store, wt_params, wt_results)
374 }));
375 match result {
376 Ok(Ok(())) => {
377 let results = crate::slice_from_raw_parts_mut(results, nresults);
378 for (slot, val) in results.iter_mut().zip(wt_results.iter()) {
379 crate::initialize(slot, wasmtime_val_t::from_val(&mut store, *val));
380 }
381 params.truncate(0);
382 store.as_context_mut().data_mut().wasm_val_storage = params;
383 None
384 }
385 Ok(Err(trap)) => store_err(trap, trap_ret),
386 Err(panic) => {
387 let err = error_from_panic(panic);
388 *trap_ret = Box::into_raw(Box::new(wasm_trap_t::new(err)));
389 None
390 }
391 }
392}
393
394#[unsafe(no_mangle)]
395pub unsafe extern "C" fn wasmtime_func_call_unchecked(

Callers 15

mainFunction · 0.85
mainFunction · 0.85
deserializeFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
check_callFunction · 0.85
check_okFunction · 0.85
check_trapFunction · 0.85
check_callFunction · 0.85
check_okFunction · 0.85
check_trapFunction · 0.85

Calls 15

translate_argsFunction · 0.85
slice_from_raw_partsFunction · 0.85
slice_from_raw_parts_mutFunction · 0.85
store_errFunction · 0.85
error_from_panicFunction · 0.85
to_valMethod · 0.80
initializeFunction · 0.70
newFunction · 0.50
data_mutMethod · 0.45
as_context_mutMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected