X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/2a49908006b177c4d6354309333d06b1b96e4887..f09e806d5032150564df39a2f7b1192c4d84cf15:/lunaix-os/kernel/asm/x86/pfault.c?ds=inline diff --git a/lunaix-os/kernel/asm/x86/pfault.c b/lunaix-os/kernel/asm/x86/pfault.c index 0d5a6fa..70d5e56 100644 --- a/lunaix-os/kernel/asm/x86/pfault.c +++ b/lunaix-os/kernel/asm/x86/pfault.c @@ -28,6 +28,7 @@ __print_panic_msg(const char* msg, const isr_param* param); void intr_routine_page_fault(const isr_param* param) { + uint32_t errcode = param->execp->err_code; ptr_t ptr = cpu_rcr2(); if (!ptr) { goto segv_term; @@ -50,6 +51,11 @@ intr_routine_page_fault(const isr_param* param) goto segv_term; } + if ((errcode & PG_ALLOW_USER)) { + // invalid access + goto segv_term; + } + volatile x86_pte_t* pte = &PTE_MOUNTED(VMS_SELF, ptr >> 12); if (PG_IS_PRESENT(*pte)) { if ((hit_region->attr & COW_MASK) == COW_MASK) { @@ -78,7 +84,7 @@ intr_routine_page_fault(const isr_param* param) goto oom; } - *pte = *pte | pa | PG_PRESENT; + *pte = *pte | pa | PG_PRESENT | PG_ALLOW_USER; memset((void*)PG_ALIGN(ptr), 0, PG_SIZE); goto resolved; } @@ -101,7 +107,7 @@ intr_routine_page_fault(const isr_param* param) } cpu_invplg((ptr_t)pte); - *pte = (*pte & 0xFFF) | pa | PG_PRESENT; + *pte = (*pte & 0xFFF) | pa | PG_PRESENT | PG_ALLOW_USER; memset((void*)ptr, 0, PG_SIZE); @@ -128,13 +134,17 @@ intr_routine_page_fault(const isr_param* param) oom: kprintf(KERROR "out of memory\n"); + segv_term: - kprintf(KERROR "(pid: %d) Segmentation fault on %p (%p:%p)\n", + kprintf(KERROR "(pid: %d) Segmentation fault on %p (%p:%p,e=0x%x)\n", __current->pid, ptr, param->execp->cs, - param->execp->eip); + param->execp->eip, + param->execp->err_code); + __SIGSET(__current->sig_pending, _SIGSEGV); + schedule(); // should not reach while (1)