kernel: mem: don't unilaterally hand memory to userspace

If it's needed for use in the kernel, don't hand it over.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-03-23 12:58:13 +08:00
parent a31c4722fa
commit 0be1b8b94c

View file

@ -349,7 +349,7 @@ impl MemoryManager {
/// Attempt to allocate a single page from the default section.
/// Note that this will be backed by a real page.
pub fn map_zeroed_page(&mut self, pid: PID) -> Result<*mut usize, xous::Error> {
pub fn map_zeroed_page(&mut self, pid: PID, is_user: bool) -> Result<*mut usize, xous::Error> {
let virt =
self.find_virtual_address(0 as *mut usize, PAGE_SIZE, xous::MemoryType::Default)?;
@ -372,7 +372,9 @@ impl MemoryManager {
// Zero-out the page
unsafe { virt.write_bytes(0, PAGE_SIZE / mem::size_of::<usize>()) };
crate::arch::mem::hand_page_to_user(virt)?;
if is_user {
crate::arch::mem::hand_page_to_user(virt)?;
}
Ok(virt)
}