forked from AbleOS/holey-bytes
Comments
This commit is contained in:
parent
afdcee9bd6
commit
b955b756e3
|
@ -97,26 +97,33 @@ impl<'p, PfH: HandlePageFault> SoftPagedMem<'p, PfH> {
|
||||||
permission_check: fn(Permission) -> bool,
|
permission_check: fn(Permission) -> bool,
|
||||||
action: fn(*mut u8, *mut u8, usize),
|
action: fn(*mut u8, *mut u8, usize),
|
||||||
) -> Result<(), u64> {
|
) -> Result<(), u64> {
|
||||||
|
// Memory load from program section
|
||||||
let (src, len) = if src < self.program.len() as _ {
|
let (src, len) = if src < self.program.len() as _ {
|
||||||
|
// Allow only loads
|
||||||
if reason != MemoryAccessReason::Load {
|
if reason != MemoryAccessReason::Load {
|
||||||
return Err(src);
|
return Err(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine how much data to copy from here
|
||||||
let to_copy = len.clamp(0, self.program.len().saturating_sub(src as _));
|
let to_copy = len.clamp(0, self.program.len().saturating_sub(src as _));
|
||||||
|
|
||||||
|
// Perform action
|
||||||
action(
|
action(
|
||||||
unsafe { self.program.as_ptr().add(src as _).cast_mut() },
|
unsafe { self.program.as_ptr().add(src as _).cast_mut() },
|
||||||
dst,
|
dst,
|
||||||
to_copy,
|
to_copy,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Return shifted from what we've already copied
|
||||||
(
|
(
|
||||||
src.saturating_add(to_copy as _),
|
src.saturating_add(to_copy as _),
|
||||||
len.saturating_sub(to_copy),
|
len.saturating_sub(to_copy),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(src, len)
|
(src, len) // Nothing weird!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Nothing to copy? Don't bother doing anything, bail.
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue