From b8c30c32acae47e2c7dd6bd523aaf262bca56007 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 15 May 2025 11:52:41 +0800 Subject: [PATCH] fix bug where pages were not marked as belonging to USER it's assumed the kernel would never want to access the flash directly, so no mode is implemented to support this possibility. --- kernel/src/mem.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/src/mem.rs b/kernel/src/mem.rs index 451091a72..a9e939878 100644 --- a/kernel/src/mem.rs +++ b/kernel/src/mem.rs @@ -6,7 +6,10 @@ use core::fmt; use xous_kernel::{MemoryFlags, MemoryRange, PID, arch::*}; pub use crate::arch::mem::MemoryMapping; -use crate::arch::process::Process; +use crate::arch::{ + mem::{MMUFlags, flush_mmu, pagetable_entry}, + process::Process, +}; #[cfg(feature = "swap")] use crate::swap::SwapAlloc; @@ -635,6 +638,13 @@ impl MemoryManager { // not automatically set on write/update). Valid is not set, because it's not // wired into memory, and "P" (swap) is set to indicate this is a swapper managed page. mm.reserve_address(self, virt, MemoryFlags::R | MemoryFlags::W | MemoryFlags::P)?; + + // now mark the page as USER + let pte = pagetable_entry(virt)?; + unsafe { + pte.write_volatile(pte.read_volatile() | MMUFlags::USER.bits()); + flush_mmu(); + } } // note that the region returned is snapped to the nearest page boundary, even if // the use called us with unaligned addresses.