uhh oohh i guess it works

This commit is contained in:
Erin 2023-06-11 14:47:49 +02:00 committed by ondra05
parent 1263941560
commit 86df8ddc64

View file

@ -64,8 +64,25 @@ impl Memory {
}
let mut value = MaybeUninit::<Value>::zeroed();
let overflow = (lookup.offset + S::BYTES).saturating_sub(lookup.size - 1);
let normal = S::BYTES - overflow;
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(), normal);
if overflow != 0 {
let lookup = self.page_lookup(lookup.ptr as u64 + lookup.size as u64)?;
match lookup.perm {
Permission::Empty | Permission::Node => return None,
Permission::Readonly | Permission::Write | Permission::Exec => (),
}
core::ptr::copy_nonoverlapping::<u8>(
lookup.ptr,
value.as_mut_ptr().cast::<u8>().add(normal),
overflow,
);
}
Some(value.assume_init())
}
}
@ -76,9 +93,27 @@ impl Memory {
if lookup.perm != Permission::Write {
return Err(());
}
let overflow = (lookup.offset + S::BYTES).saturating_sub(lookup.size - 1);
let normal = S::BYTES - overflow;
unsafe {
core::ptr::copy_nonoverlapping::<u8>((&value as *const Value).cast(), lookup.ptr, 1)
core::ptr::copy_nonoverlapping::<u8>(
(&value as *const Value).cast(),
lookup.ptr,
normal,
);
if overflow != 0 {
let lookup = self
.page_lookup(lookup.ptr as u64 + lookup.size as u64)
.ok_or(())?;
core::ptr::copy_nonoverlapping::<u8>(
(&value as *const Value).cast::<u8>().add(normal),
lookup.ptr,
overflow,
);
}
};
Ok(())