Fixed memory issues

This commit is contained in:
Syrus Akbary 2018-10-19 01:28:16 +02:00
parent 6fce21e4d5
commit 5c5fbd309d
2 changed files with 15 additions and 7 deletions

View File

@ -392,12 +392,20 @@ impl Instance {
// Instantiate memories
{
// Allocate the underlying memory and initialize it to all zeros.
memories.reserve_exact(module.info.memories.len());
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);
let total_memories = module.info.memories.len();
if total_memories > 0 {
memories.reserve_exact(total_memories);
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);
}
} else {
memories.reserve_exact(1);
memories.push(LinearMemory::new(0, None));
}
for init in &module.info.data_initializers {
debug_assert!(init.base.is_none(), "globalvar base not supported yet");

View File

@ -40,7 +40,7 @@ impl LinearMemory {
Some(val) => val as u64,
None => initial as u64,
};
let len = if len == 0 { 1 } else { len };
let len = if len == 0 { PAGE_SIZE as u64 } else { len };
let mmap = MmapMut::map_anon(len as usize).unwrap();
debug!("LinearMemory instantiated");