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

Function exception_ops

crates/fuzzing/src/oracles.rs:953–1018  ·  view source on GitHub ↗

Execute a series of exception-related operations.

(mut fuzz_config: generators::Config, mut ops: ExceptionOps)

Source from the content-addressed store, hash-verified

951
952/// Execute a series of exception-related operations.
953pub fn exception_ops(mut fuzz_config: generators::Config, mut ops: ExceptionOps) -> Result<()> {
954 match fuzz_config.wasmtime.compiler_strategy {
955 // Winch doesn't support exceptions; force to Cranelift.
956 CompilerStrategy::Winch => {
957 fuzz_config.wasmtime.compiler_strategy = CompilerStrategy::CraneliftNative;
958 }
959 CompilerStrategy::CraneliftNative | CompilerStrategy::CraneliftPulley => {}
960 }
961
962 let module_cfg = &mut fuzz_config.module_config.config;
963 // Force exceptions + GC on (exceptions require GC).
964 module_cfg.gc_enabled = true;
965 module_cfg.exceptions_enabled = true;
966 module_cfg.reference_types_enabled = true;
967
968 let expected = ops.expected_result();
969
970 let wasm = ops.to_wasm_binary();
971 log_wasm(&wasm);
972
973 let mut store = fuzz_config.to_store();
974
975 let module = compile_module(store.engine(), &wasm, KnownValid::No, &fuzz_config)
976 .ok_or_else(|| wasmtime::format_err!("Compilation failed"))?;
977 let mut linker = Linker::new(store.engine());
978
979 let check_ty = FuncType::new(store.engine(), [ValType::I32, ValType::I32], []);
980 let check_func = Func::new(&mut store, check_ty, |_caller, params, _results| {
981 let actual = params[0].unwrap_i32();
982 let expected = params[1].unwrap_i32();
983 assert_eq!(actual, expected, "check_i32 mismatch");
984 Ok(())
985 });
986 linker.define(&store, "", "check_i32", check_func).unwrap();
987
988 let instance = linker.instantiate(&mut store, &module).unwrap();
989 let run = instance.get_func(&mut store, "run").unwrap();
990
991 let mut results = [Val::I32(0)];
992 match run.call(&mut store, &[], &mut results) {
993 Ok(()) => {
994 let actual = results[0].unwrap_i32();
995 assert_eq!(
996 actual, expected,
997 "exception_ops: run returned {actual}, expected {expected} \
998 (one catch per scenario)"
999 );
1000 }
1001 Err(e) => {
1002 // AllocationTooLarge / GcHeapOutOfMemory are acceptable resource-limit traps.
1003 if let Some(trap) = e.downcast_ref::<Trap>() {
1004 match trap {
1005 Trap::AllocationTooLarge => return Ok(()),
1006 _ => {}
1007 }
1008 }
1009 if e.is::<GcHeapOutOfMemory<()>>() {
1010 return Ok(());

Callers

nothing calls this directly

Calls 14

log_wasmFunction · 0.85
compile_moduleFunction · 0.85
OkFunction · 0.85
expected_resultMethod · 0.80
to_storeMethod · 0.80
newFunction · 0.50
to_wasm_binaryMethod · 0.45
engineMethod · 0.45
unwrap_i32Method · 0.45
unwrapMethod · 0.45
defineMethod · 0.45
instantiateMethod · 0.45

Tested by

no test coverage detected