From: John Hodge Date: Sat, 1 May 2010 04:20:12 +0000 (+0800) Subject: Improved user error handling, now a user DIV0 doesn't cause a kernel X-Git-Tag: rel0.06~203 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5beb98670f040b2d4e697e4d8690cd46d2d30cf3;p=tpg%2Facess2.git Improved user error handling, now a user DIV0 doesn't cause a kernel panic. --- diff --git a/Kernel/arch/x86/errors.c b/Kernel/arch/x86/errors.c index ac54bc11..d1d9cb72 100644 --- a/Kernel/arch/x86/errors.c +++ b/Kernel/arch/x86/errors.c @@ -12,7 +12,8 @@ // === IMPORTS === extern void MM_PageFault(Uint Addr, Uint ErrorCode, tRegs *Regs); extern void VM8086_GPF(tRegs *Regs); -extern void Threads_Dump(); +extern void Threads_Dump(void); +extern void Threads_Fault(int Num); // === PROTOTYPES === void Error_Backtrace(Uint eip, Uint ebp); @@ -66,6 +67,28 @@ void ErrorHandler(tRegs *Regs) return ; } + // Check if it's a user mode fault + if( Regs->eip < KERNEL_BASE || (Regs->cs & 3) == 3 ) { + Log_Warning("Arch", "User Fault - %s, Code: 0x%x", + csaERROR_NAMES[Regs->int_num], Regs->err_code); + Log_Warning("Arch", "at CS:EIP %04x:%08x", + Regs->cs, Regs->eip); + switch( Regs->int_num ) + { + // Division by Zero + case 0: Threads_Fault(FAULT_DIV0); break; + // Invalid opcode + case 6: Threads_Fault(FAULT_OPCODE); break; + // GPF + case 13: Threads_Fault(FAULT_ACCESS); break; + // Floating Point Exception + case 16: Threads_Fault(FAULT_FLOAT); break; + + default: Threads_Fault(FAULT_MISC); break; + } + return ; + } + Debug_KernelPanic(); Warning("CPU Error %i - %s, Code: 0x%x", Regs->int_num, csaERROR_NAMES[Regs->int_num], Regs->err_code); diff --git a/Kernel/include/threads.h b/Kernel/include/threads.h index 28d669d2..2b066d9f 100644 --- a/Kernel/include/threads.h +++ b/Kernel/include/threads.h @@ -67,6 +67,16 @@ enum { THREAD_STAT_DEAD }; +enum eFaultNumbers +{ + FAULT_MISC, + FAULT_PAGE, + FAULT_ACCESS, + FAULT_DIV0, + FAULT_OPCODE, + FAULT_FLOAT +}; + // === FUNCTIONS === extern tThread *Proc_GetCurThread(); extern tThread *Threads_GetThread(Uint TID); diff --git a/Kernel/threads.c b/Kernel/threads.c index 0a9ab372..c62f7268 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -565,7 +565,7 @@ void Threads_AddActive(tThread *Thread) } /** - * \fn void Threads_SetSignalHandler(Uint Handler) + * \fn void Threads_SetFaultHandler(Uint Handler) * \brief Sets the signal handler for a signal */ void Threads_SetFaultHandler(Uint Handler) @@ -606,6 +606,8 @@ void Threads_Fault(int Num) HALT(); } + thread->CurFaultNum = Num; + Proc_CallFaultHandler(thread); }