loader now return better understanable errors, fix when compiler when to use bss section, add join exception, fix get_string_param, add support for thread in obbAddr, add a test
This commit is contained in:
@ -213,23 +213,23 @@ impl ElfHeader {
|
||||
}
|
||||
|
||||
impl TryFrom<&Vec<u8>> for ElfHeader {
|
||||
type Error = ();
|
||||
type Error = String;
|
||||
|
||||
fn try_from(instructions: &Vec<u8>) -> Result<Self, Self::Error> {
|
||||
if Self::is_elf(instructions) {
|
||||
let format = Self::is_32bits(instructions);
|
||||
let endianess = Self::check_endianess(instructions);
|
||||
let version = Self::get_version(instructions).ok_or(())?;
|
||||
let version = Self::get_version(instructions).ok_or("Cannot retrieve version")?;
|
||||
let is_sys_v_abi = Self::is_system_v_elf(instructions);
|
||||
let is_rv_target = Self::is_riscv_isa(instructions);
|
||||
let entrypoint = Self::get_entrypoint(instructions, format).ok_or(())?;
|
||||
let elf_header_size = Self::get_elf_header_size(instructions, format).ok_or(())?;
|
||||
let program_header_location = Self::get_program_header_table_location(instructions, format).ok_or(())?;
|
||||
let program_header_entries = Self::get_number_entries_program_header(instructions, format).ok_or(())? ;
|
||||
let program_header_size = Self::get_program_header_size(instructions, format).ok_or(())?;
|
||||
let section_header_location = Self::get_section_header_table_location(instructions, format).ok_or(())?;
|
||||
let section_header_entries = Self::get_section_header_num_entries(instructions, format).ok_or(())?;
|
||||
let section_header_size = Self::get_section_header_size(instructions, format).ok_or(())?;
|
||||
let entrypoint = Self::get_entrypoint(instructions, format).ok_or("Cannot get entrypoint")?;
|
||||
let elf_header_size = Self::get_elf_header_size(instructions, format).ok_or("Cannot get elf header size")?;
|
||||
let program_header_location = Self::get_program_header_table_location(instructions, format).ok_or("Cannot get program header table location")?;
|
||||
let program_header_entries = Self::get_number_entries_program_header(instructions, format).ok_or("Cannot get number of entries in program header table")? ;
|
||||
let program_header_size = Self::get_program_header_size(instructions, format).ok_or("Cannot get program header entry size")?;
|
||||
let section_header_location = Self::get_section_header_table_location(instructions, format).ok_or("Cannot get section header table location")?;
|
||||
let section_header_entries = Self::get_section_header_num_entries(instructions, format).ok_or("Cannot get number of entries of section header")?;
|
||||
let section_header_size = Self::get_section_header_size(instructions, format).ok_or("Cannot get size of section header entry")?;
|
||||
Ok(ElfHeader {
|
||||
endianess,
|
||||
is_32bits: format,
|
||||
@ -246,7 +246,7 @@ impl TryFrom<&Vec<u8>> for ElfHeader {
|
||||
section_header_size
|
||||
})
|
||||
} else {
|
||||
Err(())
|
||||
Err("File doesn't have elf magic number")?
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -409,7 +409,7 @@ pub enum LoaderError {
|
||||
/// Correspond to std IO error
|
||||
IOError(std::io::Error),
|
||||
/// Others errors
|
||||
ParsingError
|
||||
ParsingError(String)
|
||||
}
|
||||
|
||||
/// Global structure of the loader, one instance per loaded files
|
||||
@ -455,7 +455,13 @@ impl Loader {
|
||||
let mut buf: [u8; 4] = [0; 4];
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
for k in 0..buf.len() {
|
||||
buf[k] = self.bytes.get(section.image_offset as usize + j + k).copied().ok_or(LoaderError::ParsingError)?;
|
||||
if section.does_flag_contains_key(FlagValue::ShfWrite) {
|
||||
// flag WA, on doit allouer des données initialisés à 0
|
||||
// généralement, ce signifie que le compilateur à ajouter une section .bss
|
||||
buf[k] = 0;
|
||||
} else {
|
||||
buf[k] = self.bytes.get(section.image_offset as usize + j + k).copied().ok_or(LoaderError::ParsingError(format!("index 0x{:x} is out of bound because list have a size of 0x{:x} (image offset 0x{:x}, j 0x{:x}, k 0x{:x})", section.image_offset as usize + j + k, self.bytes.len(), section.image_offset, j, k)))?;
|
||||
}
|
||||
}
|
||||
machine.write_memory(4, start_index + section.virt_addr as usize + j, u32::from_le_bytes(buf) as u64);
|
||||
}
|
||||
@ -492,8 +498,8 @@ impl Loader {
|
||||
Ok(header) => {
|
||||
header
|
||||
},
|
||||
Err(_) => {
|
||||
return Err(LoaderError::ParsingError);
|
||||
Err(err) => {
|
||||
return Err(LoaderError::ParsingError(format!("Cannot parse elf header : {}", err)));
|
||||
}
|
||||
};
|
||||
let section_header = match Self::parse_section_header(&instructions, elf_header.is_32bits, elf_header.section_header_location, elf_header.section_header_entries, elf_header.section_header_size) {
|
||||
@ -501,7 +507,7 @@ impl Loader {
|
||||
header
|
||||
},
|
||||
Err(_) => {
|
||||
return Err(LoaderError::ParsingError);
|
||||
return Err(LoaderError::ParsingError("Cannot parse section header".to_string()));
|
||||
}
|
||||
};
|
||||
// #[cfg(debug_assertions)]
|
||||
|
Reference in New Issue
Block a user