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;
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) {
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;
}
}
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);
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)