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 <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-01-07 13:34:42 +08:00 committed by bunnie
parent dcdd33e594
commit b884c8ed4f

View file

@ -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::<usize>());