diff --git a/arch/x86/exception.c b/arch/x86/exception.c index 512f8c5..61f5616 100644 --- a/arch/x86/exception.c +++ b/arch/x86/exception.c @@ -53,10 +53,12 @@ void print_handler(struct cpu_state *frame, ulong intr) void pagefault_handler(struct cpu_state *frame, ulong intr) { - + // PAGE_FAULT is a interrupt with an error code (see exception_wrapper.S) + uint32_t error_code = cpu_context_get_EX_err(frame); struct thread *current = getCurrentThread(); - assert(frame == current->cpuState); + if (cpu_context_is_in_user_mode(current->cpuState)) { + assert(frame == current->cpuState); // pagefault in kernel not supported ATM struct uAddrSpace *as = processGetAddrSpace(current->process); vaddr_t faultAddr = cpu_context_get_EX_faulting_vaddr(frame); @@ -70,8 +72,6 @@ void pagefault_handler(struct cpu_state *frame, ulong intr) if (!uAddrSpaceHeapCheckNAlloc(as, faultAddr)) goto release_context; - // PAGE_FAULT is a interrupt with an error code (see exception_wrapper.S) - uint32_t error_code = cpu_context_get_EX_err(frame); int ret = uAddrSpaceSolvePageFault(as, faultAddr, error_code & 0x2); if (!ret) diff --git a/core/thread.c b/core/thread.c index 2f74f01..6e78c12 100644 --- a/core/thread.c +++ b/core/thread.c @@ -165,8 +165,9 @@ void threadDelete(struct thread *thread) } if (thread->squattedContext) { - threadChangeCurrentContext(NULL); + mmuContextUnref(thread->squattedContext); } + if (thread->process) processRemoveThread(thread);