From b884c8ed4fbd9bba1d3458262cb8431d6ca043aa Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 7 Jan 2021 13:34:42 +0800 Subject: [PATCH] kernel: riscv: use page base addr when allocating pages When allocating a page, it is only assigned a physical address once it is actually needed. This on-demand paging works well, however we were assuming that the first address of a page was accessed first. This fixes an issue where a Message is allocated but the first byte isn't accessed first. Signed-off-by: Sean Cross --- kernel/src/arch/riscv/irq.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/src/arch/riscv/irq.rs b/kernel/src/arch/riscv/irq.rs index f31147f11..217e30058 100644 --- a/kernel/src/arch/riscv/irq.rs +++ b/kernel/src/arch/riscv/irq.rs @@ -126,7 +126,8 @@ pub extern "C" fn trap_handler( "KERNEL({}): RISC-V fault: {} @ {:08x}, addr {:08x}", pid, ex, pc, addr ); - let entry = crate::arch::mem::pagetable_entry(addr).unwrap_or_else(|x| { + let virt = addr & !0xfff; + let entry = crate::arch::mem::pagetable_entry(virt).unwrap_or_else(|x| { // MemoryManagerHandle::get().print_ownership(); MemoryMapping::current().print_map(); panic!( @@ -153,7 +154,6 @@ pub extern "C" fn trap_handler( flush_mmu(); // Zero-out the page - let virt = addr & !0xfff; (virt as *mut usize) .write_bytes(0, PAGE_SIZE / core::mem::size_of::());