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:
@@ -1,12 +1,12 @@
|
||||
use anyhow::Result;
|
||||
use object::write::{Object, StandardSection, Symbol, SymbolSection};
|
||||
use object::{SymbolFlags, SymbolKind, SymbolScope};
|
||||
use wasmtime_environ::DataInitializer;
|
||||
use wasmtime_environ::MemoryInitializer;
|
||||
|
||||
/// Declares data segment symbol
|
||||
pub fn declare_data_segment(
|
||||
obj: &mut Object,
|
||||
_data_initaliazer: &DataInitializer,
|
||||
_memory_initializer: &MemoryInitializer,
|
||||
index: usize,
|
||||
) -> Result<()> {
|
||||
let name = format!("_memory_{}", index);
|
||||
@@ -26,12 +26,12 @@ pub fn declare_data_segment(
|
||||
/// Emit segment data and initialization location
|
||||
pub fn emit_data_segment(
|
||||
obj: &mut Object,
|
||||
data_initaliazer: &DataInitializer,
|
||||
memory_initializer: &MemoryInitializer,
|
||||
index: usize,
|
||||
) -> Result<()> {
|
||||
let name = format!("_memory_{}", index);
|
||||
let symbol_id = obj.symbol_id(name.as_bytes()).unwrap();
|
||||
let section_id = obj.section_id(StandardSection::Data);
|
||||
obj.add_symbol_data(symbol_id, section_id, data_initaliazer.data, 1);
|
||||
obj.add_symbol_data(symbol_id, section_id, &memory_initializer.data, 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use object::write::{Object, Relocation, StandardSection, Symbol, SymbolSection};
|
||||
use object::{RelocationEncoding, RelocationKind, SymbolFlags, SymbolKind, SymbolScope};
|
||||
use wasmtime_debug::DwarfSection;
|
||||
use wasmtime_environ::isa::TargetFrontendConfig;
|
||||
use wasmtime_environ::{CompiledFunctions, DataInitializer, Module};
|
||||
use wasmtime_environ::{CompiledFunctions, MemoryInitialization, Module};
|
||||
|
||||
fn emit_vmcontext_init(
|
||||
obj: &mut Object,
|
||||
@@ -54,24 +54,32 @@ pub fn emit_module(
|
||||
target_config: &TargetFrontendConfig,
|
||||
compilation: CompiledFunctions,
|
||||
dwarf_sections: Vec<DwarfSection>,
|
||||
data_initializers: &[DataInitializer],
|
||||
) -> Result<Object> {
|
||||
let mut builder = ObjectBuilder::new(target, module, &compilation);
|
||||
builder.set_dwarf_sections(dwarf_sections);
|
||||
let mut obj = builder.build()?;
|
||||
|
||||
// Append data, table and vmcontext_init code to the object file.
|
||||
|
||||
for (i, initializer) in data_initializers.iter().enumerate() {
|
||||
declare_data_segment(&mut obj, initializer, i)?;
|
||||
match &module.memory_initialization {
|
||||
MemoryInitialization::Segmented(initializers) => {
|
||||
for (i, initializer) in initializers.iter().enumerate() {
|
||||
declare_data_segment(&mut obj, initializer, i)?;
|
||||
}
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
|
||||
for i in 0..module.table_plans.len() {
|
||||
declare_table(&mut obj, i)?;
|
||||
}
|
||||
|
||||
for (i, initializer) in data_initializers.iter().enumerate() {
|
||||
emit_data_segment(&mut obj, initializer, i)?;
|
||||
match &module.memory_initialization {
|
||||
MemoryInitialization::Segmented(initializers) => {
|
||||
for (i, initializer) in initializers.iter().enumerate() {
|
||||
emit_data_segment(&mut obj, initializer, i)?;
|
||||
}
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
|
||||
for i in 0..module.table_plans.len() {
|
||||
|
||||
Reference in New Issue
Block a user