From b712345c922cfd32e7ec971f817af97ca7ee7ab4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 14 Feb 2021 09:30:31 +0100 Subject: [PATCH] Kernel: Use PANIC() in a bunch of places :^) --- Kernel/Arch/i386/CPU.cpp | 22 ++++++------------- Kernel/Heap/kmalloc.cpp | 5 ++--- Kernel/Interrupts/APIC.cpp | 4 ++-- .../Interrupts/UnhandledInterruptHandler.cpp | 7 +++--- Kernel/PCI/Initializer.cpp | 6 ++--- Kernel/Scheduler.cpp | 4 ++-- Kernel/Storage/StorageManagement.cpp | 13 +++++------ Kernel/init.cpp | 7 +++--- 8 files changed, 26 insertions(+), 42 deletions(-) diff --git a/Kernel/Arch/i386/CPU.cpp b/Kernel/Arch/i386/CPU.cpp index 09f8f9fc06..6c4e30b139 100644 --- a/Kernel/Arch/i386/CPU.cpp +++ b/Kernel/Arch/i386/CPU.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -163,8 +164,7 @@ void handle_crash(RegisterState& regs, const char* description, int signal, bool { auto process = Process::current(); if (!process) { - dmesgln("{} with !current", description); - Processor::halt(); + PANIC("{} with !current", description); } // If a process crashed while inspecting another process, @@ -175,9 +175,7 @@ void handle_crash(RegisterState& regs, const char* description, int signal, bool dump(regs); if (!(regs.cs & 3)) { - dmesgln("Crash in ring 0 :("); - dump_backtrace(); - Processor::halt(); + PANIC("Crash in ring 0"); } cli(); @@ -330,9 +328,7 @@ void debug_handler(TrapFrame* trap) auto current_thread = Thread::current(); auto& process = current_thread->process(); if ((regs.cs & 3) == 0) { - dmesgln("Debug exception in ring 0"); - Processor::halt(); - return; + PANIC("Debug exception in ring 0"); } constexpr u8 REASON_SINGLESTEP = 14; bool is_reason_singlestep = (read_dr6() & (1 << REASON_SINGLESTEP)); @@ -353,9 +349,7 @@ void breakpoint_handler(TrapFrame* trap) auto current_thread = Thread::current(); auto& process = current_thread->process(); if ((regs.cs & 3) == 0) { - dmesgln("Breakpoint trap in ring 0"); - Processor::halt(); - return; + PANIC("Breakpoint trap in ring 0"); } if (auto tracer = process.tracer()) { tracer->set_regs(regs); @@ -376,8 +370,7 @@ void breakpoint_handler(TrapFrame* trap) : "=a"(cr3)); \ asm("movl %%cr4, %%eax" \ : "=a"(cr4)); \ - dbgln("cr0={:08x} cr2={:08x} cr3={:08x} cr4={:08x}", cr0, cr2, cr3, cr4); \ - Processor::halt(); \ + PANIC("cr0={:08x} cr2={:08x} cr3={:08x} cr4={:08x}", cr0, cr2, cr3, cr4); \ } EH(2, "Unknown error") @@ -398,8 +391,7 @@ const DescriptorTablePointer& get_idtr() static void unimp_trap() { - dmesgln("Unhandled IRQ"); - Processor::Processor::halt(); + PANIC("Unhandled IRQ"); } GenericInterruptHandler& get_interrupt_handler(u8 interrupt_number) diff --git a/Kernel/Heap/kmalloc.cpp b/Kernel/Heap/kmalloc.cpp index 0e81d4836f..a06fa8e582 100644 --- a/Kernel/Heap/kmalloc.cpp +++ b/Kernel/Heap/kmalloc.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -247,9 +248,7 @@ void* kmalloc_impl(size_t size) void* ptr = g_kmalloc_global->m_heap.allocate(size); if (!ptr) { - klog() << "kmalloc(): PANIC! Out of memory (no suitable block for size " << size << ")"; - Kernel::dump_backtrace(); - Processor::halt(); + PANIC("kmalloc: Out of memory (requested size: {})"); } return ptr; diff --git a/Kernel/Interrupts/APIC.cpp b/Kernel/Interrupts/APIC.cpp index f5de71a18c..a698e8535f 100644 --- a/Kernel/Interrupts/APIC.cpp +++ b/Kernel/Interrupts/APIC.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -424,8 +425,7 @@ void APIC::enable(u32 cpu) { if (cpu >= 8) { // TODO: x2apic support? - klog() << "SMP support is currently limited to 8 CPUs!"; - Processor::halt(); + PANIC("SMP support is currently limited to 8 CPUs!"); } // Use the CPU# as logical apic id diff --git a/Kernel/Interrupts/UnhandledInterruptHandler.cpp b/Kernel/Interrupts/UnhandledInterruptHandler.cpp index 827747cdaa..e107beb660 100644 --- a/Kernel/Interrupts/UnhandledInterruptHandler.cpp +++ b/Kernel/Interrupts/UnhandledInterruptHandler.cpp @@ -25,6 +25,7 @@ */ #include +#include namespace Kernel { UnhandledInterruptHandler::UnhandledInterruptHandler(u8 interrupt_vector) @@ -34,14 +35,12 @@ UnhandledInterruptHandler::UnhandledInterruptHandler(u8 interrupt_vector) void UnhandledInterruptHandler::handle_interrupt(const RegisterState&) { - dbgln("Interrupt: Unhandled vector {} was invoked for handle_interrupt(RegisterState&).", interrupt_number()); - Processor::halt(); + PANIC("Interrupt: Unhandled vector {} was invoked for handle_interrupt(RegisterState&).", interrupt_number()); } [[noreturn]] bool UnhandledInterruptHandler::eoi() { - dbgln("Interrupt: Unhandled vector {} was invoked for eoi().", interrupt_number()); - Processor::halt(); + PANIC("Interrupt: Unhandled vector {} was invoked for eoi().", interrupt_number()); } UnhandledInterruptHandler::~UnhandledInterruptHandler() diff --git a/Kernel/PCI/Initializer.cpp b/Kernel/PCI/Initializer.cpp index a56cf4c937..0e8813f43e 100644 --- a/Kernel/PCI/Initializer.cpp +++ b/Kernel/PCI/Initializer.cpp @@ -27,11 +27,10 @@ #include #include #include -#include -#include #include #include #include +#include namespace Kernel { namespace PCI { @@ -46,8 +45,7 @@ static Access::Type detect_optimal_access_type(bool mmio_allowed) if (test_pci_io()) return Access::Type::IO; - klog() << "No PCI bus access method detected!"; - Processor::halt(); + PANIC("No PCI bus access method detected!"); } void initialize() diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 3fc3c6867b..620afebcae 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -418,8 +419,7 @@ bool Scheduler::context_switch(Thread* thread) if (thread->process().is_user_process()) { auto iopl = get_iopl_from_eflags(Thread::current()->get_register_dump_from_stack().eflags); if (iopl != 0) { - dbgln("PANIC: Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl); - Processor::halt(); + PANIC("Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl); } } #endif diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp index c1e0591533..1d68b0da82 100644 --- a/Kernel/Storage/StorageManagement.cpp +++ b/Kernel/Storage/StorageManagement.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -146,8 +147,7 @@ void StorageManagement::determine_boot_device() } if (m_boot_block_device.is_null()) { - klog() << "init_stage2: boot device " << m_boot_argument << " not found"; - Processor::halt(); + PANIC("StorageManagement: boot device {} not found", m_boot_argument); } } @@ -159,8 +159,7 @@ void StorageManagement::determine_boot_device_with_partition_uuid() auto partition_uuid = UUID(m_boot_argument.substring_view(strlen("PARTUUID="))); if (partition_uuid.to_string().length() != 36) { - klog() << "init_stage2: specified partition UUID is not valid"; - Processor::halt(); + PANIC("StorageManagement: Specified partition UUID is not valid"); } for (auto& partition : m_disk_partitions) { @@ -182,13 +181,11 @@ NonnullRefPtr StorageManagement::root_filesystem() const { auto boot_device_description = boot_block_device(); if (!boot_device_description) { - klog() << "init_stage2: couldn't find a suitable device to boot from"; - Processor::halt(); + PANIC("StorageManagement: Couldn't find a suitable device to boot from"); } auto e2fs = Ext2FS::create(FileDescription::create(boot_device_description.release_nonnull()).value()); if (!e2fs->initialize()) { - klog() << "init_stage2: couldn't open root filesystem"; - Processor::halt(); + PANIC("StorageManagement: Couldn't open root filesystem"); } return e2fs; } diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 073000c0d1..1b243d9bae 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -288,8 +289,7 @@ void init_stage2(void*) StorageManagement::initialize(root, force_pio); if (!VFS::the().mount_root(StorageManagement::the().root_filesystem())) { - klog() << "VFS::mount_root failed"; - Processor::halt(); + PANIC("VFS::mount_root failed"); } Process::current()->set_root_directory(VFS::the().root_custody()); @@ -307,8 +307,7 @@ void init_stage2(void*) init_args.prepend(userspace_init); Process::create_user_process(thread, userspace_init, (uid_t)0, (gid_t)0, ProcessID(0), error, move(init_args), {}, tty0); if (error != 0) { - klog() << "init_stage2: error spawning SystemServer: " << error; - Processor::halt(); + PANIC("init_stage2: Error spawning SystemServer: {}", error); } thread->set_priority(THREAD_PRIORITY_HIGH);