changed sigs

This commit is contained in:
Erin 2023-06-22 11:43:32 +02:00 committed by ondra05
parent 60ca26dcd2
commit a08e0172c9
2 changed files with 23 additions and 4 deletions

View file

@ -3,6 +3,8 @@ mod paging;
use self::paging::{PageTable, Permission, PtEntry}; use self::paging::{PageTable, Permission, PtEntry};
use alloc::boxed::Box; use alloc::boxed::Box;
use super::trap::HandleTrap;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Memory { pub struct Memory {
root_pt: *mut PageTable, root_pt: *mut PageTable,
@ -52,7 +54,13 @@ impl Memory {
} }
/// Load value from an address /// Load value from an address
pub unsafe fn load(&self, addr: u64, target: *mut u8, count: usize) -> Result<(), ()> { pub unsafe fn load(
&self,
addr: u64,
target: *mut u8,
count: usize,
traph: &mut impl HandleTrap,
) -> Result<(), ()> {
self.memory_access( self.memory_access(
addr, addr,
target, target,
@ -64,17 +72,25 @@ impl Memory {
) )
}, },
|src, dst, count| core::ptr::copy_nonoverlapping(src, dst, count), |src, dst, count| core::ptr::copy_nonoverlapping(src, dst, count),
traph,
) )
} }
/// Store value to an address /// Store value to an address
pub unsafe fn store(&mut self, addr: u64, source: *const u8, count: usize) -> Result<(), ()> { pub unsafe fn store(
&mut self,
addr: u64,
source: *const u8,
count: usize,
traph: &mut impl HandleTrap,
) -> Result<(), ()> {
self.memory_access( self.memory_access(
addr, addr,
source.cast_mut(), source.cast_mut(),
count, count,
|perm| perm == Permission::Write, |perm| perm == Permission::Write,
|dst, src, count| core::ptr::copy_nonoverlapping(src, dst, count), |dst, src, count| core::ptr::copy_nonoverlapping(src, dst, count),
traph,
) )
} }
@ -125,8 +141,9 @@ impl Memory {
src: u64, src: u64,
mut dst: *mut u8, mut dst: *mut u8,
len: usize, len: usize,
permission_check: impl Fn(Permission) -> bool, permission_check: fn(Permission) -> bool,
action: impl Fn(*mut u8, *mut u8, usize), action: fn(*mut u8, *mut u8, usize),
traph: &mut impl HandleTrap,
) -> Result<(), ()> { ) -> Result<(), ()> {
for PageSplitResult { ptr, size, perm } in PageSplitter::new(src, len, self.root_pt) { for PageSplitResult { ptr, size, perm } in PageSplitter::new(src, len, self.root_pt) {
if !permission_check(perm) { if !permission_check(perm) {

View file

@ -208,6 +208,7 @@ impl<'a, T: HandleTrap> Vm<'a, T> {
self.read_reg(base).as_u64() + off + n as u64, self.read_reg(base).as_u64() + off + n as u64,
self.registers.as_mut_ptr().add(usize::from(dst) + n).cast(), self.registers.as_mut_ptr().add(usize::from(dst) + n).cast(),
usize::from(count).saturating_sub(n), usize::from(count).saturating_sub(n),
&mut self.traph,
) )
.is_err() .is_err()
{ {
@ -222,6 +223,7 @@ impl<'a, T: HandleTrap> Vm<'a, T> {
self.read_reg(base).as_u64() + off, self.read_reg(base).as_u64() + off,
self.registers.as_ptr().add(usize::from(dst)).cast(), self.registers.as_ptr().add(usize::from(dst)).cast(),
count.into(), count.into(),
&mut self.traph,
) )
.is_err() .is_err()
{ {