Treat undeclared maximum as 4GiB (#944)
* Treat undeclared maximum as 4GiB * Review fixes.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use crate::module_environ::FunctionBodyData;
|
use crate::module_environ::FunctionBodyData;
|
||||||
use crate::tunables::Tunables;
|
use crate::tunables::Tunables;
|
||||||
|
use crate::WASM_MAX_PAGES;
|
||||||
use cranelift_codegen::ir;
|
use cranelift_codegen::ir;
|
||||||
use cranelift_entity::{EntityRef, PrimaryMap};
|
use cranelift_entity::{EntityRef, PrimaryMap};
|
||||||
use cranelift_wasm::{
|
use cranelift_wasm::{
|
||||||
@@ -55,10 +56,12 @@ pub enum MemoryStyle {
|
|||||||
impl MemoryStyle {
|
impl MemoryStyle {
|
||||||
/// Decide on an implementation style for the given `Memory`.
|
/// Decide on an implementation style for the given `Memory`.
|
||||||
pub fn for_memory(memory: Memory, tunables: &Tunables) -> (Self, u64) {
|
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 {
|
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);
|
assert_ge!(tunables.static_memory_bound, memory.minimum);
|
||||||
return (
|
return (
|
||||||
Self::Static {
|
Self::Static {
|
||||||
@@ -67,7 +70,6 @@ impl MemoryStyle {
|
|||||||
tunables.static_memory_offset_guard_size,
|
tunables.static_memory_offset_guard_size,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, make it dynamic.
|
// Otherwise, make it dynamic.
|
||||||
(Self::Dynamic, tunables.dynamic_memory_offset_guard_size)
|
(Self::Dynamic, tunables.dynamic_memory_offset_guard_size)
|
||||||
|
|||||||
Reference in New Issue
Block a user