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
|
|
|
|
***/
|
|
|
|
#include <RuntimeInternal.hpp>
|
|
|
|
#include "Debug.hpp"
|
|
|
|
#include "Panic.hpp"
|
2021-09-06 10:58:08 +00:00
|
|
|
#include <intrin.h>
|
|
|
|
#include <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()
|
|
|
|
{
|
|
|
|
#if defined(DEBUG) || defined(INTERNAL)
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
|
|
#if defined(INTERNAL)
|
|
|
|
if (IsDebuggerPresent())
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
::DebugBreak();
|
|
|
|
}
|
|
|
|
#elif 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
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (std::exchange(panicSingleshot, true))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Telemetry::Mayday();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
static bool handlingFatal = false;
|
|
|
|
if (std::exchange(handlingFatal, true))
|
|
|
|
{
|
|
|
|
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
|
|
|
|
std::exit(0xDEAD);
|
|
|
|
#endif
|
2021-06-27 21:25:29 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|