kernel: riscv: fix memory reuse bug

Memory that was marked as reserved-but-not-in-use could get reallocated.
Practically speaking, this caused threads to share stack, which makes
things spooky.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-03-03 21:12:09 +08:00
parent 8f809c2a51
commit 93d295b93b

View file

@ -593,6 +593,12 @@ pub fn virt_to_phys(virt: usize) -> Result<usize, xous_kernel::Error> {
// Ensure the entry hasn't already been mapped.
if l0_pt.entries[vpn0] & MMUFlags::VALID.bits() == 0 {
// The memory has been reserved, but isn't pointing anywhere yet.
if l0_pt.entries[vpn0] != 0 {
return Err(xous_kernel::Error::MemoryInUse);
}
// The address hasn't been allocated
return Err(xous_kernel::Error::BadAddress);
}
Ok((l0_pt.entries[vpn0] >> 10) << 12)