Treat undeclared maximum as 4GiB (#944)

* Treat undeclared maximum as 4GiB

* Review fixes.
This commit is contained in:
Sergei Pepyakin
2020-02-18 15:33:57 +01:00
committed by GitHub
parent 372cc9fa7a
commit c94cdc7730

View File

@@ -2,6 +2,7 @@
use crate::module_environ::FunctionBodyData;
use crate::tunables::Tunables;
use crate::WASM_MAX_PAGES;
use cranelift_codegen::ir;
use cranelift_entity::{EntityRef, PrimaryMap};
use cranelift_wasm::{
@@ -55,10 +56,12 @@ pub enum MemoryStyle {
impl MemoryStyle {
/// Decide on an implementation style for the given `Memory`.
pub fn for_memory(memory: Memory, tunables: &Tunables) -> (Self, u64) {
if let Some(maximum) = memory.maximum {
// A heap with a maximum that doesn't exceed the static memory bound specified by the
// tunables make it static.
//
// If the module doesn't declare an explicit maximum treat it as 4GiB.
let maximum = memory.maximum.unwrap_or(WASM_MAX_PAGES);
if maximum <= tunables.static_memory_bound {
// A heap with a declared maximum can be immovable, so make
// it static.
assert_ge!(tunables.static_memory_bound, memory.minimum);
return (
Self::Static {
@@ -67,7 +70,6 @@ impl MemoryStyle {
tunables.static_memory_offset_guard_size,
);
}
}
// Otherwise, make it dynamic.
(Self::Dynamic, tunables.dynamic_memory_offset_guard_size)