mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
kernel: riscv: ensure pages are writable when poking
Ensure pages of memory can be written to when we write to them. This lets us patch program code to, for example, insert breakpoints. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
973e4601e4
commit
524df22667
1 changed files with 7 additions and 3 deletions
|
|
@ -383,12 +383,11 @@ pub fn poke_memory<T>(addr: *mut T, val: T) -> Result<(), xous_kernel::Error> {
|
|||
}
|
||||
|
||||
// Ensure we're allowed to read it.
|
||||
if l0_pt.entries[vpn0] & MMUFlags::W.bits() == 0 {
|
||||
Err(xous_kernel::Error::AccessDenied)?;
|
||||
}
|
||||
let was_writable = l0_pt.entries[vpn0] & MMUFlags::W.bits() != 0;
|
||||
|
||||
// Strip the USER flag to the entry so we can read it
|
||||
l0_pt.entries[vpn0] &= !MMUFlags::USER.bits();
|
||||
l0_pt.entries[vpn0] |= MMUFlags::W.bits();
|
||||
unsafe { flush_mmu() };
|
||||
|
||||
// Perform the write
|
||||
|
|
@ -396,6 +395,11 @@ pub fn poke_memory<T>(addr: *mut T, val: T) -> Result<(), xous_kernel::Error> {
|
|||
|
||||
// Add the USER flag back to the entry
|
||||
l0_pt.entries[vpn0] |= MMUFlags::USER.bits();
|
||||
|
||||
// Strip the "writable" bit if it wasn't set before
|
||||
if !was_writable {
|
||||
l0_pt.entries[vpn0] &= !MMUFlags::W.bits();
|
||||
}
|
||||
unsafe { flush_mmu() };
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue