Fix an error when calculating elf memory usage

VMLayout was mistakenly used to calculate the memory usage. This
commit is to fix this and seperate VMLayout "add" and "extend"
methods.
This commit is contained in:
Hui, Chunyang 2021-07-21 07:12:54 +00:00 committed by Zongmin.Gu
parent f9bafa23a4
commit 3612442adc
2 changed files with 17 additions and 2 deletions

@ -101,7 +101,7 @@ impl<'a, 'b> ProcessVMBuilder<'a, 'b> {
let process_layout = elf_layouts.iter().chain(other_layouts.iter()).fold( let process_layout = elf_layouts.iter().chain(other_layouts.iter()).fold(
VMLayout::new_empty(), VMLayout::new_empty(),
|mut process_layout, sub_layout| { |mut process_layout, sub_layout| {
process_layout.extend(&sub_layout); process_layout.add(&sub_layout);
process_layout process_layout
}, },
); );

@ -21,7 +21,8 @@ impl VMLayout {
} }
} }
pub fn extend(&mut self, more_space: &VMLayout) -> &mut Self { // This is used to add "more_space" to VM layout
pub fn add(&mut self, more_space: &VMLayout) -> &mut Self {
if more_space.size == 0 { if more_space.size == 0 {
return self; return self;
} }
@ -31,6 +32,20 @@ impl VMLayout {
self self
} }
// This is used to get the bigger and aligned VM layout
pub fn extend(&mut self, new_space: &VMLayout) -> &mut Self {
if new_space.size == 0 {
return self;
}
self.align = max(self.align, new_space.align);
self.size = {
let size = max(self.size, new_space.size);
align_up(size, self.align)
};
self
}
pub fn size(&self) -> usize { pub fn size(&self) -> usize {
self.size self.size
} }