Kernel - Fixed recursion runaway on Panic() in debug
authorJohn Hodge (sonata) <[email protected]>
Sun, 20 Jan 2013 12:15:37 +0000 (20:15 +0800)
committerJohn Hodge (sonata) <[email protected]>
Sun, 20 Jan 2013 12:15:37 +0000 (20:15 +0800)
KernelLand/Kernel/debug.c
KernelLand/Kernel/drv/vterm.h
KernelLand/Kernel/drv/vterm_termbuf.c
KernelLand/Kernel/drv/vterm_vt100.c

index 6132bd9..5e17c0e 100644 (file)
@@ -149,7 +149,7 @@ void Debug(const char *Fmt, ...)
        va_list args;
        
        #if LOCK_DEBUG_OUTPUT
-       SHORTLOCK(&glDebug_Lock);
+       if(!CPU_HAS_LOCK(&glDebug_Lock)) SHORTLOCK(&glDebug_Lock);
        #endif
 
        Debug_Puts(0, "Debug: ");
@@ -227,7 +227,8 @@ void Panic(const char *Fmt, ...)
        va_list args;
        
        #if LOCK_DEBUG_OUTPUT
-       SHORTLOCK(&glDebug_Lock);
+       if( !CPU_HAS_LOCK(&glDebug_Lock) )
+               SHORTLOCK(&glDebug_Lock);
        #endif
        // And never SHORTREL
        
index 55eea0e..abd786c 100644 (file)
@@ -112,7 +112,7 @@ extern void VT_InitInput(void);
 extern void    VT_KBCallBack(Uint32 Codepoint);
 // --- VT100 Emulation ---
 extern void    VT_int_ParseEscape_StandardLarge(tVTerm *Term, char CmdChar, int argc, int *args);
-extern int     VT_int_ParseEscape(tVTerm *Term, const char *Buffer);
+extern int     VT_int_ParseEscape(tVTerm *Term, const char *Buffer, size_t Bytes);
 // --- Terminal Buffer ---
 extern void    VT_int_PutString(tVTerm *Term, const Uint8 *Buffer, Uint Count);
 extern void    VT_int_PutChar(tVTerm *Term, Uint32 Ch);
