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 795424820..ceca0c75c 100644 --- a/crates/sel4-capdl-initializer/add-spec/src/render_elf.rs +++ b/crates/sel4-capdl-initializer/add-spec/src/render_elf.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: BSD-2-Clause // -use num::{NumCast, One, Zero}; +use num::{NumCast, One, PrimInt, Zero}; use sel4_render_elf_with_data::{FileHeaderExt, Input, SymbolicInjection, SymbolicValue}; @@ -16,7 +16,7 @@ pub(crate) struct RenderElfArgs<'a> { } impl<'a> RenderElfArgs<'a> { - pub(crate) fn call_with(&self) -> Vec { + pub(crate) fn call_with>(&self) -> Vec { let data_len: T::Word = NumCast::from(self.data.len()).unwrap(); let heap_size: T::Word = NumCast::from(self.heap_size).unwrap(); let align_modulus = T::Word::one() << self.granule_size_bits; diff --git a/crates/sel4-kernel-loader/add-payload/src/main.rs b/crates/sel4-kernel-loader/add-payload/src/main.rs index a2f44f48a..3cdea1c9c 100644 --- a/crates/sel4-kernel-loader/add-payload/src/main.rs +++ b/crates/sel4-kernel-loader/add-payload/src/main.rs @@ -53,9 +53,12 @@ fn main() -> Result<()> { fn continue_with_word_size(args: &Args) -> Result<()> where - T: FileHeaderExt + FileHeader, - T::Word: PrimInt + WrappingSub + Integer + Serialize, - T::Sword: PrimInt, + T: FileHeaderExt + + FileHeader< + Word: PrimInt + WrappingSub + Integer + Serialize, + Sword: PrimInt, + Endian = Endianness, + >, { let loader_bytes = fs::read(&args.loader_path)?; 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 9c451327b..d3184bed3 100644 --- a/crates/sel4-kernel-loader/add-payload/src/render_elf.rs +++ b/crates/sel4-kernel-loader/add-payload/src/render_elf.rs @@ -4,13 +4,14 @@ // SPDX-License-Identifier: BSD-2-Clause // -use num::{NumCast, One, Zero}; +use num::{NumCast, One, PrimInt, Zero}; +use object::{read::elf::FileHeader, Endianness}; use sel4_render_elf_with_data::{FileHeaderExt, Input, SymbolicInjection, SymbolicValue}; pub fn render_elf(orig_elf: &[u8], serialized_payload: &[u8]) -> Vec where - T: FileHeaderExt, + T: FileHeaderExt + FileHeader, { let align_modulus = T::Word::one(); let align_residue = T::Word::one(); diff --git a/crates/sel4-kernel-loader/add-payload/src/serialize_payload.rs b/crates/sel4-kernel-loader/add-payload/src/serialize_payload.rs index 88fa0ffe8..a6c83a9b0 100644 --- a/crates/sel4-kernel-loader/add-payload/src/serialize_payload.rs +++ b/crates/sel4-kernel-loader/add-payload/src/serialize_payload.rs @@ -30,16 +30,14 @@ struct PlatformInfoForBuildSystem { devices: Ranges, } -pub fn serialize_payload( +pub fn serialize_payload< + T: FileHeader, +>( kernel_path: impl AsRef, app_path: impl AsRef, dtb_path: impl AsRef, platform_info_path: impl AsRef, -) -> Vec -where - T: FileHeader, - T::Word: PrimInt + WrappingSub + Integer + Serialize, -{ +) -> Vec { let platform_info: PlatformInfoForBuildSystem = serde_yaml::from_reader(fs::File::open(&platform_info_path).unwrap()).unwrap(); @@ -92,11 +90,7 @@ struct Builder { actual_content: Vec, } -impl Builder -where - T: FileHeader, - T::Word: PrimInt + WrappingSub + Integer, -{ +impl> Builder { fn new() -> Self { Self { regions: HeaplessVec::new(), @@ -191,12 +185,9 @@ where f(&elf) } -fn elf_virt_addr_range<'a, T, R>(elf: &ElfFile<'a, T, R>) -> Range -where - T: FileHeader, - T::Word: PrimInt, - R: ReadRef<'a>, -{ +fn elf_virt_addr_range<'a, T: FileHeader, R: ReadRef<'a>>( + elf: &ElfFile<'a, T, R>, +) -> Range { let endian = elf.endian(); let virt_min = elf .raw_segments() @@ -219,12 +210,9 @@ where virt_min..virt_max } -fn elf_phys_to_vaddr_offset<'a, T, R>(elf: &ElfFile<'a, T, R>) -> T::Word -where - T: FileHeader, - T::Word: PrimInt + WrappingSub, - R: ReadRef<'a>, -{ +fn elf_phys_to_vaddr_offset<'a, T: FileHeader, R: ReadRef<'a>>( + elf: &ElfFile<'a, T, R>, +) -> T::Word { let endian = elf.endian(); unified( elf.raw_segments() diff --git a/crates/sel4-render-elf-with-data/src/lib.rs b/crates/sel4-render-elf-with-data/src/lib.rs index ad0299ede..4fef089b9 100644 --- a/crates/sel4-render-elf-with-data/src/lib.rs +++ b/crates/sel4-render-elf-with-data/src/lib.rs @@ -33,46 +33,29 @@ impl ElfBitWidth { pub type ConcreteFileHeader32 = FileHeader32; pub type ConcreteFileHeader64 = FileHeader64; -// NOTE(rustc_wishlist) -// -// This is much simpler with #![feature(associated_type_bounds)]: -// ``` -// pub trait FileHeaderExt: -// FileHeader -// ``` -// pub trait FileHeaderExt: - FileHeader + FileHeader + FileHeader { - type ExtWord: PrimInt + Into; - type ExtSword: PrimInt + Into; - - fn checked_add_signed(x: Self::ExtWord, y: Self::ExtSword) -> Option; - fn write_word_bytes(endian: impl Endian, n: Self::ExtWord) -> Vec; + fn checked_add_signed(x: Self::Word, y: Self::Sword) -> Option; + fn write_word_bytes(endian: impl Endian, n: Self::Word) -> Vec; } impl FileHeaderExt for ConcreteFileHeader32 { - type ExtWord = u32; - type ExtSword = i32; - - fn checked_add_signed(x: Self::ExtWord, y: Self::ExtSword) -> Option { + fn checked_add_signed(x: Self::Word, y: Self::Sword) -> Option { x.checked_add_signed(y) } - fn write_word_bytes(endian: impl Endian, n: Self::ExtWord) -> Vec { + fn write_word_bytes(endian: impl Endian, n: Self::Word) -> Vec { endian.write_u32_bytes(n).to_vec() } } impl FileHeaderExt for ConcreteFileHeader64 { - type ExtWord = u64; - type ExtSword = i64; - - fn checked_add_signed(x: Self::ExtWord, y: Self::ExtSword) -> Option { + fn checked_add_signed(x: Self::Word, y: Self::Sword) -> Option { x.checked_add_signed(y) } - fn write_word_bytes(endian: impl Endian, n: Self::ExtWord) -> Vec { + fn write_word_bytes(endian: impl Endian, n: Self::Word) -> Vec { endian.write_u64_bytes(n).to_vec() } } @@ -101,31 +84,31 @@ impl<'a, T: FileHeaderExt> Default for Input<'a, T> { type Symbol = String; -type ConcreteValue = ::ExtWord; +type ConcreteValue = ::Word; pub struct SymbolicInjection<'a, T: FileHeaderExt> { - pub align_modulus: T::ExtWord, - pub align_residue: T::ExtWord, + pub align_modulus: T::Word, + pub align_residue: T::Word, pub content: &'a [u8], - pub memsz: T::ExtWord, + pub memsz: T::Word, pub patches: Vec<(Symbol, SymbolicValue)>, } #[derive(Debug)] pub struct SymbolicValue { - pub addend: T::ExtSword, + pub addend: T::Sword, } impl<'a, T: FileHeaderExt> SymbolicInjection<'a, T> { - fn filesz(&self) -> T::ExtWord { + fn filesz(&self) -> T::Word { NumCast::from(self.content.len()).unwrap() } - fn align_from(&self, addr: T::ExtWord) -> T::ExtWord { + fn align_from(&self, addr: T::Word) -> T::Word { align_from::(addr, self.align_modulus, self.align_residue) } - fn locate(&self, vaddr: T::ExtWord) -> Result> { + fn locate(&self, vaddr: T::Word) -> Result> { Ok(Injection { vaddr, content: self.content, @@ -145,22 +128,22 @@ impl<'a, T: FileHeaderExt> SymbolicInjection<'a, T> { } pub struct Injection<'a, T: FileHeaderExt> { - pub vaddr: T::ExtWord, + pub vaddr: T::Word, pub content: &'a [u8], - pub memsz: T::ExtWord, + pub memsz: T::Word, pub patches: Vec<(Symbol, ConcreteValue)>, } impl<'a, T: FileHeaderExt> Injection<'a, T> { - fn vaddr(&self) -> T::ExtWord { + fn vaddr(&self) -> T::Word { self.vaddr } - fn filesz(&self) -> T::ExtWord { + fn filesz(&self) -> T::Word { NumCast::from(self.content.len()).unwrap() } - fn memsz(&self) -> T::ExtWord { + fn memsz(&self) -> T::Word { self.memsz } @@ -173,10 +156,6 @@ impl<'a, T: FileHeaderExt> Injection<'a, T> { } } -fn align_from( - addr: T::ExtWord, - modulus: T::ExtWord, - residue: T::ExtWord, -) -> T::ExtWord { +fn align_from(addr: T::Word, modulus: T::Word, residue: T::Word) -> T::Word { addr + (modulus + residue - addr % modulus) % modulus } diff --git a/hacking/unstable-feature-monitoring/wishlist/src/lib.rs b/hacking/unstable-feature-monitoring/wishlist/src/lib.rs index 99c7b0121..4fdaa015c 100644 --- a/hacking/unstable-feature-monitoring/wishlist/src/lib.rs +++ b/hacking/unstable-feature-monitoring/wishlist/src/lib.rs @@ -21,9 +21,6 @@ // For sel4_microkit::Handler::Error = ! #![feature(associated_type_defaults)] -// Would greatly simplify sel4_render_elf_with_data::FileHeaderExt -#![feature(associated_type_bounds)] - // Would enable sel4_bounce_buffer_allocator::Basic without a global heap #![feature(allocator_api)] #![feature(btreemap_alloc)]