2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: Panic.cpp
|
|
|
|
Date: 2021-6-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
2021-09-30 14:57:41 +00:00
|
|
|
#include <Source/RuntimeInternal.hpp>
|
2021-06-27 21:25:29 +00:00
|
|
|
#include "Debug.hpp"
|
|
|
|
#include "Panic.hpp"
|
2021-10-02 16:07:33 +00:00
|
|
|
//#include <intrin.h>
|
2021-09-30 14:57:41 +00:00
|
|
|
#include <Source/Console/ConsoleFIO/ConsoleFIO.hpp>
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
namespace Aurora::Debug
|
|
|
|
{
|
2021-09-06 10:58:08 +00:00
|
|
|
AUKN_SYM void DebugBreak()
|
|
|
|
{
|
2021-09-17 19:26:05 +00:00
|
|
|
#if defined(DEBUG) || defined(STAGING)
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
2021-09-17 19:26:05 +00:00
|
|
|
#if defined(STAGING)
|
2021-09-06 10:58:08 +00:00
|
|
|
if (IsDebuggerPresent())
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
::DebugBreak();
|
|
|
|
}
|
2021-09-14 23:56:26 +00:00
|
|
|
#elif defined(DEBUG)
|
|
|
|
#if defined(AURORA_COMPILER_MSVC)
|
|
|
|
__debugbreak();
|
2021-10-02 16:07:33 +00:00
|
|
|
#elif (defined(__has_builtin) && __has_builtin(__builtin_debugtrap))
|
2021-09-14 23:56:26 +00:00
|
|
|
__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
|
2021-09-06 10:58:08 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
AUKN_SYM void Panic()
|
|
|
|
{
|
2021-09-06 10:58:08 +00:00
|
|
|
DebugBreak();
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
CheckErrors();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-09-06 10:58:08 +00:00
|
|
|
Console::ConsoleFIO::Flush();
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool panicSingleshot = false;
|
2022-01-19 17:08:13 +00:00
|
|
|
if (AuExchange(panicSingleshot, true))
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Telemetry::Mayday();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
static bool handlingFatal = false;
|
2022-01-19 17:08:13 +00:00
|
|
|
if (AuExchange(handlingFatal, true))
|
2021-06-27 21:25:29 +00:00
|
|
|
{
|
|
|
|
std::terminate();
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED)
|
2021-06-27 21:25:29 +00:00
|
|
|
// 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
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_COMPILER_GCC) || defined(AURORA_COMPILER_CLANG)
|
|
|
|
__builtin_trap();
|
|
|
|
#else
|
2022-01-18 14:26:38 +00:00
|
|
|
std::terminate();
|
2021-09-06 10:58:08 +00:00
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
2021-10-02 16:07:33 +00:00
|
|
|
}
|