From 98677c7b5b8168a4debab71b63fff195a5491e0f Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 27 Mar 2023 20:30:03 +0300 Subject: [PATCH] Unhook interrupts from every driver on crash --- Core/Crash/CrashHandler.cpp | 2 +- Core/Driver/Driver.cpp | 22 ++++++++++++++++++++++ include/driver.hpp | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Core/Crash/CrashHandler.cpp b/Core/Crash/CrashHandler.cpp index 247c88c..e72b5f8 100644 --- a/Core/Crash/CrashHandler.cpp +++ b/Core/Crash/CrashHandler.cpp @@ -917,7 +917,7 @@ namespace CrashHandler ExceptionOccurred = true; if (DriverManager) - DriverManager->UnloadAllDrivers(); + DriverManager->Panic(); debug("Reading control registers..."); crashdata.Frame = Frame; diff --git a/Core/Driver/Driver.cpp b/Core/Driver/Driver.cpp index 4ad539d..3564811 100644 --- a/Core/Driver/Driver.cpp +++ b/Core/Driver/Driver.cpp @@ -29,6 +29,28 @@ namespace Driver "Input", "Audio"}; + void Driver::Panic() + { + size_t DriversNum = Drivers.size(); + debug("%ld drivers loaded, [DUIDs: %ld]", DriversNum, DriverUIDs); + debug("driver size %ld", DriversNum); + for (size_t i = 0; i < DriversNum; i++) + { + DriverFile drv = Drivers[i]; + KernelCallback callback; + callback.Reason = StopReason; + debug("Removing interrupt hook for %ld [%#lx]", drv.DriverUID, drv.Address); + DriverManager->IOCB(drv.DriverUID, (void *)&callback); + + for (size_t j = 0; j < sizeof(drv.InterruptHook) / sizeof(drv.InterruptHook[0]); j++) + { + if (!drv.InterruptHook[j]) + continue; + delete drv.InterruptHook[j], drv.InterruptHook[j] = nullptr; + } + } + } + void Driver::UnloadAllDrivers() { size_t DriversNum = Drivers.size(); diff --git a/include/driver.hpp b/include/driver.hpp index 69e2bee..1539639 100644 --- a/include/driver.hpp +++ b/include/driver.hpp @@ -102,6 +102,7 @@ namespace Driver public: std::vector GetDrivers() { return Drivers; } + void Panic(); void UnloadAllDrivers(); bool UnloadDriver(unsigned long DUID); int IOCB(unsigned long DUID, /* KernelCallback */ void *KCB);