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.
This commit is contained in:
@@ -9,6 +9,9 @@ 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};
|
||||
|
||||
@@ -23,7 +26,8 @@ fuzz_target!(|data: &[u8]| {
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
let mut compiler = Compiler::new(isa);
|
||||
let mut resolver = NullResolver {};
|
||||
let _compiled = match CompiledModule::new(&mut compiler, data, &mut resolver) {
|
||||
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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user