mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-12 21:38:39 +00:00
Use Page units for memory operations
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
use more_asserts::assert_ge;
|
||||
use std::cmp::min;
|
||||
use target_lexicon::{OperatingSystem, PointerWidth, Triple, HOST};
|
||||
use wasm_common::{MemoryType, TableType, WASM_MAX_PAGES};
|
||||
use wasm_common::{MemoryType, Pages, TableType};
|
||||
use wasmer_runtime::{MemoryPlan, MemoryStyle, TablePlan, TableStyle};
|
||||
|
||||
/// Tunable parameters for WebAssembly compilation.
|
||||
#[derive(Clone)]
|
||||
pub struct Tunables {
|
||||
/// For static heaps, the size in wasm pages of the heap protected by bounds checking.
|
||||
pub static_memory_bound: u32,
|
||||
pub static_memory_bound: Pages,
|
||||
|
||||
/// The size in bytes of the offset guard for static heaps.
|
||||
pub static_memory_offset_guard_size: u64,
|
||||
@@ -21,17 +21,17 @@ impl Tunables {
|
||||
/// Get the `Tunables` for a specific Target
|
||||
pub fn for_target(triple: &Triple) -> Self {
|
||||
let pointer_width: PointerWidth = triple.pointer_width().unwrap();
|
||||
let (mut static_memory_bound, mut static_memory_offset_guard_size): (u32, u64) =
|
||||
let (mut static_memory_bound, mut static_memory_offset_guard_size): (Pages, u64) =
|
||||
match pointer_width {
|
||||
PointerWidth::U16 => (0x400, 0x1000),
|
||||
PointerWidth::U32 => (0x4000, 0x1_0000),
|
||||
PointerWidth::U16 => (0x400.into(), 0x1000),
|
||||
PointerWidth::U32 => (0x4000.into(), 0x1_0000),
|
||||
// Static Memory Bound:
|
||||
// Allocating 4 GiB of address space let us avoid the
|
||||
// need for explicit bounds checks.
|
||||
// Static Memory Guard size:
|
||||
// Allocating 2 GiB of address space lets us translate wasm
|
||||
// offsets into x86 offsets as aggressively as we can.
|
||||
PointerWidth::U64 => (0x1_0000, 0x8000_0000),
|
||||
PointerWidth::U64 => (0x1_0000.into(), 0x8000_0000),
|
||||
};
|
||||
|
||||
// Allocate a small guard to optimize common cases but without
|
||||
@@ -42,7 +42,7 @@ impl Tunables {
|
||||
OperatingSystem::Windows => {
|
||||
// For now, use a smaller footprint on Windows so that we don't
|
||||
// don't outstrip the paging file.
|
||||
static_memory_bound = min(static_memory_bound, 0x100);
|
||||
static_memory_bound = min(static_memory_bound, 0x100.into());
|
||||
static_memory_offset_guard_size = min(static_memory_offset_guard_size, 0x10000);
|
||||
}
|
||||
_ => {}
|
||||
@@ -61,7 +61,7 @@ impl Tunables {
|
||||
// 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);
|
||||
let maximum = memory.maximum.unwrap_or(Pages::max_value());
|
||||
if maximum <= self.static_memory_bound {
|
||||
assert_ge!(self.static_memory_bound, memory.minimum);
|
||||
MemoryPlan {
|
||||
|
||||
Reference in New Issue
Block a user