Code review feedback changes.
* Add `anyhow` dependency to `wasmtime-runtime`. * Revert `get_data` back to `fn`. * Remove `DataInitializer` and box the data in `Module` translation instead. * Improve comments on `MemoryInitialization`. * Remove `MemoryInitialization::OutOfBounds` in favor of proper bulk memory semantics. * Use segmented memory initialization except for when the uffd feature is enabled on Linux. * Validate modules with the allocator after translation. * Updated various functions in the runtime to return `anyhow::Result`. * Use a slice when copying pages instead of `ptr::copy_nonoverlapping`. * Remove unnecessary casts in `OnDemandAllocator::deallocate`. * Better document the `uffd` feature. * Use WebAssembly page-sized pages in the paged initialization. * Remove the stack pool from the uffd handler and simply protect just the guard pages.
This commit is contained in:
@@ -627,15 +627,12 @@ impl Config {
|
||||
#[cfg(not(feature = "async"))]
|
||||
let stack_size = 0;
|
||||
|
||||
Some(Arc::new(
|
||||
PoolingInstanceAllocator::new(
|
||||
strategy,
|
||||
module_limits,
|
||||
instance_limits,
|
||||
stack_size,
|
||||
)
|
||||
.map_err(|e| anyhow::anyhow!(e))?,
|
||||
))
|
||||
Some(Arc::new(PoolingInstanceAllocator::new(
|
||||
strategy,
|
||||
module_limits,
|
||||
instance_limits,
|
||||
stack_size,
|
||||
)?))
|
||||
}
|
||||
};
|
||||
Ok(self)
|
||||
|
||||
@@ -307,22 +307,36 @@ impl Module {
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn from_binary(engine: &Engine, binary: &[u8]) -> Result<Module> {
|
||||
// Check with the instance allocator to see if the given module is supported
|
||||
let allocator = engine.config().instance_allocator();
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "cache")] {
|
||||
let (main_module, artifacts, types) = ModuleCacheEntry::new(
|
||||
"wasmtime",
|
||||
engine.cache_config(),
|
||||
)
|
||||
.get_data((engine.compiler(), binary), |(compiler, binary)| {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(all(feature = "uffd", target_os = "linux"))] {
|
||||
let use_paged_mem_init = true;
|
||||
} else {
|
||||
let use_paged_mem_init = false;
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(feature = "cache")]
|
||||
let (main_module, artifacts, types) = ModuleCacheEntry::new(
|
||||
"wasmtime",
|
||||
engine.cache_config(),
|
||||
)
|
||||
.get_data((engine.compiler(), binary), |(compiler, binary)| {
|
||||
CompilationArtifacts::build(compiler, binary, |m| allocator.validate_module(m))
|
||||
})?;
|
||||
#[cfg(not(feature = "cache"))]
|
||||
let (main_module, artifacts, types) =
|
||||
CompilationArtifacts::build(engine.compiler(), binary, |m| {
|
||||
allocator.validate_module(m)
|
||||
})?;
|
||||
CompilationArtifacts::build(compiler, binary, use_paged_mem_init)
|
||||
})?;
|
||||
} else {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(all(feature = "uffd", target_os = "linux"))] {
|
||||
let use_paged_mem_init = true;
|
||||
} else {
|
||||
let use_paged_mem_init = false;
|
||||
}
|
||||
};
|
||||
|
||||
let (main_module, artifacts, types) =
|
||||
CompilationArtifacts::build(engine.compiler(), binary, use_paged_mem_init)?;
|
||||
}
|
||||
};
|
||||
|
||||
let mut modules = CompiledModule::from_artifacts_list(
|
||||
artifacts,
|
||||
@@ -331,6 +345,12 @@ impl Module {
|
||||
)?;
|
||||
let module = modules.remove(main_module);
|
||||
|
||||
// Validate the module can be used with the current allocator
|
||||
engine
|
||||
.config()
|
||||
.instance_allocator()
|
||||
.validate(module.module())?;
|
||||
|
||||
Ok(Module {
|
||||
inner: Arc::new(ModuleInner {
|
||||
engine: engine.clone(),
|
||||
|
||||
Reference in New Issue
Block a user