Skip to content

Commit

Permalink
ELF: mark memory areas with section name
Browse files Browse the repository at this point in the history
  • Loading branch information
xarantolus committed Dec 31, 2022
1 parent 2bdb7e6 commit 9da0a57
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/instructions/elf.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate elf_rs;
use elf_rs::*;
use std::str;
use std::{str, string::FromUtf8Error};
use wasm_bindgen::prelude::wasm_bindgen;

use crate::{
Expand All @@ -18,6 +18,12 @@ impl From<Error> for AxError {
}
}

impl From<FromUtf8Error> for AxError {
fn from(err: FromUtf8Error) -> Self {
AxError::from(format!("ELF: Invalid UTF-8 in section name: {}", err))
}
}

#[wasm_bindgen]
impl Axecutor {
pub fn from_binary(binary: &[u8]) -> Result<Axecutor, AxError> {
Expand All @@ -44,7 +50,11 @@ impl Axecutor {
if section.section_name() != b".text" && section.sh_type() == SectionType::SHT_PROGBITS
{
axecutor
.mem_init_area(section.addr(), section.content().to_vec())
.mem_init_area_named(
section.addr(),
section.content().to_vec(),
Some(String::from_utf8(section.section_name().to_vec())?),
)
.map_err(|err| {
AxError::from(format!(
"ELF: initializing {} section: {}",
Expand Down

0 comments on commit 9da0a57

Please sign in to comment.