wip/its-not-my-fault
ondra05 2023-06-11 14:05:57 +02:00
parent adb8b63657
commit 46cba93a89
1 changed files with 16 additions and 20 deletions

View File

@ -59,33 +59,29 @@ impl Memory {
pub fn load<S: MemAccessSize>(&self, addr: u64) -> Option<Value> {
let lookup = self.page_lookup(addr)?;
match lookup.perm {
Permission::Empty | Permission::Node => None,
Permission::Readonly | Permission::Write | Permission::Exec => {
let mut value = MaybeUninit::<Value>::zeroed();
unsafe {
core::ptr::copy_nonoverlapping::<u8>(lookup.ptr, value.as_mut_ptr().cast(), 1);
Some(value.assume_init())
}
}
Permission::Empty | Permission::Node => return None,
Permission::Readonly | Permission::Write | Permission::Exec => (),
}
let mut value = MaybeUninit::<Value>::zeroed();
unsafe {
core::ptr::copy_nonoverlapping::<u8>(lookup.ptr, value.as_mut_ptr().cast(), 1);
Some(value.assume_init())
}
}
/// Store value to an address
pub fn store<S: MemAccessSize>(&mut self, addr: u64, value: Value) -> Result<(), ()> {
let lookup = self.page_lookup(addr).ok_or(())?;
match lookup.perm {
Permission::Write => {
unsafe {
core::ptr::copy_nonoverlapping::<u8>(
(&value as *const Value).cast(),
lookup.ptr,
1,
)
};
Ok(())
}
_ => Err(()),
if lookup.perm != Permission::Write {
return Err(());
}
unsafe {
core::ptr::copy_nonoverlapping::<u8>((&value as *const Value).cast(), lookup.ptr, 1)
};
Ok(())
}
#[inline]