diff --git a/crates/sel4-backtrace/embedded-debug-info/cli/src/bin/sel4-embed-debug-info.rs b/crates/sel4-backtrace/embedded-debug-info/cli/src/bin/sel4-embed-debug-info.rs index b3fbddb39..ed974db82 100644 --- a/crates/sel4-backtrace/embedded-debug-info/cli/src/bin/sel4-embed-debug-info.rs +++ b/crates/sel4-backtrace/embedded-debug-info/cli/src/bin/sel4-embed-debug-info.rs @@ -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> { @@ -72,6 +72,7 @@ fn with_bit_width>( align_residue: T::Word::zero(), content, memsz: content_len, + p_flags: PF_R, patches: vec![( "embedded_debug_info_start".to_owned(), SymbolicValue { diff --git a/crates/sel4-capdl-initializer/add-spec/src/render_elf.rs b/crates/sel4-capdl-initializer/add-spec/src/render_elf.rs index ceca0c75c..5de3b740f 100644 --- a/crates/sel4-capdl-initializer/add-spec/src/render_elf.rs +++ b/crates/sel4-capdl-initializer/add-spec/src/render_elf.rs @@ -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], @@ -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(), diff --git a/crates/sel4-kernel-loader/add-payload/src/render_elf.rs b/crates/sel4-kernel-loader/add-payload/src/render_elf.rs index d3184bed3..d5a3fa3b3 100644 --- a/crates/sel4-kernel-loader/add-payload/src/render_elf.rs +++ b/crates/sel4-kernel-loader/add-payload/src/render_elf.rs @@ -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(orig_elf: &[u8], serialized_payload: &[u8]) -> Vec where @@ -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 { diff --git a/crates/sel4-render-elf-with-data/src/lib.rs b/crates/sel4-render-elf-with-data/src/lib.rs index 9f74336e2..138e6baa2 100644 --- a/crates/sel4-render-elf-with-data/src/lib.rs +++ b/crates/sel4-render-elf-with-data/src/lib.rs @@ -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)] @@ -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)>, } @@ -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() @@ -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)>, } @@ -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)> { self.patches.iter() } diff --git a/crates/sel4-render-elf-with-data/src/render.rs b/crates/sel4-render-elf-with-data/src/render.rs index 3e6e14276..e6856073c 100644 --- a/crates/sel4-render-elf-with-data/src/render.rs +++ b/crates/sel4-render-elf-with-data/src/render.rs @@ -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}, @@ -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(), diff --git a/crates/sel4-reset/cli/src/main.rs b/crates/sel4-reset/cli/src/main.rs index 58dfe82d7..f3c4c08ca 100644 --- a/crates/sel4-reset/cli/src/main.rs +++ b/crates/sel4-reset/cli/src/main.rs @@ -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}; @@ -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 {