Replace the global-exports mechanism with a caller-vmctx mechanism. (#789)

* Replace the global-exports mechanism with a caller-vmctx mechanism.

This eliminates the global exports mechanism, and instead adds a
caller-vmctx argument to wasm functions so that WASI can obtain the
memory and other things from the caller rather than looking them up in a
global registry.

This replaces #390.

* Fixup some merge conflicts

* Rustfmt

* Ensure VMContext is aligned to 16 bytes

With the removal of `global_exports` it "just so happens" that this
isn't happening naturally any more.

* Fixup some bugs with double vmctx in wasmtime crate

* Trampoline stub needed adjusting
* Use pointer type instead of always using I64 for caller vmctx
* Don't store `ir::Signature` in `Func` since we don't know the pointer
  size at creation time.
* Skip the first 2 arguments in IR signatures since that's the two vmctx
  parameters.

* Update cranelift to 0.56.0

* Handle more merge conflicts

* Rustfmt

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
This commit is contained in:
Dan Gohman
2020-01-21 14:50:59 -08:00
committed by GitHub
parent de72435576
commit 9a88d3d894
33 changed files with 362 additions and 330 deletions

View File

@@ -3,9 +3,6 @@ use crate::{
instantiate, ActionError, ActionOutcome, CompilationStrategy, CompiledModule, Compiler,
InstanceHandle, Namespace, RuntimeValue, SetupError,
};
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use thiserror::Error;
use wasmparser::{validate, OperatorValidatorConfig, ValidatingParserConfig};
use wasmtime_environ::isa::TargetIsa;
@@ -61,7 +58,6 @@ impl Into<ValidatingParserConfig> for Features {
pub struct Context {
namespace: Namespace,
compiler: Box<Compiler>,
global_exports: Rc<RefCell<HashMap<String, Option<wasmtime_runtime::Export>>>>,
debug_info: bool,
features: Features,
}
@@ -72,7 +68,6 @@ impl Context {
Self {
namespace: Namespace::new(),
compiler,
global_exports: Rc::new(RefCell::new(HashMap::new())),
debug_info: false,
features: Default::default(),
}
@@ -119,7 +114,6 @@ impl Context {
&data,
None,
&mut self.namespace,
Rc::clone(&self.global_exports),
debug_info,
)
}
@@ -152,13 +146,7 @@ impl Context {
self.validate(&data).map_err(SetupError::Validate)?;
let debug_info = self.debug_info();
CompiledModule::new(
&mut *self.compiler,
data,
None,
Rc::clone(&self.global_exports),
debug_info,
)
CompiledModule::new(&mut *self.compiler, data, None, debug_info)
}
/// If `name` isn't None, register it for the given instance.
@@ -239,12 +227,4 @@ impl Context {
) -> Result<&'instance [u8], ActionError> {
inspect_memory(instance, field_name, start, len)
}
/// Return a handle to the global_exports mapping, needed by some modules
/// for instantiation.
pub fn get_global_exports(
&mut self,
) -> Rc<RefCell<HashMap<String, Option<wasmtime_runtime::Export>>>> {
Rc::clone(&self.global_exports)
}
}