From a3e491a314efc4ff736cc329c9ec5923dcc1cf64 Mon Sep 17 00:00:00 2001 From: copi143 Date: Tue, 31 Dec 2024 21:40:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9pf=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kernel/mm/vpage.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/kernel/mm/vpage.c b/src/kernel/mm/vpage.c index 7fafaf24..5a3b5277 100755 --- a/src/kernel/mm/vpage.c +++ b/src/kernel/mm/vpage.c @@ -591,26 +591,31 @@ void page_set_physics_attr_pde(u32 vaddr, void *paddr, u32 attr, u32 cr3_backup) } __attr(fastcall) void page_fault(i32 id, regs32 *regs) { - u32 pde = current_task->cr3; + u32 pd = current_task->cr3; asm_set_cr3(PD_ADDRESS); // 设置一个安全的页表 - const var address = asm_get_cr2(); + const var addr = asm_get_cr2(); - if (!(page_get_attr(address, pde) & PAGE_PRESENT) || // 不存在 - (!(page_get_attr(address, pde) & PAGE_USER))) { // 用户不可写 + var pde = pdeof(addr, pd); + var pte = pteof(addr, pde->addr << 12); + + if (!pte->present || !pte->user) { + info("task %d", current_task->tid); error("Attempt to %s a %s memory %p at %p.", // regs->err & PF_WRITE ? "write" : "read", // regs->err & PF_PRESENT ? "kernel" : "non-existent", // - address, regs->eip); - if (current_task->user_mode) { + addr, regs->eip); + if (regs->err & PF_USER) { + kassert(current_task->user_mode); task_abort(); } else { - abort(); // 系统级FAULT + abort(); } } - copy_on_write(address); - asm_set_cr3(pde); + copy_on_write(addr); + + asm_set_cr3(pd); } void page_set_attr(u32 start, u32 end, u32 attr, u32 pde) {