diff --git a/.gitignore b/.gitignore index cf0ef1c..468b6d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ /boot /target -mythril/target -mythril/src/blob/bios.bin mythril/.cargo +mythril/src/blob/bios.bin +mythril/target +mythril/vendor _boot.img **/*.rs.bk debug.log diff --git a/mythril/src/memory.rs b/mythril/src/memory.rs index ab68658..19d0022 100644 --- a/mythril/src/memory.rs +++ b/mythril/src/memory.rs @@ -14,10 +14,10 @@ use x86::bits64::paging::*; use x86::controlregs::Cr0; #[repr(align(4096))] -pub struct Raw4kPage(pub [u8; 4096]); +pub struct Raw4kPage(pub [u8; BASE_PAGE_SIZE]); impl Default for Raw4kPage { fn default() -> Self { - Raw4kPage([0u8; 4096]) + Raw4kPage([0u8; BASE_PAGE_SIZE]) } } @@ -221,7 +221,7 @@ impl fmt::Debug for HostPhysAddr { #[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Debug)] pub struct HostPhysFrame(HostPhysAddr); impl HostPhysFrame { - pub const SIZE: usize = 4096; + pub const SIZE: usize = BASE_PAGE_SIZE; pub fn from_start_address(addr: HostPhysAddr) -> Result { if !addr.is_frame_aligned() { @@ -391,7 +391,7 @@ impl GuestAddressSpace { addr: GuestVirtAddr, access: GuestAccess, ) -> Result { - //TODO: align the addr to 4096 boundary + //TODO: align the addr to BASE_PAGE_SIZE boundary Ok(FrameIter { view: GuestAddressSpaceView::new(cr3, self), addr: addr, @@ -561,7 +561,7 @@ impl<'a> Iterator for FrameIter<'a> { // This is the smallest possible guest page size, so permissions // can't change except at this granularity - self.addr = self.addr + 4096; + self.addr = self.addr + BASE_PAGE_SIZE; let physaddr = match self.view.translate_linear_address(old, self.access) { @@ -574,7 +574,7 @@ impl<'a> Iterator for FrameIter<'a> { #[repr(align(4096))] pub struct EptTable { - entries: [T; 512], + entries: [T; PAGE_SIZE_ENTRIES], } impl Default for EptTable where @@ -582,7 +582,7 @@ where { fn default() -> Self { Self { - entries: [T::default(); 512], + entries: [T::default(); PAGE_SIZE_ENTRIES], } } } diff --git a/mythril/src/vm.rs b/mythril/src/vm.rs index 51943b3..0e14968 100644 --- a/mythril/src/vm.rs +++ b/mythril/src/vm.rs @@ -19,6 +19,7 @@ use alloc::string::String; use alloc::sync::Arc; use alloc::vec::Vec; use arraydeque::ArrayDeque; +use core::mem; use spin::RwLock; static BIOS_BLOB: &'static [u8] = include_bytes!("blob/bios.bin"); @@ -345,7 +346,8 @@ impl VirtualMachine { addr: &GuestPhysAddr, space: &mut GuestAddressSpace, ) -> Result<()> { - for (i, chunk) in image.chunks(4096 as usize).enumerate() { + for (i, chunk) in image.chunks(mem::size_of::()).enumerate() + { let frame_ptr = Box::into_raw(Box::new(Raw4kPage::default())) as *mut u8; let frame = HostPhysFrame::from_start_address(HostPhysAddr::new( @@ -362,7 +364,8 @@ impl VirtualMachine { space.map_frame( memory::GuestPhysAddr::new( - addr.as_u64() + (i as u64 * 4096) as u64, + addr.as_u64() + + (i as u64 * mem::size_of::() as u64), ), frame, false, @@ -417,7 +420,9 @@ impl VirtualMachine { // Iterate over each page for i in 0..(config.memory << 8) { match guest_space.map_new_frame( - memory::GuestPhysAddr::new((i as u64 * 4096) as u64), + memory::GuestPhysAddr::new( + i as u64 * mem::size_of::() as u64, + ), false, ) { Ok(_) | Err(Error::DuplicateMapping(_)) => continue,