Added ForceUnlock boolean

This commit is contained in:
Alex 2023-02-18 04:11:28 +02:00
parent 95a78ef939
commit 476e97baf1
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
3 changed files with 18 additions and 23 deletions

View File

@ -738,6 +738,7 @@ namespace CrashHandler
debug("Exception in kernel mode (ip: %#lx (%s), cr2: %#lx)", Frame->rip, KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress(Frame->rip) : "No symbol", PageFaultAddress); debug("Exception in kernel mode (ip: %#lx (%s), cr2: %#lx)", Frame->rip, KernelSymbolTable ? KernelSymbolTable->GetSymbolFromAddress(Frame->rip) : "No symbol", PageFaultAddress);
if (TaskManager) if (TaskManager)
TaskManager->Panic(); TaskManager->Panic();
ForceUnlock = true;
Display->CreateBuffer(0, 0, SBIdx); Display->CreateBuffer(0, 0, SBIdx);
} }
else else
@ -746,6 +747,7 @@ namespace CrashHandler
CPUData *data = GetCurrentCPU(); CPUData *data = GetCurrentCPU();
if (!data) if (!data)
{ {
ForceUnlock = true;
Display->CreateBuffer(0, 0, SBIdx); Display->CreateBuffer(0, 0, SBIdx);
EHPrint("\eFF0000Cannot get CPU data! This results in a kernel crash!"); EHPrint("\eFF0000Cannot get CPU data! This results in a kernel crash!");
error("Cannot get CPU data! This results in a kernel crash!"); error("Cannot get CPU data! This results in a kernel crash!");
@ -759,6 +761,7 @@ namespace CrashHandler
debug("Critical thread \"%s\"(%d) died", data->CurrentThread->Name, data->CurrentThread->ID); debug("Critical thread \"%s\"(%d) died", data->CurrentThread->Name, data->CurrentThread->ID);
if (TaskManager) if (TaskManager)
TaskManager->Panic(); TaskManager->Panic();
ForceUnlock = true;
Display->CreateBuffer(0, 0, SBIdx); Display->CreateBuffer(0, 0, SBIdx);
} }
else else
@ -890,8 +893,8 @@ namespace CrashHandler
if (TaskManager && cpudata != nullptr) if (TaskManager && cpudata != nullptr)
{ {
crashdata.Process = cpudata->CurrentProcess; crashdata.Process = cpudata->CurrentProcess.Load();
crashdata.Thread = cpudata->CurrentThread; crashdata.Thread = cpudata->CurrentThread.Load();
error("Current Process: %s(%ld)", error("Current Process: %s(%ld)",
cpudata->CurrentProcess->Name, cpudata->CurrentProcess->Name,

View File

@ -5,8 +5,18 @@
#include "../kernel.h" #include "../kernel.h"
bool ForceUnlock = false;
void LockClass::DeadLock(SpinLockData Lock) void LockClass::DeadLock(SpinLockData Lock)
{ {
if (ForceUnlock)
{
warn("Unlocking lock '%s' which it was held by '%s'...", Lock.AttemptingToGet, Lock.CurrentHolder);
this->DeadLocks = 0;
this->Unlock();
return;
}
CPUData *CoreData = GetCurrentCPU(); CPUData *CoreData = GetCurrentCPU();
long CCore = 0xdead; long CCore = 0xdead;
if (CoreData != nullptr) if (CoreData != nullptr)
@ -33,19 +43,6 @@ void LockClass::DeadLock(SpinLockData Lock)
int LockClass::Lock(const char *FunctionName) int LockClass::Lock(const char *FunctionName)
{ {
// LockData.AttemptingToGet = FunctionName;
// SpinLock_Lock(&LockData.LockData);
// LockData.Count++;
// LockData.CurrentHolder = FunctionName;
// CPUData *CoreData = GetCurrentCPU();
// if (CoreData != nullptr)
// LockData.Core = CoreData->ID;
// __sync_synchronize();
// while (!__sync_bool_compare_and_swap(&IsLocked, false, true))
// CPU::Pause();
// __sync_synchronize();
LockData.AttemptingToGet = FunctionName; LockData.AttemptingToGet = FunctionName;
Retry: Retry:
unsigned int i = 0; unsigned int i = 0;
@ -68,14 +65,6 @@ Retry:
int LockClass::Unlock() int LockClass::Unlock()
{ {
// SpinLock_Unlock(&LockData.LockData);
// LockData.Count--;
// __sync_synchronize();
// __sync_synchronize();
// __atomic_store_n(&IsLocked, false, __ATOMIC_SEQ_CST);
// IsLocked = false;
__sync_synchronize(); __sync_synchronize();
IsLocked.Store(false, MemoryOrder::Release); IsLocked.Store(false, MemoryOrder::Release);
LockData.Count--; LockData.Count--;

View File

@ -8,6 +8,9 @@
#ifdef __cplusplus #ifdef __cplusplus
/* Enabled ONLY on crash. */
extern bool ForceUnlock;
/** @brief Please use this macro to create a new lock. */ /** @brief Please use this macro to create a new lock. */
class LockClass class LockClass
{ {