c
This commit is contained in:
parent
efdcd826ee
commit
1263941560
|
@ -59,34 +59,30 @@ impl Memory {
|
||||||
pub fn load<S: MemAccessSize>(&self, addr: u64) -> Option<Value> {
|
pub fn load<S: MemAccessSize>(&self, addr: u64) -> Option<Value> {
|
||||||
let lookup = self.page_lookup(addr)?;
|
let lookup = self.page_lookup(addr)?;
|
||||||
match lookup.perm {
|
match lookup.perm {
|
||||||
Permission::Empty | Permission::Node => None,
|
Permission::Empty | Permission::Node => return None,
|
||||||
Permission::Readonly | Permission::Write | Permission::Exec => {
|
Permission::Readonly | Permission::Write | Permission::Exec => (),
|
||||||
|
}
|
||||||
|
|
||||||
let mut value = MaybeUninit::<Value>::zeroed();
|
let mut value = MaybeUninit::<Value>::zeroed();
|
||||||
unsafe {
|
unsafe {
|
||||||
core::ptr::copy_nonoverlapping::<u8>(lookup.ptr, value.as_mut_ptr().cast(), 1);
|
core::ptr::copy_nonoverlapping::<u8>(lookup.ptr, value.as_mut_ptr().cast(), 1);
|
||||||
Some(value.assume_init())
|
Some(value.assume_init())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Store value to an address
|
/// Store value to an address
|
||||||
pub fn store<S: MemAccessSize>(&mut self, addr: u64, value: Value) -> Result<(), ()> {
|
pub fn store<S: MemAccessSize>(&mut self, addr: u64, value: Value) -> Result<(), ()> {
|
||||||
let lookup = self.page_lookup(addr).ok_or(())?;
|
let lookup = self.page_lookup(addr).ok_or(())?;
|
||||||
match lookup.perm {
|
if lookup.perm != Permission::Write {
|
||||||
Permission::Write => {
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
core::ptr::copy_nonoverlapping::<u8>(
|
core::ptr::copy_nonoverlapping::<u8>((&value as *const Value).cast(), lookup.ptr, 1)
|
||||||
(&value as *const Value).cast(),
|
|
||||||
lookup.ptr,
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn root_pt(&self) -> &PageTable {
|
pub fn root_pt(&self) -> &PageTable {
|
||||||
|
|
Loading…
Reference in a new issue