From 2aad3a1002e65bf6b0108cb302b056444d588bd7 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 8 Aug 2023 02:06:15 +0200 Subject: [PATCH] Reimplemented BMC --- hbvm/src/mem/bmc.rs | 28 ++++++---------------------- hbvm/src/mem/mod.rs | 4 ++-- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/hbvm/src/mem/bmc.rs b/hbvm/src/mem/bmc.rs index 35d282db..0d47566a 100644 --- a/hbvm/src/mem/bmc.rs +++ b/hbvm/src/mem/bmc.rs @@ -1,7 +1,7 @@ use { super::MemoryAccessReason, crate::{ - mem::{perm_check, HandlePageFault, Memory}, + mem::{HandlePageFault, Memory}, VmRunError, }, core::{mem::MaybeUninit, task::Poll}, @@ -68,7 +68,7 @@ impl BlockCopier { Some(n) => self.src = n, None => return Poll::Ready(Err(BlkCopyError::OutOfBounds)), }; - + match self.dst.checked_add(BUF_SIZE as u64) { Some(n) => self.dst = n, None => return Poll::Ready(Err(BlkCopyError::OutOfBounds)), @@ -113,32 +113,16 @@ unsafe fn act( ) -> Result<(), BlkCopyError> { // Load to buffer memory - .memory_access( - MemoryAccessReason::Load, - src, - buf, - count, - perm_check::readable, - |src, dst, count| core::ptr::copy(src, dst, count), - traph, - ) - .map_err(|addr| BlkCopyError::Access { + .load(src, buf, count, traph) + .map_err(|super::LoadError(addr)| BlkCopyError::Access { access_reason: MemoryAccessReason::Load, addr, })?; // Store from buffer memory - .memory_access( - MemoryAccessReason::Store, - dst, - buf, - count, - perm_check::writable, - |dst, src, count| core::ptr::copy(src, dst, count), - traph, - ) - .map_err(|addr| BlkCopyError::Access { + .store(dst, buf, count, traph) + .map_err(|super::StoreError(addr)| BlkCopyError::Access { access_reason: MemoryAccessReason::Store, addr, })?; diff --git a/hbvm/src/mem/mod.rs b/hbvm/src/mem/mod.rs index f2d9ac71..38b99012 100644 --- a/hbvm/src/mem/mod.rs +++ b/hbvm/src/mem/mod.rs @@ -426,12 +426,12 @@ impl PageSize { /// Unhandled load access trap #[derive(Clone, Copy, Display, Debug, PartialEq, Eq)] #[display(fmt = "Load access error at address {_0:#x}")] -pub struct LoadError(u64); +pub struct LoadError(pub u64); /// Unhandled store access trap #[derive(Clone, Copy, Display, Debug, PartialEq, Eq)] #[display(fmt = "Store access error at address {_0:#x}")] -pub struct StoreError(u64); +pub struct StoreError(pub u64); /// There was no entry in page table to unmap ///