struct thread *fault_page(struct thread *image) { uint32_t cr2; /* Get faulting address from register CR2 */ cr2 = cpu_get_cr2(); /* If in kernelspace, panic */ if ((image->cs & 0x3) == 0) { /* i.e. if it was kernelmode */ debug_printf("page fault at %x, ip = %x, frame %x, esp = %x\n", cr2, image->eip, page_get(cr2), image->esp); debug_panic("page fault exception"); } if (cr2 >= image->stack && cr2 < image->stack + SEGSZ) { /* allocate stack */ mem_alloc(cr2 & ~0xFFF, PAGESZ, PF_PRES | PF_RW | PF_USER); return image; } else { /* fault */ debug_printf("%d: %s: page fault at %x, ip = %x, frame %x\n", image->proc->pid, image->proc->name, cr2, image->eip, page_get(cr2)); debug_printf("user stack: %x - %x\n", image->stack, image->stack + SEGSZ); debug_printf("user stack dump: (ebp = %x)\n", image->ebp); debug_dumpi((void*) image->useresp, 30); process_freeze(image->proc); return thread_send(image, image->proc->pid, PORT_PAGE, NULL); } }
struct thread *fault_generic(struct thread *image) { /* If in kernelspace, panic */ if ((image->cs & 0x3) == 0) { debug_printf("EIP:%x NUM:%d ERR:%x\n", image->eip, image->num, image->err); debug_panic("unknown exception"); } process_freeze(image->proc); return thread_send(image, image->proc->pid, PORT_ILL, NULL); }