From 1263941560b999a145861caf88ee33058f99ff6c Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 11 Jun 2023 14:05:57 +0200 Subject: [PATCH] c --- hbvm/src/vm/mem/mod.rs | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/hbvm/src/vm/mem/mod.rs b/hbvm/src/vm/mem/mod.rs index 88e82ca..a10490d 100644 --- a/hbvm/src/vm/mem/mod.rs +++ b/hbvm/src/vm/mem/mod.rs @@ -59,33 +59,29 @@ impl Memory { pub fn load(&self, addr: u64) -> Option { let lookup = self.page_lookup(addr)?; match lookup.perm { - Permission::Empty | Permission::Node => None, - Permission::Readonly | Permission::Write | Permission::Exec => { - let mut value = MaybeUninit::::zeroed(); - unsafe { - core::ptr::copy_nonoverlapping::(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::::zeroed(); + unsafe { + core::ptr::copy_nonoverlapping::(lookup.ptr, value.as_mut_ptr().cast(), 1); + Some(value.assume_init()) } } /// Store value to an address pub fn store(&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::( - (&value as *const Value).cast(), - lookup.ptr, - 1, - ) - }; - Ok(()) - } - _ => Err(()), + if lookup.perm != Permission::Write { + return Err(()); } + + unsafe { + core::ptr::copy_nonoverlapping::((&value as *const Value).cast(), lookup.ptr, 1) + }; + + Ok(()) } #[inline]