diff --git a/Core/Crash/CrashHandler.cpp b/Core/Crash/CrashHandler.cpp index 42bcafe..7c83d7d 100644 --- a/Core/Crash/CrashHandler.cpp +++ b/Core/Crash/CrashHandler.cpp @@ -670,23 +670,7 @@ namespace CrashHandler ExceptionOccurred = true; if (DriverManager) - { - KernelCallback callback; - foreach (Driver::DriverFile *drv in DriverManager->GetDrivers()) - { - memset(&callback, 0, sizeof(KernelCallback)); - callback.Reason = StopReason; - debug("Stopping driver %ld...", drv->DriverUID); - 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]; - } - } - } + DriverManager->UnloadAllDrivers(); debug("Reading control registers..."); crashdata.Frame = Frame; diff --git a/Core/Driver/Driver.cpp b/Core/Driver/Driver.cpp index 602bef2..8bb5f07 100644 --- a/Core/Driver/Driver.cpp +++ b/Core/Driver/Driver.cpp @@ -28,6 +28,26 @@ namespace Driver "Input", "Audio"}; + void Driver::UnloadAllDrivers() + { + KernelCallback callback; + debug("%ld drivers loaded, [DUIDs: %ld]", DriverManager->GetDrivers().size(), DriverUIDs); + foreach (DriverFile *drv in DriverManager->GetDrivers()) + { + memset(&callback, 0, sizeof(KernelCallback)); + callback.Reason = StopReason; + debug("Stopping & unloading driver %ld [%#lx]", drv->DriverUID, drv->Address); + 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]; + } + } + } + int Driver::IOCB(unsigned long DUID, void *KCB) { foreach (auto var in Drivers) diff --git a/Core/Driver/DriverLoading/BindInput.cpp b/Core/Driver/DriverLoading/BindInput.cpp index 412fd4b..574027b 100644 --- a/Core/Driver/DriverLoading/BindInput.cpp +++ b/Core/Driver/DriverLoading/BindInput.cpp @@ -64,7 +64,7 @@ namespace Driver KernelAllocator.FreePages(KCallback, TO_PAGES(sizeof(KernelCallback))); DriverFile *DrvFile = new DriverFile; - DrvFile->DriverUID = KAPI.Info.DriverUID; + DrvFile->DriverUID = this->DriverUIDs - 1; DrvFile->Address = (void *)fex; DrvFile->InterruptHook[0] = nullptr; Drivers.push_back(DrvFile); diff --git a/Core/Driver/DriverLoading/BindInterrupt.cpp b/Core/Driver/DriverLoading/BindInterrupt.cpp index 3c5df78..e545299 100644 --- a/Core/Driver/DriverLoading/BindInterrupt.cpp +++ b/Core/Driver/DriverLoading/BindInterrupt.cpp @@ -42,7 +42,7 @@ namespace Driver { fixme("Generic driver: %s", fexExtended->Driver.Name); DriverFile *DrvFile = new DriverFile; - DrvFile->DriverUID = KAPI.Info.DriverUID; + DrvFile->DriverUID = this->DriverUIDs - 1; DrvFile->Address = (void *)fex; Drivers.push_back(DrvFile); break; @@ -142,7 +142,7 @@ namespace Driver KCallback->Reason = CallbackReason::InterruptReason; DriverFile *DrvFile = new DriverFile; - DrvFile->DriverUID = KAPI.Info.DriverUID; + DrvFile->DriverUID = this->DriverUIDs - 1; DrvFile->Address = (void *)fex; DrvFile->InterruptHook[0] = InterruptHook; Drivers.push_back(DrvFile); diff --git a/Core/Driver/DriverLoading/BindPCI.cpp b/Core/Driver/DriverLoading/BindPCI.cpp index 4272736..d661a31 100644 --- a/Core/Driver/DriverLoading/BindPCI.cpp +++ b/Core/Driver/DriverLoading/BindPCI.cpp @@ -121,7 +121,7 @@ namespace Driver KCallback->Reason = CallbackReason::InterruptReason; DriverFile *DrvFile = new DriverFile; - DrvFile->DriverUID = KAPI.Info.DriverUID; + DrvFile->DriverUID = this->DriverUIDs - 1; DrvFile->Address = (void *)fex; DrvFile->InterruptHook[0] = InterruptHook; Drivers.push_back(DrvFile); @@ -150,7 +150,7 @@ namespace Driver } DriverFile *DrvFile = new DriverFile; - DrvFile->DriverUID = KAPI.Info.DriverUID; + DrvFile->DriverUID = this->DriverUIDs - 1; DrvFile->Address = (void *)fex; DrvFile->InterruptHook[0] = nullptr; Drivers.push_back(DrvFile); diff --git a/KThread.cpp b/KThread.cpp index e819eec..d03f48b 100644 --- a/KThread.cpp +++ b/KThread.cpp @@ -83,23 +83,8 @@ Exit: void KernelShutdownThread(bool Reboot) { if (DriverManager) - { - KernelCallback callback; - foreach (Driver::DriverFile *drv in DriverManager->GetDrivers()) - { - memset(&callback, 0, sizeof(KernelCallback)); - callback.Reason = StopReason; - debug("Stopping driver %ld...", drv->DriverUID); - DriverManager->IOCB(drv->DriverUID, (void *)&callback); + DriverManager->UnloadAllDrivers(); - 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..."); if (Reboot) PowerManager->Reboot(); diff --git a/include/driver.hpp b/include/driver.hpp index e710c13..4d21652 100644 --- a/include/driver.hpp +++ b/include/driver.hpp @@ -63,6 +63,7 @@ namespace Driver public: Vector GetDrivers() { return Drivers; } + void UnloadAllDrivers(); int IOCB(unsigned long DUID, /* KernelCallback */ void *KCB); DriverCode LoadDriver(uint64_t DriverAddress, uint64_t Size); DriverCode StartDrivers();