From b955b756e34d1710452db5b25e982c68f42d1149 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 9 Aug 2023 02:59:11 +0200 Subject: [PATCH] Comments --- hbvm/src/softpaging/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hbvm/src/softpaging/mod.rs b/hbvm/src/softpaging/mod.rs index bf35ff1..c33bc11 100644 --- a/hbvm/src/softpaging/mod.rs +++ b/hbvm/src/softpaging/mod.rs @@ -97,26 +97,33 @@ impl<'p, PfH: HandlePageFault> SoftPagedMem<'p, PfH> { permission_check: fn(Permission) -> bool, action: fn(*mut u8, *mut u8, usize), ) -> Result<(), u64> { + // Memory load from program section let (src, len) = if src < self.program.len() as _ { + // Allow only loads if reason != MemoryAccessReason::Load { return Err(src); } + // Determine how much data to copy from here let to_copy = len.clamp(0, self.program.len().saturating_sub(src as _)); + + // Perform action action( unsafe { self.program.as_ptr().add(src as _).cast_mut() }, dst, to_copy, ); + // Return shifted from what we've already copied ( src.saturating_add(to_copy as _), len.saturating_sub(to_copy), ) } else { - (src, len) + (src, len) // Nothing weird! }; + // Nothing to copy? Don't bother doing anything, bail. if len == 0 { return Ok(()); }