* 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.
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use anyhow::Result;
|
|
use object::write::{Object, StandardSection, Symbol, SymbolSection};
|
|
use object::{SymbolFlags, SymbolKind, SymbolScope};
|
|
use wasmtime_environ::MemoryInitializer;
|
|
|
|
/// Declares data segment symbol
|
|
pub fn declare_data_segment(
|
|
obj: &mut Object,
|
|
_memory_initializer: &MemoryInitializer,
|
|
index: usize,
|
|
) -> Result<()> {
|
|
let name = format!("_memory_{}", index);
|
|
let _symbol_id = obj.add_symbol(Symbol {
|
|
name: name.as_bytes().to_vec(),
|
|
value: 0,
|
|
size: 0,
|
|
kind: SymbolKind::Data,
|
|
scope: SymbolScope::Linkage,
|
|
weak: false,
|
|
section: SymbolSection::Undefined,
|
|
flags: SymbolFlags::None,
|
|
});
|
|
Ok(())
|
|
}
|
|
|
|
/// Emit segment data and initialization location
|
|
pub fn emit_data_segment(
|
|
obj: &mut Object,
|
|
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, &memory_initializer.data, 1);
|
|
Ok(())
|
|
}
|