Don't create Static memories larger than the Tunables' static bound size.

This commit is contained in:
Dan Gohman
2018-12-24 21:57:43 -08:00
parent 57a1618742
commit f997cde2db

View File

@@ -54,24 +54,25 @@ 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 declared maximum is prepared to be used with
// threads and therefore be immovable, so make it static.
(
if maximum <= tunables.static_memory_bound {
// A heap with a declared maximum can be immovable, so make
// it static.
return (
MemoryStyle::Static {
bound: cmp::max(tunables.static_memory_bound, maximum),
bound: tunables.static_memory_bound,
},
tunables.static_memory_offset_guard_size,
)
} else {
// A heap without a declared maximum is likely to want to be small
// at least some of the time, so make it dynamic.
);
}
}
// Otherwise, make it dynamic.
(
MemoryStyle::Dynamic,
tunables.dynamic_memory_offset_guard_size,
)
}
}
}
/// A WebAssembly linear memory description along with our chosen style for
/// implementing it.