From 02a980ee54487cd3b09a3c4bc870d0b1b3bb7b51 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 16 Sep 2022 13:10:06 +0300 Subject: [PATCH] Kernel/Graphics: Always ensure a console is set when initialization ends We use a ScopeGuard to ensure we always set a console of some sort if we exit early from the initialization sequence in the GraphicsManagement code. We do so to ensure we can boot into text mode console in an ISA-PC machine type, because earlier we failed with an assertion due to not setting any console for VirtualConsole to use. --- Kernel/Graphics/GraphicsManagement.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp index 4411ec45639..ef1f9ac1957 100644 --- a/Kernel/Graphics/GraphicsManagement.cpp +++ b/Kernel/Graphics/GraphicsManagement.cpp @@ -189,15 +189,20 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize() * a variant that is suitable for ISA VGA handling, and not PCI adapters. */ + ScopeGuard assign_console_on_initialization_exit([this] { + if (!m_console) { + // If no graphics driver was instantiated and we had a bootloader provided + // framebuffer console we can simply re-use it. + if (auto* boot_console = g_boot_console.load()) { + m_console = *boot_console; + boot_console->unref(); // Drop the leaked reference from Kernel::init() + } + } + }); + auto graphics_subsystem_mode = kernel_command_line().graphics_subsystem_mode(); if (graphics_subsystem_mode == CommandLine::GraphicsSubsystemMode::Disabled) { VERIFY(!m_console); - // If no graphics driver was instantiated and we had a bootloader provided - // framebuffer console we can simply re-use it. - if (auto* boot_console = g_boot_console.load()) { - m_console = *boot_console; - boot_console->unref(); // Drop the leaked reference from Kernel::init() - } return true; } @@ -232,15 +237,6 @@ UNMAP_AFTER_INIT bool GraphicsManagement::initialize() return true; } - if (!m_console) { - // If no graphics driver was instantiated and we had a bootloader provided - // framebuffer console we can simply re-use it. - if (auto* boot_console = g_boot_console.load()) { - m_console = *boot_console; - boot_console->unref(); // Drop the leaked reference from Kernel::init() - } - } - if (m_graphics_devices.is_empty()) { dbgln("No graphics adapter was initialized."); return false;