Add paged_memory_initialization to Config.

This commit adds a `paged_memory_initialization` setting to `Config`.

The setting controls whether or not an attempt is made to organize data
segments into Wasm pages during compilation.

When used in conjunction with the `uffd` feature on Linux, Wasmtime can
completely skip initializing linear memories and instead initialize any pages
that are accessed for the first time during Wasm execution.
This commit is contained in:
Peter Huene
2021-08-25 20:05:48 -07:00
parent da5c82b786
commit e2b9b54301
3 changed files with 49 additions and 1 deletions

View File

@@ -32,6 +32,29 @@ fn initializes_linear_memory() -> Result<()> {
Ok(())
}
#[test]
fn initializes_linear_memory_paged() -> Result<()> {
let wat = r#"
(module
(memory (export "memory") 2)
(data (i32.const 0) "Hello World!")
)"#;
let mut config = Config::new();
config.paged_memory_initialization(true);
let module = Module::new(&Engine::new(&config)?, wat)?;
let mut store = Store::new(module.engine(), ());
let instance = Instance::new(&mut store, &module, &[])?;
let memory = instance.get_memory(&mut store, "memory").unwrap();
let mut bytes = [0; 12];
memory.read(&store, 0, &mut bytes)?;
assert_eq!(bytes, "Hello World!".as_bytes());
Ok(())
}
#[test]
fn linear_memory_limits() -> Result<()> {
// this test will allocate 4GB of virtual memory space, and may not work in