Files
wasmtime/fuzz/fuzz_targets/compile.rs
Dan Gohman 00a4e93bcd Add a concept of "global exports".
This adds a feature which allows one to look up an export by name
without knowing what module it's in -- `lookup_global_export` on an
`InstanceContents`.

The main expected use for this is to support APIs where module A
imports a function from module B, and module B needs to access module
A's memory. B can't import it from A in the normal way, because that
would create a dependency cycle. So for now, allow B to look up A's
exported memory dynamically with `lookup_global_export`.

In the future, with reference types and possibly host bindings, we'll be
able to pass references to memory as arguments, which will obviate the
need for this mechanism.
2019-01-22 16:32:07 -08:00

35 lines
1.0 KiB
Rust

#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
extern crate cranelift_codegen;
extern crate cranelift_native;
extern crate wasmparser;
extern crate wasmtime_environ;
extern crate wasmtime_jit;
use cranelift_codegen::settings;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use wasmparser::validate;
use wasmtime_jit::{CompiledModule, Compiler, NullResolver};
fuzz_target!(|data: &[u8]| {
if !validate(data, None) {
return;
}
let flag_builder = settings::builder();
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {
panic!("host machine is not a supported target");
});
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
let mut compiler = Compiler::new(isa);
let mut resolver = NullResolver {};
let mut global_exports = Rc::new(RefCell::new(HashMap::new()));
let _compiled = match CompiledModule::new(&mut compiler, data, &mut resolver, global_exports) {
Ok(x) => x,
Err(_) => return,
};
});