Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions mythril/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand Down Expand Up @@ -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<Self> {
if !addr.is_frame_aligned() {
Expand Down Expand Up @@ -391,7 +391,7 @@ impl GuestAddressSpace {
addr: GuestVirtAddr,
access: GuestAccess,
) -> Result<FrameIter> {
//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,
Expand Down Expand Up @@ -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) {
Expand All @@ -574,15 +574,15 @@ impl<'a> Iterator for FrameIter<'a> {

#[repr(align(4096))]
pub struct EptTable<T> {
entries: [T; 512],
entries: [T; PAGE_SIZE_ENTRIES],
}
impl<T> Default for EptTable<T>
where
T: Copy + Default,
{
fn default() -> Self {
Self {
entries: [T::default(); 512],
entries: [T::default(); PAGE_SIZE_ENTRIES],
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions mythril/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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::<Raw4kPage>()).enumerate()
{
let frame_ptr =
Box::into_raw(Box::new(Raw4kPage::default())) as *mut u8;
let frame = HostPhysFrame::from_start_address(HostPhysAddr::new(
Expand All @@ -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::<Raw4kPage>() as u64),
),
frame,
false,
Expand Down Expand Up @@ -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::<Raw4kPage>() as u64,
),
false,
) {
Ok(_) | Err(Error::DuplicateMapping(_)) => continue,
Expand Down