From: John Hodge (sonata) Date: Sun, 20 Jan 2013 12:15:37 +0000 (+0800) Subject: Kernel - Fixed recursion runaway on Panic() in debug X-Git-Tag: rel0.15~598^2~3 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a88ba0c5436470438a63241b126f926968ef558f;p=tpg%2Facess2.git Kernel - Fixed recursion runaway on Panic() in debug --- diff --git a/KernelLand/Kernel/debug.c b/KernelLand/Kernel/debug.c index 6132bd90..5e17c0ed 100644 --- a/KernelLand/Kernel/debug.c +++ b/KernelLand/Kernel/debug.c @@ -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 diff --git a/KernelLand/Kernel/drv/vterm.h b/KernelLand/Kernel/drv/vterm.h index 55eea0e5..abd786cb 100644 --- a/KernelLand/Kernel/drv/vterm.h +++ b/KernelLand/Kernel/drv/vterm.h @@ -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); diff --git a/KernelLand/Kernel/drv/vterm_termbuf.c b/KernelLand/Kernel/drv/vterm_termbuf.c index 7c296566..525f1a4b 100644 --- a/KernelLand/Kernel/drv/vterm_termbuf.c +++ b/KernelLand/Kernel/drv/vterm_termbuf.c @@ -15,24 +15,27 @@ */ 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); } diff --git a/KernelLand/Kernel/drv/vterm_vt100.c b/KernelLand/Kernel/drv/vterm_vt100.c index fb152a30..d86ee0fb 100644 --- a/KernelLand/Kernel/drv/vterm_vt100.c +++ b/KernelLand/Kernel/drv/vterm_vt100.c @@ -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; }