From 12a37500b085755a79fad9451415039d44b2b104 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 9 Dec 2024 03:35:51 +0200 Subject: [PATCH] Kernel: Fix triple-fault in vitual tty This was happening when printing non-utf8 data while having virtual tty as the debug console. --- kernel/include/kernel/Debug.h | 1 + kernel/kernel/Terminal/VirtualTTY.cpp | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/kernel/include/kernel/Debug.h b/kernel/include/kernel/Debug.h index c626f0452d..78e1a8e0e8 100644 --- a/kernel/include/kernel/Debug.h +++ b/kernel/include/kernel/Debug.h @@ -47,6 +47,7 @@ #define BOCHS_BREAK() asm volatile("xchgw %bx, %bx") +#define DEBUG_VTTY 1 #define DEBUG_PCI 0 #define DEBUG_SCHEDULER 0 diff --git a/kernel/kernel/Terminal/VirtualTTY.cpp b/kernel/kernel/Terminal/VirtualTTY.cpp index 8ef3c172cd..2ea8cdc055 100644 --- a/kernel/kernel/Terminal/VirtualTTY.cpp +++ b/kernel/kernel/Terminal/VirtualTTY.cpp @@ -251,7 +251,7 @@ namespace Kernel return reset_ansi(); } reset_ansi(); - dprintln("Unsupported ANSI CSI character J"); + dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character J"); return; case 'K': // Erase in Line if (m_ansi_state.nums[0] == -1 || m_ansi_state.nums[0] == 0) @@ -261,7 +261,7 @@ namespace Kernel return reset_ansi(); } reset_ansi(); - dprintln("Unsupported ANSI CSI character K"); + dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character K"); return; case 'L': // Insert Line if (m_ansi_state.nums[0] == -1) @@ -297,15 +297,15 @@ namespace Kernel return reset_ansi(); case 'S': // Scroll Up reset_ansi(); - dprintln("Unsupported ANSI CSI character S"); + dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character S"); return; case 'T': // Scroll Down reset_ansi(); - dprintln("Unsupported ANSI CSI character T"); + dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character T"); return; case 'f': // Horizontal Vertical Position reset_ansi(); - dprintln("Unsupported ANSI CSI character f"); + dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character f"); return; case 'm': handle_ansi_csi_color(); @@ -350,7 +350,7 @@ namespace Kernel return reset_ansi(); } reset_ansi(); - dprintln("invalid ANSI CSI ?"); + dprintln_if(DEBUG_VTTY, "invalid ANSI CSI ?"); return; case 'h': case 'l': @@ -360,11 +360,11 @@ namespace Kernel return reset_ansi(); } reset_ansi(); - dprintln("invalid ANSI CSI ?{}{}", m_ansi_state.nums[0], (char)ch); + dprintln_if(DEBUG_VTTY, "invalid ANSI CSI ?{}{}", m_ansi_state.nums[0], (char)ch); return; default: reset_ansi(); - dprintln("Unsupported ANSI CSI character {}", ch); + dprintln_if(DEBUG_VTTY, "Unsupported ANSI CSI character {}", ch); return; } } @@ -416,7 +416,9 @@ namespace Kernel } else { - dprintln("invalid utf8"); + reset_ansi(); + dprintln_if(DEBUG_VTTY, "invalid utf8"); + return; } m_state = State::WaitingUTF8; return; @@ -425,8 +427,8 @@ namespace Kernel m_state = State::WaitingAnsiCSI; else { - dprintln("unsupported byte after ansi escape {2H}", (uint8_t)ch); reset_ansi(); + dprintln_if(DEBUG_VTTY, "unsupported byte after ansi escape {2H}", (uint8_t)ch); } return; case State::WaitingAnsiCSI: @@ -436,8 +438,8 @@ namespace Kernel case State::WaitingUTF8: if ((ch & 0xC0) != 0x80) { - dprintln("invalid utf8"); m_state = State::Normal; + dprintln_if(DEBUG_VTTY, "invalid utf8"); return; } m_utf8_state.codepoint = (m_utf8_state.codepoint << 6) | (ch & 0x3F);