kernel: riscv: mark address_available() as false when shared

When a page is shared, only report an address as being available when
we receive a `BadAddress` error when doing the translation. Otherwise,
assume it is in use.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-02-17 17:21:24 +08:00
parent 3b85392877
commit e9a1da25b0

View file

@ -597,5 +597,12 @@ pub fn virt_to_phys(virt: usize) -> Result<usize, xous_kernel::Error> {
/// Determine whether a virtual address has been mapped
pub fn address_available(virt: usize) -> bool {
virt_to_phys(virt).is_err()
if let Err(e) = virt_to_phys(virt) {
// If the value is a `BadAddress`, then that means that address is not valid
// and is therefore available
e == xous_kernel::Error::BadAddress
} else {
// If the address is not an error, then it is not available and shouldn't be used.
false
}
}