index 7c29656..525f1a4 100644 (file)
  */
 void VT_int_PutString(tVTerm *Term, const Uint8 *Buffer, Uint Count)
 {
-       Uint32  val;
         int    i;
        
        // Iterate
        for( i = 0; i < Count; i++ )
        {
                // Handle escape sequences
-               if( Buffer[i] == 0x1B )
+               if( Buffer[i] == 0x1B && Count - i > 1 )
                {
-                       i ++;
-                       i += VT_int_ParseEscape(Term, (const char*)&Buffer[i]) - 1;
-                       continue;
+                       int ret = VT_int_ParseEscape(Term, (const char*)&Buffer[i+1], Count-(i+1));
+                       if( ret > 0 )
+                       {
+                               i += ret;
+                               continue;
+                       }
                }
                
                // Fast check for non UTF-8
                if( Buffer[i] < 128 )   // Plain ASCII
                        VT_int_PutChar(Term, Buffer[i]);
                else {  // UTF-8
+                       Uint32  val;
                        i += ReadUTF8(&Buffer[i], &val) - 1;
                        VT_int_PutChar(Term, val);
                }
index fb152a3..d86ee0f 100644 (file)
@@ -211,30 +211,39 @@ void VT_int_ParseEscape_StandardLarge(tVTerm *Term, char CmdChar, int argc, int
  * \fn int VT_int_ParseEscape(tVTerm *Term, const char *Buffer)
  * \brief Parses a VT100 Escape code
  */
-int VT_int_ParseEscape(tVTerm *Term, const char *Buffer)
+int VT_int_ParseEscape(tVTerm *Term, const char *Buffer, size_t Bytes)
 {
        char    c;
-        int    argc = 0, j = 1;
+        int    argc = 0, j = 0;
         int    args[6] = {0,0,0,0};
         int    bQuestionMark = 0;
-       
-       switch(Buffer[0])
+
+       if( Bytes == j )        return j;
+       c = Buffer[j++];
+
+       switch(c)
        {
        //Large Code
        case '[':
                // Get Arguments
+               if(Bytes == j)  return j;
                c = Buffer[j++];
                if(c == '?') {
                        bQuestionMark = 1;
+                       if(Bytes == j)  return j;
                        c = Buffer[j++];
                }
                if( '0' <= c && c <= '9' )
                {
                        do {
-                               if(c == ';')    c = Buffer[j++];
+                               if(c == ';') {
+                                       if(Bytes == j)  return j;
+                                       c = Buffer[j++];
+                               }
                                while('0' <= c && c <= '9') {
                                        args[argc] *= 10;
                                        args[argc] += c-'0';
+                                       if(Bytes == j)  return j;
                                        c = Buffer[j++];
                                }
                                argc ++;
@@ -242,51 +251,64 @@ int VT_int_ParseEscape(tVTerm *Term, const char *Buffer)
                }
                
                // Get Command
-               if( ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
+               if( !('a' <= c && c <= 'z') && !('A' <= c && c <= 'Z') )
                {
-                       if( bQuestionMark )
+                       // Error
+                       return j;
+               }
+               
+               if( bQuestionMark )
+               {
+                       switch(c)
                        {
-                               switch(c)
+                       // DEC Private Mode Set
+                       case 'h':
+                               if(argc != 1)   break;
+                               switch(args[0])
                                {
-                               // DEC Private Mode Set
-                               case 'h':
-                                       if(argc != 1)   break;
-                                       switch(args[0])
-                                       {
-                                       case 25:
-                                               Term->Flags &= ~VT_FLAG_HIDECSR;
-                                               break;
-                                       case 1047:
-                                               VT_int_ToggleAltBuffer(Term, 1);
-                                               break;
-                                       }
+                               case 25:
+                                       Term->Flags &= ~VT_FLAG_HIDECSR;
+                                       break;
+                               case 1047:
+                                       VT_int_ToggleAltBuffer(Term, 1);
                                        break;
-                               case 'l':
-                                       if(argc != 1)   break;
-                                       switch(args[0])
-                                       {
-                                       case 25:
-                                               Term->Flags |= VT_FLAG_HIDECSR;
-                                               break;
-                                       case 1047:
-                                               VT_int_ToggleAltBuffer(Term, 0);
-                                               break;
-                                       }
+                               }
+                               break;
+                       case 'l':
+                               if(argc != 1)   break;
+                               switch(args[0])
+                               {
+                               case 25:
+                                       Term->Flags |= VT_FLAG_HIDECSR;
                                        break;
-                               default:
-                                       Log_Warning("VTerm", "Unknown control sequence '\\x1B[?%c'", c);
+                               case 1047:
+                                       VT_int_ToggleAltBuffer(Term, 0);
                                        break;
                                }
+                               break;
+                       default:
+                               Log_Warning("VTerm", "Unknown control sequence '\\x1B[?%c'", c);
+                               break;
                        }
-                       else
-                       {
-                               VT_int_ParseEscape_StandardLarge(Term, c, argc, args);
-                       }
+               }
+               else
+               {
+                       VT_int_ParseEscape_StandardLarge(Term, c, argc, args);
                }
                break;
-               
+       case '\0':
+               // Ignore \0
+               break;
        default:
-               Log_Notice("VTerm", "TODO: Handle short escape codes");
+               //Log_Notice("VTerm", "TODO: Handle short escape codes");
+               {
+                       static volatile int tmp = 0;
+                       if(tmp == 0) {
+                               tmp = 1;
+                               Debug("VTerm: Unknown short 0x%x", c);
+                               tmp = 0;
+                       }
+               }
                break;
        }
        

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