diff --git a/crates/wasmtime/src/config.rs b/crates/wasmtime/src/config.rs index 7afc00bbf5..5522e561ec 100644 --- a/crates/wasmtime/src/config.rs +++ b/crates/wasmtime/src/config.rs @@ -1368,7 +1368,7 @@ impl Config { /// for pooling allocation by using memory protection; see /// `PoolingAllocatorConfig::memory_protection_keys` for details. pub fn static_memory_maximum_size(&mut self, max_size: u64) -> &mut Self { - self.tunables.static_memory_reservation = Some(max_size); + self.tunables.static_memory_reservation = Some(round_up_to_pages(max_size)); self } diff --git a/tests/all/memory.rs b/tests/all/memory.rs index 6625cf9196..6bbd3c2ce9 100644 --- a/tests/all/memory.rs +++ b/tests/all/memory.rs @@ -658,3 +658,14 @@ fn init_with_negative_segment() -> Result<()> { Instance::new(&mut store, &module, &[])?; Ok(()) } + +#[test] +fn non_page_aligned_static_memory() -> Result<()> { + let mut config = Config::new(); + config.static_memory_maximum_size(100_000); + config.static_memory_forced(true); + let engine = Engine::new(&config)?; + let ty = MemoryType::new(1, None); + Memory::new(&mut Store::new(&engine, ()), ty)?; + Ok(()) +}