diff --git a/Core/Lock.cpp b/Core/Lock.cpp index 6203d8d..6b59a06 100644 --- a/Core/Lock.cpp +++ b/Core/Lock.cpp @@ -52,9 +52,9 @@ int LockClass::Lock(const char *FunctionName) LockData.StackPointerAttempt = (uintptr_t)__builtin_frame_address(0); Retry: unsigned int i = 0; - while (IsLocked.Exchange(true, MemoryOrder::Acquire) && ++i < 0x10000000) + while (IsLocked.Exchange(true, MemoryOrder::Acquire) && ++i < (DebuggerIsAttached ? 0x100000 : 0x10000000)) CPU::Pause(); - if (i >= 0x10000000) + if (i >= (DebuggerIsAttached ? 0x100000 : 0x10000000)) { DeadLock(LockData); goto Retry; @@ -89,15 +89,14 @@ void LockClass::TimeoutDeadLock(SpinLockData Lock, uint64_t Timeout) if (CoreData != nullptr) CCore = CoreData->ID; - warn("Potential deadlock in lock '%s' held by '%s'! %ld %s in queue. Interrupts are %s. Core %ld is being held by %ld. Timeout in %ld", + uint64_t Counter = TimeManager->GetCounter(); + + warn("Potential deadlock in lock '%s' held by '%s'! %ld %s in queue. Interrupts are %s. Core %ld is being held by %ld. Timeout in %ld (%ld ticks remaining).", Lock.AttemptingToGet, Lock.CurrentHolder, Lock.Count, Lock.Count > 1 ? "locks" : "lock", CPU::Interrupts(CPU::Check) ? "enabled" : "disabled", - CCore, Lock.Core, this->DeadLocks, Timeout); + CCore, Lock.Core, Timeout, Timeout - Counter); - // TODO: Print on screen too. - - uint64_t Counter = TimeManager->GetCounter(); if (Timeout < Counter) { warn("Unlocking lock '%s' because of timeout. (%ld < %ld)", Lock.AttemptingToGet, Timeout, Counter); @@ -117,13 +116,13 @@ int LockClass::TimeoutLock(const char *FunctionName, uint64_t Timeout) Atomic Target = 0; Retry: unsigned int i = 0; - while (IsLocked.Exchange(true, MemoryOrder::Acquire) && ++i < 0x10000000) + while (IsLocked.Exchange(true, MemoryOrder::Acquire) && ++i < (DebuggerIsAttached ? 0x100000 : 0x10000000)) CPU::Pause(); - if (i >= 0x10000000) + if (i >= (DebuggerIsAttached ? 0x100000 : 0x10000000)) { - if (Target == 0) - Target = TimeManager->CalculateTarget(Timeout); - TimeoutDeadLock(LockData, Target); + if (Target.Load() == 0) + Target.Store(TimeManager->CalculateTarget(Timeout)); + TimeoutDeadLock(LockData, Target.Load()); goto Retry; } LockData.Count++; diff --git a/Kernel.cpp b/Kernel.cpp index ed08420..e3f8371 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -15,6 +15,8 @@ #include "Core/smbios.hpp" #include "Tests/t.h" +bool DebuggerIsAttached = false; + #ifdef DEBUG bool EnableExternalMemoryTracer = false; /* This can be modified while we are debugging with GDB. */ char mExtTrkLog[MEM_TRK_MAX_SIZE]; @@ -182,6 +184,13 @@ EXTERNC NIF void Main(BootInfo *Info) Interrupts::Initialize(0); KPrint("Initializing CPU Features"); CPU::InitializeFeatures(0); + + if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0) + { + KPrint("\eFFA500Debugger detected! (TCG Virtual Machine)"); + DebuggerIsAttached = true; + } + KPrint("Loading Kernel Symbols"); KernelSymbolTable = new SymbolResolver::Symbols((uintptr_t)Info->Kernel.FileBase); KPrint("Reading Kernel Parameters"); diff --git a/Tests/MemoryAllocation.cpp b/Tests/MemoryAllocation.cpp index 38f9a68..f0c28ea 100644 --- a/Tests/MemoryAllocation.cpp +++ b/Tests/MemoryAllocation.cpp @@ -28,12 +28,13 @@ test_mem_new_delete::~test_mem_new_delete() } extern bool EnableExternalMemoryTracer; +extern bool DebuggerIsAttached; void TestMemoryAllocation() { - if (EnableExternalMemoryTracer) + if (EnableExternalMemoryTracer || DebuggerIsAttached) { - debug("The test is disabled when the external memory tracer is enabled."); + debug("The test is disabled when the external memory tracer or a debugger is enabled."); return; } diff --git a/kernel.h b/kernel.h index 82e8c64..0d4972d 100644 --- a/kernel.h +++ b/kernel.h @@ -20,6 +20,7 @@ #endif extern struct BootInfo *bInfo; +extern bool DebuggerIsAttached; #ifdef __cplusplus #ifdef DEBUG