From d8e000b5c32281dd09221bd28a80b133cc7b867f Mon Sep 17 00:00:00 2001 From: Reece Date: Thu, 27 Jan 2022 20:25:04 +0000 Subject: [PATCH] [*] Prevent WriteLater from entering a deadlock condition. OnFlushs are no longer atomic [*] Fix up gen1 copypasta [+] ConsoleMessage::ToPersistentString [*] Adjust ConsoleMessage formatting --- Include/Aurora/Console/ConsoleMessage.hpp | 2 + Include/Aurora/HWInfo/CpuBitId.hpp | 1 + Include/Aurora/HWInfo/CpuBitId.inl | 12 ++++++ Include/Aurora/IO/Net/Net.hpp | 8 ++-- Source/Console/ConsoleFIO/ConsoleFIO.cpp | 26 +++++++++--- Source/Console/ConsoleFIO/ConsoleFIO.hpp | 1 + Source/Console/ConsoleFIO/FileSink.cpp | 2 +- Source/Console/ConsoleMessage.cpp | 52 ++++++++++++++++++++--- Source/Console/Logging/Logger.cpp | 44 +++++++++++-------- Source/Debug/Debug.cpp | 1 - Source/Debug/Debug.hpp | 7 +-- Source/Debug/ExceptionWatcher.NT.cpp | 18 ++++---- Source/Debug/ExceptionWatcher.Win32.cpp | 20 +++++---- Source/Debug/ExceptionWatcher.Win32.hpp | 2 +- Source/HWInfo/CpuId.cpp | 52 +++++++++++------------ Source/HWInfo/CpuInfo.NT.cpp | 1 - 16 files changed, 165 insertions(+), 84 deletions(-) diff --git a/Include/Aurora/Console/ConsoleMessage.hpp b/Include/Aurora/Console/ConsoleMessage.hpp index 63360ff8..ee1980e8 100644 --- a/Include/Aurora/Console/ConsoleMessage.hpp +++ b/Include/Aurora/Console/ConsoleMessage.hpp @@ -48,8 +48,10 @@ namespace Aurora::Console } AUKN_SYM AuString StringifyTime(bool simple = false) const; + AUKN_SYM AuString StringifyTimeUTC() const; AUKN_SYM AuString GetWrappedTag() const; AUKN_SYM AuString ToConsole() const; + AUKN_SYM AuString ToPersistentString() const; AUKN_SYM AuString ToSimplified() const; }; } \ No newline at end of file diff --git a/Include/Aurora/HWInfo/CpuBitId.hpp b/Include/Aurora/HWInfo/CpuBitId.hpp index 79957afa..11bd74af 100644 --- a/Include/Aurora/HWInfo/CpuBitId.hpp +++ b/Include/Aurora/HWInfo/CpuBitId.hpp @@ -29,6 +29,7 @@ namespace Aurora::HWInfo inline CpuBitId Not() const; inline CpuBitId And(const CpuBitId &id) const; inline CpuBitId Xor(const CpuBitId &id) const; + inline CpuBitId Or(const CpuBitId &id) const; inline bool CpuBitScanForward(AuUInt8 &index, AuUInt8 offset) const; diff --git a/Include/Aurora/HWInfo/CpuBitId.inl b/Include/Aurora/HWInfo/CpuBitId.inl index 856e5b83..11a35320 100644 --- a/Include/Aurora/HWInfo/CpuBitId.inl +++ b/Include/Aurora/HWInfo/CpuBitId.inl @@ -117,6 +117,18 @@ namespace Aurora::HWInfo return ret; } + CpuBitId CpuBitId::Or(const CpuBitId &id) const + { + CpuBitId ret = *this; + ret.lower |= id.lower; + ret.upper |= id.upper; + #if defined(_AU_MASSIVE_CPUID) + ret.upper2 |= id.upper2; + ret.upper3 |= id.upper3; + #endif + return ret; + } + CpuBitId &CpuBitId::operator=(const CpuBitId &id) { lower = id.lower; diff --git a/Include/Aurora/IO/Net/Net.hpp b/Include/Aurora/IO/Net/Net.hpp index ba3cbaf4..da6c4c08 100644 --- a/Include/Aurora/IO/Net/Net.hpp +++ b/Include/Aurora/IO/Net/Net.hpp @@ -437,12 +437,12 @@ namespace Aurora::IO::Net AUE_DEFINE(ENetworkPoolModel, ( + // Do not attach to a thread subsystem + eNoHooks, + /// given a group id, uses prespawned async application event queues eAsyncApp, - /// - eAsyncThreadPool, - /// it just werks eInternalThreadPool, @@ -456,7 +456,7 @@ namespace Aurora::IO::Net ENetworkPoolModel mode; - AuUInt8 asyncWorkGroup; + AuUInt8 asyncWorkGroup {}; AuUInt8 asyncWorkerIdOffset {}; AuSPtr threadPool; diff --git a/Source/Console/ConsoleFIO/ConsoleFIO.cpp b/Source/Console/ConsoleFIO/ConsoleFIO.cpp index 56f7fb1f..d48735cb 100644 --- a/Source/Console/ConsoleFIO/ConsoleFIO.cpp +++ b/Source/Console/ConsoleFIO/ConsoleFIO.cpp @@ -16,7 +16,7 @@ namespace Aurora::Console::ConsoleFIO static const auto &gLogConfig = gRuntimeConfig.console.fio; - AuString GetLogDirectory() + static AuString GetLogDirectory(const AuString &type) { AuString path; AuString procName; @@ -26,17 +26,31 @@ namespace Aurora::Console::ConsoleFIO path = "."; } - if (!Process::GetProcName(procName)) + path += "/" + type + "/"; + + if (Process::GetProcName(procName)) { - procName = "Unknown"; + path += procName; + path.push_back('/'); + } + else + { + path += "Unknown/"; } - path += "/Logs/"; - path += procName; - return path; } + AuString GetLogDirectory() + { + return GetLogDirectory("Logs"); + } + + AuString GetTelemetryDirectory() + { + return GetLogDirectory("Telemetry"); + } + static void EraseFilesByTimestamp(const AuString &path, /*const its not worth reallocation*/ AuList &files) { if (files.size() <= gLogConfig.maxLogs) diff --git a/Source/Console/ConsoleFIO/ConsoleFIO.hpp b/Source/Console/ConsoleFIO/ConsoleFIO.hpp index 8f0f0a90..ec30d163 100644 --- a/Source/Console/ConsoleFIO/ConsoleFIO.hpp +++ b/Source/Console/ConsoleFIO/ConsoleFIO.hpp @@ -14,5 +14,6 @@ namespace Aurora::Console::ConsoleFIO void Exit(); void Flush(); AuString GetLogDirectory(); + AuString GetTelemetryDirectory(); void FIOCleanup(); } \ No newline at end of file diff --git a/Source/Console/ConsoleFIO/FileSink.cpp b/Source/Console/ConsoleFIO/FileSink.cpp index 7f25fd5e..59242cab 100644 --- a/Source/Console/ConsoleFIO/FileSink.cpp +++ b/Source/Console/ConsoleFIO/FileSink.cpp @@ -25,7 +25,7 @@ namespace Aurora::Console::ConsoleFIO void FIOSink::OnMessageBlocking(AuUInt8 level, const ConsoleMessage &msg) { AU_LOCK_GUARD(logMutex_->AsWritable()); - auto str = msg.ToSimplified(); + auto str = msg.ToPersistentString(); logBuffer_.reserve(logBuffer_.size() + str.size() + 2); diff --git a/Source/Console/ConsoleMessage.cpp b/Source/Console/ConsoleMessage.cpp index 5fa12807..ffea2926 100644 --- a/Source/Console/ConsoleMessage.cpp +++ b/Source/Console/ConsoleMessage.cpp @@ -28,13 +28,13 @@ namespace Aurora::Console "\033[0m" }; - AuString ConsoleMessage::StringifyTime(bool simple) const + static AuString StringifyTimeEx(const ConsoleMessage &msg, bool simple, bool utc) { try { std::tm localized; - Aurora::Time::ToCivilTime(time, false).CopyTo(localized); + Aurora::Time::ToCivilTime(msg.time, utc).CopyTo(localized); if (simple) { @@ -51,6 +51,30 @@ namespace Aurora::Console } } + AuString ConsoleMessage::StringifyTime(bool simple) const + { + try + { + return StringifyTimeEx(*this, simple, false); + } + catch (...) + { + return {}; + } + } + + AuString ConsoleMessage::StringifyTimeUTC() const + { + try + { + return StringifyTimeEx(*this, false, true); + } + catch (...) + { + return {}; + } + } + AuString ConsoleMessage::GetWrappedTag() const { return "[" + prefix + "]"; @@ -60,11 +84,11 @@ namespace Aurora::Console { try { - return fmt::format("{}[{}] {:<7} | {}{}", + return fmt::format("{}[{}] {:<8} | {}{}", static_cast(color) <= EAnsiColor::eCount ? kAnsiCheats[static_cast(color)] : "", - StringifyTime(), + StringifyTime(true), GetWrappedTag(), line, kAnsiCheats[static_cast(EAnsiColor::eReset)]); @@ -75,12 +99,30 @@ namespace Aurora::Console } } + + + AuString ConsoleMessage::ToPersistentString() const + { + try + { + + return fmt::format("[{}] {:<7} | {}", + StringifyTimeUTC(), + GetWrappedTag(), + line); + } + catch (...) + { + return {}; + } + + } AuString ConsoleMessage::ToSimplified() const { try { - return fmt::format("{:<9} {:<7} | {}", StringifyTime(true), GetWrappedTag(), line); + return fmt::format("{:<9} {:<8} | {}", StringifyTime(true), GetWrappedTag(), line); } catch (...) { diff --git a/Source/Console/Logging/Logger.cpp b/Source/Console/Logging/Logger.cpp index 59873096..ef4a0a06 100644 --- a/Source/Console/Logging/Logger.cpp +++ b/Source/Console/Logging/Logger.cpp @@ -121,22 +121,26 @@ namespace Aurora::Console::Logging void ForceFlushLoggers() { - AU_LOCK_GUARD(gGlobalSpin); + decltype(gLogTasks) logTasks; - try { + AU_LOCK_GUARD(gGlobalSpin); - logTasks = AuExchange(gLogTasks, {}); - } - catch (...) - { + try + { - } + logTasks = AuExchange(gLogTasks, {}); + } + catch (...) + { - if (logTasks.empty()) - { - return; + } + + if (logTasks.empty()) + { + return; + } } try @@ -156,17 +160,21 @@ namespace Aurora::Console::Logging } - for (const auto &logger : gFlushableLoggers) { - for (const auto &sink : logger->sinks) + AU_LOCK_GUARD(gGlobalSpin); + + for (const auto &logger : gFlushableLoggers) { - try + for (const auto &sink : logger->sinks) { - sink->OnFlush(); - } - catch (...) - { - SysPushErrorGeneric("..."); + try + { + sink->OnFlush(); + } + catch (...) + { + SysPushErrorGeneric("..."); + } } } } diff --git a/Source/Debug/Debug.cpp b/Source/Debug/Debug.cpp index 8fd9f590..285617d1 100644 --- a/Source/Debug/Debug.cpp +++ b/Source/Debug/Debug.cpp @@ -80,7 +80,6 @@ namespace Aurora::Debug return lastError = ret; } - AuOptional TryGetOrFetchOSError() { static AuOptional lastErrorError; diff --git a/Source/Debug/Debug.hpp b/Source/Debug/Debug.hpp index ead453a4..44f2b703 100644 --- a/Source/Debug/Debug.hpp +++ b/Source/Debug/Debug.hpp @@ -16,20 +16,17 @@ namespace Aurora::Debug AuString dbg; }; - AuUInt32 GetOSErrorFence(); AuOptional TryGetOrFetchOSError(); AuUInt32 GetCErrorFence(); AuOptional TryGetOrFetchCError(); - - AuUInt32 ReportStackTrace(const StackTrace &trace, const AuString &message); - - AuOptional TryFetchOSError(); AuOptional TryFetchCError(); + AuUInt32 ReportStackTrace(const StackTrace &trace, const AuString &message); + void CheckErrors(); void PlatformHandleFatal(bool fatal); void InitDebug(); diff --git a/Source/Debug/ExceptionWatcher.NT.cpp b/Source/Debug/ExceptionWatcher.NT.cpp index 18d6be5c..304b74fa 100644 --- a/Source/Debug/ExceptionWatcher.NT.cpp +++ b/Source/Debug/ExceptionWatcher.NT.cpp @@ -143,11 +143,6 @@ namespace Aurora::Debug { static bool handlingFatal = false; - if (std::exchange(handlingFatal, true)) - { - std::terminate(); - } - #if defined(DEBUG) || defined(INTERNAL) if (!fatal) { @@ -156,7 +151,7 @@ namespace Aurora::Debug } else { - SaveMinidump(pExceptionInfo); + SaveMinidump(pExceptionInfo, true); } #else BlackboxReport(pExceptionInfo, true); @@ -194,8 +189,15 @@ static thread_local AuUInt tlsThrowCounter; extern "C" AUKN_SYM void __stdcall _ReportMSVCSEH(void *exception, const void *throwInfo, void *caller) { - if (!throwInfo) return; - if (!exception) return; + if (!throwInfo) + { + return; + } + + if (!exception) + { + return; + } HMODULE handle = 0; diff --git a/Source/Debug/ExceptionWatcher.Win32.cpp b/Source/Debug/ExceptionWatcher.Win32.cpp index 56fa50fc..c1db50b6 100644 --- a/Source/Debug/ExceptionWatcher.Win32.cpp +++ b/Source/Debug/ExceptionWatcher.Win32.cpp @@ -24,6 +24,8 @@ #include #include +#include + static thread_local int gDebugLocked = 0; namespace Aurora::Debug @@ -112,7 +114,6 @@ namespace Aurora::Debug return EXCEPTION_CONTINUE_SEARCH; } - auto minimal = gDebugLocked++; if (minimal >= 5) @@ -194,6 +195,8 @@ namespace Aurora::Debug { PlatformHandleFatal(true); } + + Console::ForceFlush(); } catch (...) { @@ -219,9 +222,9 @@ namespace Aurora::Debug try { auto tm = Time::ToCivilTime(Time::CurrentClockMS()); - return fmt::format("{}-{}-{}T{}-{}-{}Z_{}.dmp", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - exeName); + return fmt::format("{}-{}-{}T{}-{}-{}Z_{}.dmp", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, + exeName); } catch (...) { @@ -230,7 +233,7 @@ namespace Aurora::Debug } #if defined(DEBUG) || defined(INTERNAL) - void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo) + void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo, bool isFatal) { bool ok {}; MINIDUMP_EXCEPTION_INFORMATION info; @@ -288,9 +291,10 @@ namespace Aurora::Debug { } - __debugbreak(); - - __fastfail('fokd'); + if (isFatal) + { + __fastfail('fokd'); + } } #endif diff --git a/Source/Debug/ExceptionWatcher.Win32.hpp b/Source/Debug/ExceptionWatcher.Win32.hpp index a70c95c5..894b5629 100644 --- a/Source/Debug/ExceptionWatcher.Win32.hpp +++ b/Source/Debug/ExceptionWatcher.Win32.hpp @@ -12,7 +12,7 @@ namespace Aurora::Debug void InitWin32(); #if defined(DEBUG) || defined(INTERNAL) - void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo); + void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo, bool isFatal); #endif void BlackboxReport(_EXCEPTION_POINTERS *ExceptionInfo, bool isFatal); } \ No newline at end of file diff --git a/Source/HWInfo/CpuId.cpp b/Source/HWInfo/CpuId.cpp index c088a02e..b1574b87 100644 --- a/Source/HWInfo/CpuId.cpp +++ b/Source/HWInfo/CpuId.cpp @@ -320,32 +320,32 @@ namespace Aurora::HWInfo AuString CpuId::ToString() const { return fmt::format( - "FMA {}\t\tFSGSBASE {}\t\tCLFSH {}\t\tERMS {}{}" - "CMPXCHG16B {}\t\tAVX512PF {}\t\tMOVBE {}\t\tRTM {}{}" - "POPCNT {}\t\tAVX512ER {}\t\tMONITOR {}\t\tLAHF {}{}" - "SSE {}\t\tAVX512CD {}\t\tF16C {}\t\tABM {}{}" - "SSE2 {}\t\tSYSCALL {}\t\tRDRAND {}\t\tXOP {}{}" - "SSE3 {}\t\tAES {}\t\tMSR {}\t\tTBM {}{}" - "SSSE3 {}\t\tRDTSCP {}\t\tCX8 {}\t\tMMXEXT {}{}" - "SSE41 {}\t\tXSAVE {}\t\tSEP {}\t\tRDSEED {}{}" - "SSE42 {}\t\tOSXSAVE {}\t\tCMOV {}\t\tPREFETCHWT1 {}{}" - "SSE4a {}\t\tSHA {}\t\tFXSR {}\t\tPCLMULQDQ {}{}" - "AVX {}\t\tAVX512F {}\t\tBMI1 {}\t\tINVPCID {}{}" - "AVX2 {}\t\tLZCNT {}\t\tHLE {}\t\t_3DNOWEXT {}{}" - "MMX {}\t\tADX {}\t\tBMI2 {}\t\t_3DNOW {}", - FMA(), FSGSBASE(), CLFSH(), ERMS(), Aurora::Locale::NewLine(), - CMPXCHG16B(), AVX512PF(), MOVBE(), RTM(), Aurora::Locale::NewLine(), - POPCNT(), AVX512ER(), MONITOR(), LAHF(), Aurora::Locale::NewLine(), - SSE(), AVX512CD(), F16C(), ABM(), Aurora::Locale::NewLine(), - SSE2(), SYSCALL(), RDRAND(), XOP(), Aurora::Locale::NewLine(), - SSE3(), AES(), MSR(), TBM(), Aurora::Locale::NewLine(), - SSSE3(), RDTSCP(), CX8(), MMXEXT(), Aurora::Locale::NewLine(), - SSE41(), XSAVE(), SEP(), RDSEED(), Aurora::Locale::NewLine(), - SSE42(), OSXSAVE(), CMOV(), PREFETCHWT1(), Aurora::Locale::NewLine(), - SSE4a(), SHA(), FXSR(), PCLMULQDQ(), Aurora::Locale::NewLine(), - AVX(), AVX512F(), BMI1(), INVPCID(), Aurora::Locale::NewLine(), - AVX2(), LZCNT(), HLE(), _3DNOWEXT(), Aurora::Locale::NewLine(), - MMX(), ADX(), BMI2(), _3DNOW() + "FMA {}\t\tFSGSBASE {}\t\tCLFSH {}\t\t\tERMS {}{}" + "CMPXCHG16B {}\t\tAVX512PF {}\t\tMOVBE {}\t\t\tRTM {}{}" + "POPCNT {}\t\tAVX512ER {}\t\tMONITOR {}\t\t\tLAHF {}{}" + "SSE {}\t\tAVX512CD {}\t\tF16C {}\t\t\tABM {}{}" + "SSE2 {}\t\tSYSCALL {}\t\tRDRAND {}\t\t\tXOP {}{}" + "SSE3 {}\t\tAES {}\t\tMSR {}\t\t\tTBM {}{}" + "SSSE3 {}\t\tRDTSCP {}\t\tCX8 {}\t\t\tMMXEXT {}{}" + "SSE41 {}\t\tXSAVE {}\t\tSEP {}\t\t\tRDSEED {}{}" + "SSE42 {}\t\tOSXSAVE {}\t\tCMOV {}\t\t\tPREFETCHWT1 {}{}" + "SSE4a {}\t\tSHA {}\t\tFXSR {}\t\t\tPCLMULQDQ {}{}" + "AVX {}\t\tAVX512F {}\t\tBMI1 {}\t\t\tINVPCID {}{}" + "AVX2 {}\t\tLZCNT {}\t\tHLE {}\t\t\t_3DNOWEXT {}{}" + "MMX {}\t\tADX {}\t\tBMI2 {}\t\t\t_3DNOW {}", + FMA(), FSGSBASE(), CLFSH(), ERMS(), Aurora::Locale::NewLine(), + CMPXCHG16B(), AVX512PF(), MOVBE(), RTM(), Aurora::Locale::NewLine(), + POPCNT(), AVX512ER(), MONITOR(), LAHF(), Aurora::Locale::NewLine(), + SSE(), AVX512CD(), F16C(), ABM(), Aurora::Locale::NewLine(), + SSE2(), SYSCALL(), RDRAND(), XOP(), Aurora::Locale::NewLine(), + SSE3(), AES(), MSR(), TBM(), Aurora::Locale::NewLine(), + SSSE3(), RDTSCP(), CX8(), MMXEXT(), Aurora::Locale::NewLine(), + SSE41(), XSAVE(), SEP(), RDSEED(), Aurora::Locale::NewLine(), + SSE42(), OSXSAVE(), CMOV(), PREFETCHWT1(), Aurora::Locale::NewLine(), + SSE4a(), SHA(), FXSR(), PCLMULQDQ(), Aurora::Locale::NewLine(), + AVX(), AVX512F(), BMI1(), INVPCID(), Aurora::Locale::NewLine(), + AVX2(), LZCNT(), HLE(), _3DNOWEXT(), Aurora::Locale::NewLine(), + MMX(), ADX(), BMI2(), _3DNOW() ); } diff --git a/Source/HWInfo/CpuInfo.NT.cpp b/Source/HWInfo/CpuInfo.NT.cpp index 9d38fd43..96a9f908 100644 --- a/Source/HWInfo/CpuInfo.NT.cpp +++ b/Source/HWInfo/CpuInfo.NT.cpp @@ -129,7 +129,6 @@ namespace Aurora::HWInfo gCpuInfo.cores = 0; gCpuInfo.threads = 0; - bool sparse = false; for (auto i = 0; i < length; i++) {