AuroraRuntime/Source/Debug/Panic.cpp
Reece c4567f4c8c [*] Amend %x -> {:X} formatting
[+] Added source files ready for an LTC ECC implementation
[+] Added linux specific HWInfo get threads backend
[+] AU_TEMPLATE_ENABLE_WHEN
[*] Amend IO::FS::WriteString compilation issue
2021-09-17 20:26:05 +01:00

95 lines
2.3 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 <RuntimeInternal.hpp>
#include "Debug.hpp"
#include "Panic.hpp"
#include <intrin.h>
#include <Console/ConsoleFIO/ConsoleFIO.hpp>
namespace Aurora::Debug
{
AUKN_SYM void DebugBreak()
{
#if defined(DEBUG) || defined(STAGING)
#if defined(AURORA_PLATFORM_WIN32)
#if defined(STAGING)
if (IsDebuggerPresent())
#endif
{
::DebugBreak();
}
#elif defined(DEBUG)
#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
}
AUKN_SYM void Panic()
{
DebugBreak();
try
{
CheckErrors();
}
catch (...)
{
}
try
{
Console::ConsoleFIO::Flush();
}
catch (...)
{
}
static bool panicSingleshot = false;
if (std::exchange(panicSingleshot, true))
{
try
{
Telemetry::Mayday();
}
catch (...)
{
}
}
//
static bool handlingFatal = false;
if (std::exchange(handlingFatal, true))
{
std::terminate();
}
#if defined(AURORA_IS_MODERNNT_DERIVED)
// there is a syscall you can use to terminate in instances like this
// anticheats and drm love it
// i just dont remember what it is
// amendment: i believe its some software interrupt that raises an unhandleable exception
TerminateProcess(GetCurrentProcess(), 0xDEAD);
#else
#if defined(AURORA_COMPILER_GCC) || defined(AURORA_COMPILER_CLANG)
__builtin_trap();
#else
std::exit(0xDEAD);
#endif
#endif
}
}