Improved user error handling, now a user DIV0 doesn't cause a kernel
authorJohn Hodge <[email protected]>
Sat, 1 May 2010 04:20:12 +0000 (12:20 +0800)
committerJohn Hodge <[email protected]>
Sat, 1 May 2010 04:20:12 +0000 (12:20 +0800)
 panic.

Kernel/arch/x86/errors.c
Kernel/include/threads.h
Kernel/threads.c

index ac54bc1..d1d9cb7 100644 (file)
@@ -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);
index 28d669d..2b066d9 100644 (file)
@@ -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);
index 0a9ab37..c62f726 100644 (file)
@@ -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);
 }
 

UCC git Repository :: git.ucc.asn.au