diff options
author | Andreas Kling <kling@serenityos.org> | 2021-02-14 09:30:31 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-14 09:36:58 +0100 |
commit | b712345c922cfd32e7ec971f817af97ca7ee7ab4 (patch) | |
tree | c8cbfe3b0e281b603cfae05f5b0abb87b53e3776 | |
parent | c598a95b1c3b66cf1029eac2bcd88288c1fdb05f (diff) | |
download | serenity-b712345c922cfd32e7ec971f817af97ca7ee7ab4.zip |
Kernel: Use PANIC() in a bunch of places :^)
-rw-r--r-- | Kernel/Arch/i386/CPU.cpp | 22 | ||||
-rw-r--r-- | Kernel/Heap/kmalloc.cpp | 5 | ||||
-rw-r--r-- | Kernel/Interrupts/APIC.cpp | 4 | ||||
-rw-r--r-- | Kernel/Interrupts/UnhandledInterruptHandler.cpp | 7 | ||||
-rw-r--r-- | Kernel/PCI/Initializer.cpp | 6 | ||||
-rw-r--r-- | Kernel/Scheduler.cpp | 4 | ||||
-rw-r--r-- | Kernel/Storage/StorageManagement.cpp | 13 | ||||
-rw-r--r-- | 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 <Kernel/Interrupts/SpuriousInterruptHandler.h> #include <Kernel/Interrupts/UnhandledInterruptHandler.h> #include <Kernel/KSyms.h> +#include <Kernel/Panic.h> #include <Kernel/Process.h> #include <Kernel/Random.h> #include <Kernel/SpinLock.h> @@ -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 <Kernel/Heap/Heap.h> #include <Kernel/Heap/kmalloc.h> #include <Kernel/KSyms.h> +#include <Kernel/Panic.h> #include <Kernel/Process.h> #include <Kernel/Scheduler.h> #include <Kernel/SpinLock.h> @@ -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 <Kernel/IO.h> #include <Kernel/Interrupts/APIC.h> #include <Kernel/Interrupts/SpuriousInterruptHandler.h> +#include <Kernel/Panic.h> #include <Kernel/Thread.h> #include <Kernel/Time/APICTimer.h> #include <Kernel/VM/MemoryManager.h> @@ -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 <Kernel/Interrupts/UnhandledInterruptHandler.h> +#include <Kernel/Panic.h> 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 <Kernel/ACPI/Parser.h> #include <Kernel/CommandLine.h> #include <Kernel/IO.h> -#include <Kernel/Net/E1000NetworkAdapter.h> -#include <Kernel/Net/RTL8139NetworkAdapter.h> #include <Kernel/PCI/IOAccess.h> #include <Kernel/PCI/Initializer.h> #include <Kernel/PCI/MMIOAccess.h> +#include <Kernel/Panic.h> 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 <AK/TemporaryChange.h> #include <AK/Time.h> #include <Kernel/Debug.h> +#include <Kernel/Panic.h> #include <Kernel/PerformanceEventBuffer.h> #include <Kernel/Process.h> #include <Kernel/RTC.h> @@ -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 <Kernel/Devices/BlockDevice.h> #include <Kernel/FileSystem/Ext2FileSystem.h> #include <Kernel/PCI/Access.h> +#include <Kernel/Panic.h> #include <Kernel/Storage/IDEController.h> #include <Kernel/Storage/Partition/EBRPartitionTable.h> #include <Kernel/Storage/Partition/GUIDPartitionTable.h> @@ -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<FS> 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 <Kernel/Net/RTL8139NetworkAdapter.h> #include <Kernel/PCI/Access.h> #include <Kernel/PCI/Initializer.h> +#include <Kernel/Panic.h> #include <Kernel/Process.h> #include <Kernel/RTC.h> #include <Kernel/Random.h> @@ -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); |