Initialize sp value for each threads (temporary workaround)

This commit is contained in:
Quentin Legot
2023-04-02 19:55:06 +02:00
parent 8239079130
commit 8c844c3e5c
3 changed files with 13 additions and 12 deletions

View File

@ -308,16 +308,18 @@ pub enum LoaderError {
impl Loader {
pub fn new(path: &str, machine: &mut Machine, start_index: usize) -> Result<Self, LoaderError> {
pub fn new(path: &str, machine: &mut Machine, start_index: usize) -> Result<(Self, u64), LoaderError> {
let loader = Self::load_and_parse(path)?;
loader.load_into_machine(machine, start_index)?;
Ok(loader)
let end_alloc = loader.load_into_machine(machine, start_index)?;
Ok((loader, end_alloc))
}
fn load_into_machine(&self, machine: &mut Machine, start_index: usize) -> Result<u64, LoaderError>{
fn load_into_machine(&self, machine: &mut Machine, start_index: usize) -> Result<u64, LoaderError> {
let mut end_index = 0;
for i in 0..self.sections.len() {
let section = &self.sections[i];
if section.does_flag_contains_key(FlagValue::ShfAlloc) {
end_index = section.virt_addr + section.section_size;
// Can allocate to machine memory
for j in (0..section.section_size as usize).step_by(4) {
let mut buf: [u8; 4] = [0; 4];
@ -328,8 +330,7 @@ impl Loader {
}
}
}
let last = self.sections.last().ok_or(LoaderError::ParsingError)?;
Ok(start_index as u64 + last.virt_addr + last.section_size)
Ok(start_index as u64 + end_index)
}
fn load_and_parse(path: &str) -> Result<Self, LoaderError> {