add support for symbol maps

This commit is contained in:
Mark McCaskey
2019-03-26 16:41:40 -07:00
parent ad897b2076
commit 9c58bed344
9 changed files with 85 additions and 10 deletions

View File

@ -13,6 +13,7 @@ use crate::{
types::{FuncIndex, FuncSig, GlobalIndex, LocalOrImport, MemoryIndex, TableIndex, Value},
vm,
};
use hashbrown::HashMap;
use std::{mem, sync::Arc};
pub(crate) struct InstanceInner {
@ -39,12 +40,16 @@ impl Drop for InstanceInner {
pub struct Instance {
module: Arc<ModuleInner>,
inner: Box<InstanceInner>,
#[allow(dead_code)]
import_object: ImportObject,
}
impl Instance {
pub(crate) fn new(module: Arc<ModuleInner>, imports: &ImportObject) -> Result<Instance> {
pub(crate) fn new(
module: Arc<ModuleInner>,
imports: &ImportObject,
maybe_symbol_map: Option<HashMap<u32, String>>,
) -> Result<Instance> {
// We need the backing and import_backing to create a vm::Ctx, but we need
// a vm::Ctx to create a backing and an import_backing. The solution is to create an
// uninitialized vm::Ctx and then initialize it in-place.
@ -63,7 +68,12 @@ impl Instance {
// Initialize the vm::Ctx in-place after the backing
// has been boxed.
unsafe {
*inner.vmctx = vm::Ctx::new(&mut inner.backing, &mut inner.import_backing, &module)
*inner.vmctx = vm::Ctx::new(
&mut inner.backing,
&mut inner.import_backing,
&module,
maybe_symbol_map,
)
};
let instance = Instance {

View File

@ -100,8 +100,12 @@ impl Module {
/// # Ok(())
/// # }
/// ```
pub fn instantiate(&self, import_object: &ImportObject) -> error::Result<Instance> {
Instance::new(Arc::clone(&self.inner), import_object)
pub fn instantiate(
&self,
import_object: &ImportObject,
maybe_symbol_map: Option<HashMap<u32, String>>,
) -> error::Result<Instance> {
Instance::new(Arc::clone(&self.inner), import_object, maybe_symbol_map)
}
pub fn cache(&self) -> Result<Artifact, CacheError> {

View File

@ -5,6 +5,7 @@ use crate::{
structures::TypedIndex,
types::{LocalOrImport, MemoryIndex},
};
use hashbrown::HashMap;
use std::{ffi::c_void, mem, ptr};
/// The context of the currently running WebAssembly instance.
@ -24,6 +25,8 @@ pub struct Ctx {
pub data: *mut c_void,
pub data_finalizer: Option<extern "C" fn(data: *mut c_void)>,
pub maybe_symbol_map: Option<HashMap<u32, String>>,
}
/// The internal context of the currently running WebAssembly instance.
@ -67,6 +70,7 @@ impl Ctx {
local_backing: &mut LocalBacking,
import_backing: &mut ImportBacking,
module: &ModuleInner,
maybe_symbol_map: Option<HashMap<u32, String>>,
) -> Self {
Self {
internal: InternalCtx {
@ -89,6 +93,7 @@ impl Ctx {
data: ptr::null_mut(),
data_finalizer: None,
maybe_symbol_map,
}
}
@ -121,6 +126,7 @@ impl Ctx {
data,
data_finalizer: Some(data_finalizer),
maybe_symbol_map: None,
}
}