Reece Wilson
124038df62
[+] AuConsole::Commands::RemoveCommand [+] EExtendedUsage::eServerAuth [+] SysPanic2 for SysSafeLine hints (backtrace may contain optimized SysPanics, making tracing the true origin difficult) [*] Reworked SysAssertions [*] AuParse::EncodeHex now takes AuMemoryViewRead [*] AuRng::ReadSecureRNG now takes AuMemoryViewWrite [*] AuRng::ReadFastRNG now takes AuMemoryViewWrite
129 lines
3.0 KiB
C++
129 lines
3.0 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: Panic.cpp
|
|
Date: 2021-6-12
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "Debug.hpp"
|
|
#include "Panic.hpp"
|
|
//#include <intrin.h>
|
|
#include <Source/Grug/AuGrug.hpp>
|
|
#include <Source/Console/ConsoleTTY/ConsoleTTY.hpp>
|
|
#include <Source/Console/Console.hpp>
|
|
|
|
namespace Aurora::Debug
|
|
{
|
|
void PlatformHandleFatal();
|
|
static bool gHandlingFatal = false;
|
|
|
|
AUKN_SYM void DebugBreak()
|
|
{
|
|
#if defined(AU_CFG_ID_INTERNAL) || defined(AU_CFG_ID_DEBUG)
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
#if defined(AU_CFG_ID_INTERNAL)
|
|
if (IsDebuggerPresent())
|
|
#endif
|
|
{
|
|
::DebugBreak();
|
|
}
|
|
#elif defined(AU_CFG_ID_DEBUG) // bc nix
|
|
#if defined(AURORA_COMPILER_MSVC)
|
|
__debugbreak();
|
|
#elif (defined(__has_builtin) && __has_builtin(__builtin_debugtrap))
|
|
__builtin_debugtrap();
|
|
#elif defined(AURORA_COMPILER_GCC) || defined(AURORA_COMPILER_CLANG)
|
|
// GCC is a terrible compiler, msvc is annoying at best, and LLVM + cpp frontend seems great, whats new?
|
|
// I refuse to chuck inline assembly here, not here, not in this project, not for freetards.
|
|
#endif
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
bool InPanic()
|
|
{
|
|
return gHandlingFatal;
|
|
}
|
|
|
|
AUKN_SYM void Panic2(AuUInt uLineHintInNonshipBinary)
|
|
{
|
|
// TODO: telemetry insert crashing from line uLineHintInNonshipBinary
|
|
Panic();
|
|
}
|
|
|
|
AUKN_SYM void Panic()
|
|
{
|
|
//
|
|
if (gHandlingFatal)
|
|
{
|
|
goto failFast;
|
|
}
|
|
|
|
DebugBreak();
|
|
// Edge case: internal builds should always check for a debugger before crashing
|
|
#if defined(AU_CFG_ID_INTERNAL) && defined(__has_builtin) && __has_builtin(__builtin_debugtrap)
|
|
__builtin_debugtrap();
|
|
#endif
|
|
//
|
|
|
|
if (AuExchange(gHandlingFatal, true))
|
|
{
|
|
goto failFast;
|
|
}
|
|
|
|
try
|
|
{
|
|
Console::ConsoleTTY::PumpForce();
|
|
}
|
|
catch (...)
|
|
{
|
|
|
|
}
|
|
|
|
try
|
|
{
|
|
Grug::GrugFlushFlushs();
|
|
Grug::GrugFlushWrites();
|
|
}
|
|
catch (...)
|
|
{
|
|
|
|
}
|
|
|
|
try
|
|
{
|
|
Console::Pump();
|
|
}
|
|
catch (...)
|
|
{
|
|
|
|
}
|
|
|
|
failFast:
|
|
|
|
static bool runPlatformFastFailOnce {};
|
|
if (!AuExchange(runPlatformFastFailOnce, true))
|
|
{
|
|
try
|
|
{
|
|
Debug::PlatformHandleFatal(true);
|
|
}
|
|
catch (...)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
|
__fastfail('FCKD');
|
|
#else
|
|
#if defined(AURORA_COMPILER_GCC) || defined(AURORA_COMPILER_CLANG)
|
|
__builtin_trap();
|
|
#else
|
|
std::terminate();
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|