From 948f519a045086cef2e1fae4fe707067710bbefc Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 29 Nov 2018 20:49:34 -0800 Subject: [PATCH] Make tests happy again --- src/webassembly/instance.rs | 14 +++++++++++--- src/webassembly/memory.rs | 10 +++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index c0bb07ba1..6381f80c9 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -463,9 +463,17 @@ impl Instance { // Get memories in module for memory in &module.info.memories { let memory = memory.entity; - let v = - LinearMemory::new(memory.pages_count as u32, memory.maximum.map(|m| m as u32)); - memories.push(v); + // If we use emscripten, we set a fixed initial and maximum + debug!("Instance - init memory ({}, {:?})", memory.pages_count, memory.maximum); + let memory = if options.use_emscripten { + // We use MAX_PAGES, so at the end the result is: + // (initial * LinearMemory::PAGE_SIZE) == LinearMemory::DEFAULT_HEAP_SIZE + LinearMemory::new(LinearMemory::MAX_PAGES as u32, None) + } + else { + LinearMemory::new(memory.pages_count as u32, memory.maximum.map(|m| m as u32)) + }; + memories.push(memory); } for init in &module.info.data_initializers { diff --git a/src/webassembly/memory.rs b/src/webassembly/memory.rs index e0a75b70a..394628fe8 100644 --- a/src/webassembly/memory.rs +++ b/src/webassembly/memory.rs @@ -60,8 +60,8 @@ impl LinearMemory { unsafe { mprotect( base, - // (initial * Self::PAGE_SIZE) as _, - Self::DEFAULT_HEAP_SIZE, + initial as usize * Self::PAGE_SIZE as usize, + // Self::DEFAULT_HEAP_SIZE, PROT_READ | PROT_WRITE, ) }, @@ -86,7 +86,7 @@ impl LinearMemory { /// Returns a number of allocated wasm pages. pub fn current_size(&self) -> usize { - (self.current * Self::PAGE_SIZE) as _ + self.current as usize * Self::PAGE_SIZE as usize } pub fn current_pages(&self) -> u32 { @@ -168,12 +168,12 @@ impl PartialEq for LinearMemory { impl Deref for LinearMemory { type Target = [u8]; fn deref(&self) -> &[u8] { - unsafe { slice::from_raw_parts(self.base as _, (self.current * Self::PAGE_SIZE) as _) } + unsafe { slice::from_raw_parts(self.base as _, self.current as usize * Self::PAGE_SIZE as usize) } } } impl DerefMut for LinearMemory { fn deref_mut(&mut self) -> &mut [u8] { - unsafe { slice::from_raw_parts_mut(self.base as _, (self.current * Self::PAGE_SIZE) as _) } + unsafe { slice::from_raw_parts_mut(self.base as _, self.current as usize * Self::PAGE_SIZE as usize) } } }