From 3b853928778e7130ea15676b89e555a1994dcf36 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 17 Feb 2021 17:20:40 +0800 Subject: [PATCH] kernel: riscv: return ShareViolation when memory is shared When memory has been shared, it is no longer valid. However, it is still "in use". Return a `ShareViolation` error in this case so we can check for it elsewhere. Signed-off-by: Sean Cross --- kernel/src/arch/riscv/mem.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/src/arch/riscv/mem.rs b/kernel/src/arch/riscv/mem.rs index 27c3dd8e9..6951478cf 100644 --- a/kernel/src/arch/riscv/mem.rs +++ b/kernel/src/arch/riscv/mem.rs @@ -583,8 +583,13 @@ pub fn virt_to_phys(virt: usize) -> Result { return Err(xous_kernel::Error::BadAddress); } + // If the page is "Valid" but shared, issue a sharing violation + if l0_pt.entries[vpn0] & MMUFlags::S.bits() == 0 { + return Err(xous_kernel::Error::ShareViolation); + } + // Ensure the entry hasn't already been mapped. - if l0_pt.entries[vpn0] & 1 == 0 { + if l0_pt.entries[vpn0] & MMUFlags::VALID.bits() == 0 { return Err(xous_kernel::Error::BadAddress); } Ok((l0_pt.entries[vpn0] >> 10) << 12)