Stop all drivers on shutdown / crash

This commit is contained in:
Alex 2022-12-15 14:16:22 +02:00
parent 2ed1bf05a0
commit ad61c7acc5
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 37 additions and 4 deletions

View File

@ -18,6 +18,7 @@
#endif #endif
#include "../../kernel.h" #include "../../kernel.h"
#include "../../DAPI.hpp"
NewLock(UserInputLock); NewLock(UserInputLock);
@ -609,9 +610,7 @@ namespace CrashHandler
{ {
SBIdx = 255; SBIdx = 255;
Display->ClearBuffer(SBIdx); Display->ClearBuffer(SBIdx);
debug("e0-1");
Display->SetBufferCursor(SBIdx, 0, 0); Display->SetBufferCursor(SBIdx, 0, 0);
debug("e0-2");
CPU::x64::CR0 cr0 = CPU::x64::readcr0(); CPU::x64::CR0 cr0 = CPU::x64::readcr0();
CPU::x64::CR2 cr2 = CPU::x64::readcr2(); CPU::x64::CR2 cr2 = CPU::x64::readcr2();
@ -664,12 +663,29 @@ namespace CrashHandler
EHPrint("\nException occurred while handling exception! HALTED!"); EHPrint("\nException occurred while handling exception! HALTED!");
Display->SetBuffer(SBIdx); Display->SetBuffer(SBIdx);
Interrupts::RemoveAll();
CPU::Stop(); CPU::Stop();
} }
ExceptionOccurred = true; ExceptionOccurred = true;
/* TODO: Remove all useless interrupts, and only leave the ones that are needed (dsdt, acpi, etc.) */
Interrupts::RemoveAll(); if (DriverManager)
foreach (Driver::DriverFile *drv in DriverManager->GetDrivers())
{
if (!drv)
continue;
KernelCallback callback;
memset(&callback, 0, sizeof(KernelCallback));
callback.Reason = StopReason;
DriverManager->IOCB(drv->DriverUID, (void *)&callback);
for (size_t i = 0; i < sizeof(drv->InterruptHook) / sizeof(drv->InterruptHook[0]); i++)
{
if (!drv->InterruptHook[i])
continue;
delete drv->InterruptHook[i];
}
}
debug("Reading control registers..."); debug("Reading control registers...");
crashdata.Frame = Frame; crashdata.Frame = Frame;

View File

@ -77,6 +77,23 @@ Exit:
void KernelShutdownThread(bool Reboot) void KernelShutdownThread(bool Reboot)
{ {
if (DriverManager)
foreach (Driver::DriverFile *drv in DriverManager->GetDrivers())
{
if (!drv)
continue;
KernelCallback callback;
memset(&callback, 0, sizeof(KernelCallback));
callback.Reason = StopReason;
DriverManager->IOCB(drv->DriverUID, (void *)&callback);
for (size_t i = 0; i < sizeof(drv->InterruptHook) / sizeof(drv->InterruptHook[0]); i++)
{
if (!drv->InterruptHook[i])
continue;
delete drv->InterruptHook[i];
}
}
trace("Shutting Down/Rebooting..."); trace("Shutting Down/Rebooting...");
if (Reboot) if (Reboot)
PowerManager->Reboot(); PowerManager->Reboot();