1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 00:08:11 +00:00

Kernel: Use PANIC() in a bunch of places :^)

This commit is contained in:
Andreas Kling 2021-02-14 09:30:31 +01:00
parent c598a95b1c
commit b712345c92
8 changed files with 26 additions and 42 deletions

View file

@ -43,6 +43,7 @@
#include <Kernel/Interrupts/SpuriousInterruptHandler.h> #include <Kernel/Interrupts/SpuriousInterruptHandler.h>
#include <Kernel/Interrupts/UnhandledInterruptHandler.h> #include <Kernel/Interrupts/UnhandledInterruptHandler.h>
#include <Kernel/KSyms.h> #include <Kernel/KSyms.h>
#include <Kernel/Panic.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
#include <Kernel/SpinLock.h> #include <Kernel/SpinLock.h>
@ -163,8 +164,7 @@ void handle_crash(RegisterState& regs, const char* description, int signal, bool
{ {
auto process = Process::current(); auto process = Process::current();
if (!process) { if (!process) {
dmesgln("{} with !current", description); PANIC("{} with !current", description);
Processor::halt();
} }
// If a process crashed while inspecting another process, // 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); dump(regs);
if (!(regs.cs & 3)) { if (!(regs.cs & 3)) {
dmesgln("Crash in ring 0 :("); PANIC("Crash in ring 0");
dump_backtrace();
Processor::halt();
} }
cli(); cli();
@ -330,9 +328,7 @@ void debug_handler(TrapFrame* trap)
auto current_thread = Thread::current(); auto current_thread = Thread::current();
auto& process = current_thread->process(); auto& process = current_thread->process();
if ((regs.cs & 3) == 0) { if ((regs.cs & 3) == 0) {
dmesgln("Debug exception in ring 0"); PANIC("Debug exception in ring 0");
Processor::halt();
return;
} }
constexpr u8 REASON_SINGLESTEP = 14; constexpr u8 REASON_SINGLESTEP = 14;
bool is_reason_singlestep = (read_dr6() & (1 << REASON_SINGLESTEP)); bool is_reason_singlestep = (read_dr6() & (1 << REASON_SINGLESTEP));
@ -353,9 +349,7 @@ void breakpoint_handler(TrapFrame* trap)
auto current_thread = Thread::current(); auto current_thread = Thread::current();
auto& process = current_thread->process(); auto& process = current_thread->process();
if ((regs.cs & 3) == 0) { if ((regs.cs & 3) == 0) {
dmesgln("Breakpoint trap in ring 0"); PANIC("Breakpoint trap in ring 0");
Processor::halt();
return;
} }
if (auto tracer = process.tracer()) { if (auto tracer = process.tracer()) {
tracer->set_regs(regs); tracer->set_regs(regs);
@ -376,8 +370,7 @@ void breakpoint_handler(TrapFrame* trap)
: "=a"(cr3)); \ : "=a"(cr3)); \
asm("movl %%cr4, %%eax" \ asm("movl %%cr4, %%eax" \
: "=a"(cr4)); \ : "=a"(cr4)); \
dbgln("cr0={:08x} cr2={:08x} cr3={:08x} cr4={:08x}", cr0, cr2, cr3, cr4); \ PANIC("cr0={:08x} cr2={:08x} cr3={:08x} cr4={:08x}", cr0, cr2, cr3, cr4); \
Processor::halt(); \
} }
EH(2, "Unknown error") EH(2, "Unknown error")
@ -398,8 +391,7 @@ const DescriptorTablePointer& get_idtr()
static void unimp_trap() static void unimp_trap()
{ {
dmesgln("Unhandled IRQ"); PANIC("Unhandled IRQ");
Processor::Processor::halt();
} }
GenericInterruptHandler& get_interrupt_handler(u8 interrupt_number) GenericInterruptHandler& get_interrupt_handler(u8 interrupt_number)

View file

@ -38,6 +38,7 @@
#include <Kernel/Heap/Heap.h> #include <Kernel/Heap/Heap.h>
#include <Kernel/Heap/kmalloc.h> #include <Kernel/Heap/kmalloc.h>
#include <Kernel/KSyms.h> #include <Kernel/KSyms.h>
#include <Kernel/Panic.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/Scheduler.h> #include <Kernel/Scheduler.h>
#include <Kernel/SpinLock.h> #include <Kernel/SpinLock.h>
@ -247,9 +248,7 @@ void* kmalloc_impl(size_t size)
void* ptr = g_kmalloc_global->m_heap.allocate(size); void* ptr = g_kmalloc_global->m_heap.allocate(size);
if (!ptr) { if (!ptr) {
klog() << "kmalloc(): PANIC! Out of memory (no suitable block for size " << size << ")"; PANIC("kmalloc: Out of memory (requested size: {})");
Kernel::dump_backtrace();
Processor::halt();
} }
return ptr; return ptr;

View file

@ -36,6 +36,7 @@
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Interrupts/APIC.h> #include <Kernel/Interrupts/APIC.h>
#include <Kernel/Interrupts/SpuriousInterruptHandler.h> #include <Kernel/Interrupts/SpuriousInterruptHandler.h>
#include <Kernel/Panic.h>
#include <Kernel/Thread.h> #include <Kernel/Thread.h>
#include <Kernel/Time/APICTimer.h> #include <Kernel/Time/APICTimer.h>
#include <Kernel/VM/MemoryManager.h> #include <Kernel/VM/MemoryManager.h>
@ -424,8 +425,7 @@ void APIC::enable(u32 cpu)
{ {
if (cpu >= 8) { if (cpu >= 8) {
// TODO: x2apic support? // TODO: x2apic support?
klog() << "SMP support is currently limited to 8 CPUs!"; PANIC("SMP support is currently limited to 8 CPUs!");
Processor::halt();
} }
// Use the CPU# as logical apic id // Use the CPU# as logical apic id

View file

@ -25,6 +25,7 @@
*/ */
#include <Kernel/Interrupts/UnhandledInterruptHandler.h> #include <Kernel/Interrupts/UnhandledInterruptHandler.h>
#include <Kernel/Panic.h>
namespace Kernel { namespace Kernel {
UnhandledInterruptHandler::UnhandledInterruptHandler(u8 interrupt_vector) UnhandledInterruptHandler::UnhandledInterruptHandler(u8 interrupt_vector)
@ -34,14 +35,12 @@ UnhandledInterruptHandler::UnhandledInterruptHandler(u8 interrupt_vector)
void UnhandledInterruptHandler::handle_interrupt(const RegisterState&) void UnhandledInterruptHandler::handle_interrupt(const RegisterState&)
{ {
dbgln("Interrupt: Unhandled vector {} was invoked for handle_interrupt(RegisterState&).", interrupt_number()); PANIC("Interrupt: Unhandled vector {} was invoked for handle_interrupt(RegisterState&).", interrupt_number());
Processor::halt();
} }
[[noreturn]] bool UnhandledInterruptHandler::eoi() [[noreturn]] bool UnhandledInterruptHandler::eoi()
{ {
dbgln("Interrupt: Unhandled vector {} was invoked for eoi().", interrupt_number()); PANIC("Interrupt: Unhandled vector {} was invoked for eoi().", interrupt_number());
Processor::halt();
} }
UnhandledInterruptHandler::~UnhandledInterruptHandler() UnhandledInterruptHandler::~UnhandledInterruptHandler()

View file

@ -27,11 +27,10 @@
#include <Kernel/ACPI/Parser.h> #include <Kernel/ACPI/Parser.h>
#include <Kernel/CommandLine.h> #include <Kernel/CommandLine.h>
#include <Kernel/IO.h> #include <Kernel/IO.h>
#include <Kernel/Net/E1000NetworkAdapter.h>
#include <Kernel/Net/RTL8139NetworkAdapter.h>
#include <Kernel/PCI/IOAccess.h> #include <Kernel/PCI/IOAccess.h>
#include <Kernel/PCI/Initializer.h> #include <Kernel/PCI/Initializer.h>
#include <Kernel/PCI/MMIOAccess.h> #include <Kernel/PCI/MMIOAccess.h>
#include <Kernel/Panic.h>
namespace Kernel { namespace Kernel {
namespace PCI { namespace PCI {
@ -46,8 +45,7 @@ static Access::Type detect_optimal_access_type(bool mmio_allowed)
if (test_pci_io()) if (test_pci_io())
return Access::Type::IO; return Access::Type::IO;
klog() << "No PCI bus access method detected!"; PANIC("No PCI bus access method detected!");
Processor::halt();
} }
void initialize() void initialize()

View file

@ -29,6 +29,7 @@
#include <AK/TemporaryChange.h> #include <AK/TemporaryChange.h>
#include <AK/Time.h> #include <AK/Time.h>
#include <Kernel/Debug.h> #include <Kernel/Debug.h>
#include <Kernel/Panic.h>
#include <Kernel/PerformanceEventBuffer.h> #include <Kernel/PerformanceEventBuffer.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/RTC.h> #include <Kernel/RTC.h>
@ -418,8 +419,7 @@ bool Scheduler::context_switch(Thread* thread)
if (thread->process().is_user_process()) { if (thread->process().is_user_process()) {
auto iopl = get_iopl_from_eflags(Thread::current()->get_register_dump_from_stack().eflags); auto iopl = get_iopl_from_eflags(Thread::current()->get_register_dump_from_stack().eflags);
if (iopl != 0) { if (iopl != 0) {
dbgln("PANIC: Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl); PANIC("Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl);
Processor::halt();
} }
} }
#endif #endif

View file

@ -29,6 +29,7 @@
#include <Kernel/Devices/BlockDevice.h> #include <Kernel/Devices/BlockDevice.h>
#include <Kernel/FileSystem/Ext2FileSystem.h> #include <Kernel/FileSystem/Ext2FileSystem.h>
#include <Kernel/PCI/Access.h> #include <Kernel/PCI/Access.h>
#include <Kernel/Panic.h>
#include <Kernel/Storage/IDEController.h> #include <Kernel/Storage/IDEController.h>
#include <Kernel/Storage/Partition/EBRPartitionTable.h> #include <Kernel/Storage/Partition/EBRPartitionTable.h>
#include <Kernel/Storage/Partition/GUIDPartitionTable.h> #include <Kernel/Storage/Partition/GUIDPartitionTable.h>
@ -146,8 +147,7 @@ void StorageManagement::determine_boot_device()
} }
if (m_boot_block_device.is_null()) { if (m_boot_block_device.is_null()) {
klog() << "init_stage2: boot device " << m_boot_argument << " not found"; PANIC("StorageManagement: boot device {} not found", m_boot_argument);
Processor::halt();
} }
} }
@ -159,8 +159,7 @@ void StorageManagement::determine_boot_device_with_partition_uuid()
auto partition_uuid = UUID(m_boot_argument.substring_view(strlen("PARTUUID="))); auto partition_uuid = UUID(m_boot_argument.substring_view(strlen("PARTUUID=")));
if (partition_uuid.to_string().length() != 36) { if (partition_uuid.to_string().length() != 36) {
klog() << "init_stage2: specified partition UUID is not valid"; PANIC("StorageManagement: Specified partition UUID is not valid");
Processor::halt();
} }
for (auto& partition : m_disk_partitions) { for (auto& partition : m_disk_partitions) {
@ -182,13 +181,11 @@ NonnullRefPtr<FS> StorageManagement::root_filesystem() const
{ {
auto boot_device_description = boot_block_device(); auto boot_device_description = boot_block_device();
if (!boot_device_description) { if (!boot_device_description) {
klog() << "init_stage2: couldn't find a suitable device to boot from"; PANIC("StorageManagement: Couldn't find a suitable device to boot from");
Processor::halt();
} }
auto e2fs = Ext2FS::create(FileDescription::create(boot_device_description.release_nonnull()).value()); auto e2fs = Ext2FS::create(FileDescription::create(boot_device_description.release_nonnull()).value());
if (!e2fs->initialize()) { if (!e2fs->initialize()) {
klog() << "init_stage2: couldn't open root filesystem"; PANIC("StorageManagement: Couldn't open root filesystem");
Processor::halt();
} }
return e2fs; return e2fs;
} }

View file

@ -60,6 +60,7 @@
#include <Kernel/Net/RTL8139NetworkAdapter.h> #include <Kernel/Net/RTL8139NetworkAdapter.h>
#include <Kernel/PCI/Access.h> #include <Kernel/PCI/Access.h>
#include <Kernel/PCI/Initializer.h> #include <Kernel/PCI/Initializer.h>
#include <Kernel/Panic.h>
#include <Kernel/Process.h> #include <Kernel/Process.h>
#include <Kernel/RTC.h> #include <Kernel/RTC.h>
#include <Kernel/Random.h> #include <Kernel/Random.h>
@ -288,8 +289,7 @@ void init_stage2(void*)
StorageManagement::initialize(root, force_pio); StorageManagement::initialize(root, force_pio);
if (!VFS::the().mount_root(StorageManagement::the().root_filesystem())) { if (!VFS::the().mount_root(StorageManagement::the().root_filesystem())) {
klog() << "VFS::mount_root failed"; PANIC("VFS::mount_root failed");
Processor::halt();
} }
Process::current()->set_root_directory(VFS::the().root_custody()); Process::current()->set_root_directory(VFS::the().root_custody());
@ -307,8 +307,7 @@ void init_stage2(void*)
init_args.prepend(userspace_init); 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); Process::create_user_process(thread, userspace_init, (uid_t)0, (gid_t)0, ProcessID(0), error, move(init_args), {}, tty0);
if (error != 0) { if (error != 0) {
klog() << "init_stage2: error spawning SystemServer: " << error; PANIC("init_stage2: Error spawning SystemServer: {}", error);
Processor::halt();
} }
thread->set_priority(THREAD_PRIORITY_HIGH); thread->set_priority(THREAD_PRIORITY_HIGH);