Skip to content

Commit

Permalink
crates/sel4-render-elf-with-data: Add p_flags field to SymbolicInjection
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Jul 9, 2024
1 parent 67a74c8 commit 6145def
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use num::{NumCast, One, PrimInt, Zero};

use sel4_render_elf_with_data::{
ConcreteFileHeader32, ConcreteFileHeader64, ElfBitWidth, FileHeaderExt, Input,
SymbolicInjection, SymbolicValue,
SymbolicInjection, SymbolicValue, PF_R,
};

fn main() -> Result<(), io::Error> {
Expand Down Expand Up @@ -72,6 +72,7 @@ fn with_bit_width<T: FileHeaderExt<Word: PrimInt, Sword: PrimInt>>(
align_residue: T::Word::zero(),
content,
memsz: content_len,
p_flags: PF_R,
patches: vec![(
"embedded_debug_info_start".to_owned(),
SymbolicValue {
Expand Down
5 changes: 4 additions & 1 deletion crates/sel4-capdl-initializer/add-spec/src/render_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use num::{NumCast, One, PrimInt, Zero};

use sel4_render_elf_with_data::{FileHeaderExt, Input, SymbolicInjection, SymbolicValue};
use sel4_render_elf_with_data::{
FileHeaderExt, Input, SymbolicInjection, SymbolicValue, PF_R, PF_W,
};

pub(crate) struct RenderElfArgs<'a> {
pub(crate) orig_elf: &'a [u8],
Expand All @@ -28,6 +30,7 @@ impl<'a> RenderElfArgs<'a> {
align_residue,
content: self.data,
memsz,
p_flags: PF_R | PF_W,
patches: vec![
(
"sel4_capdl_initializer_serialized_spec_start".to_owned(),
Expand Down
3 changes: 2 additions & 1 deletion crates/sel4-kernel-loader/add-payload/src/render_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use num::{NumCast, One, PrimInt, Zero};
use object::{read::elf::FileHeader, Endianness};

use sel4_render_elf_with_data::{FileHeaderExt, Input, SymbolicInjection, SymbolicValue};
use sel4_render_elf_with_data::{FileHeaderExt, Input, SymbolicInjection, SymbolicValue, PF_R};

pub fn render_elf<T>(orig_elf: &[u8], serialized_payload: &[u8]) -> Vec<u8>
where
Expand All @@ -22,6 +22,7 @@ where
align_residue,
content: serialized_payload,
memsz: NumCast::from(memsz).unwrap(),
p_flags: PF_R,
patches: vec![(
"loader_payload_start".to_owned(),
SymbolicValue {
Expand Down
9 changes: 9 additions & 0 deletions crates/sel4-render-elf-with-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use object::{
Endian, Endianness, File,
};

pub use object::elf::{PF_R, PF_W, PF_X};

mod render;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -89,6 +91,7 @@ pub struct SymbolicInjection<'a, T: FileHeaderExt> {
pub align_residue: T::Word,
pub content: &'a [u8],
pub memsz: T::Word,
pub p_flags: u32,
pub patches: Vec<(Symbol, SymbolicValue<T>)>,
}

Expand All @@ -111,6 +114,7 @@ impl<'a, T: FileHeaderExt> SymbolicInjection<'a, T> {
vaddr,
content: self.content,
memsz: self.memsz,
p_flags: self.p_flags,
patches: self
.patches
.iter()
Expand All @@ -129,6 +133,7 @@ pub struct Injection<'a, T: FileHeaderExt> {
pub vaddr: T::Word,
pub content: &'a [u8],
pub memsz: T::Word,
pub p_flags: u32,
pub patches: Vec<(Symbol, ConcreteValue<T>)>,
}

Expand All @@ -149,6 +154,10 @@ impl<'a, T: FileHeaderExt> Injection<'a, T> {
self.content
}

fn p_flags(&self) -> u32 {
self.p_flags
}

fn patches(&self) -> impl Iterator<Item = &(Symbol, ConcreteValue<T>)> {
self.patches.iter()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sel4-render-elf-with-data/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::mem;
use anyhow::{anyhow, ensure, Result};
use num::{CheckedAdd, NumCast, ToPrimitive};
use object::{
elf::{PF_R, PF_W, PT_LOAD},
elf::PT_LOAD,
read::elf::{ElfFile, FileHeader, ProgramHeader as _},
read::ReadRef,
write::elf::{ProgramHeader, Writer},
Expand Down Expand Up @@ -92,7 +92,7 @@ impl<'a, T: FileHeaderExt> Input<'a, T> {
let vaddr = injection.vaddr();
writer.write_program_header(&ProgramHeader {
p_type: PT_LOAD,
p_flags: PF_R | PF_W,
p_flags: injection.p_flags(),
p_offset: (*offset).try_into()?,
p_vaddr: vaddr.into(),
p_paddr: vaddr.into(),
Expand Down
3 changes: 2 additions & 1 deletion crates/sel4-reset/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::mem;

use anyhow::Result;
use num::{NumCast, Zero};
use object::elf::{PF_W, PT_LOAD};
use object::elf::{PF_R, PF_W, PT_LOAD};
use object::read::elf::{ElfFile, ProgramHeader};
use object::{Endian, File, Object, ObjectSection, ReadCache, ReadRef};

Expand Down Expand Up @@ -176,6 +176,7 @@ impl Regions {
align_residue,
content: &self.raw,
memsz: NumCast::from(memsz).unwrap(),
p_flags: PF_R,
patches: vec![(
"sel4_reset_regions_start".to_owned(),
SymbolicValue {
Expand Down

0 comments on commit 6145def

Please sign in to comment.