117 lines
4.4 KiB
C++
117 lines
4.4 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: RuntimeInternal.hpp
|
|
Date: 2021-6-12
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
//#include <AuroraCommon.hpp>
|
|
#include <AuroraEnvironment.h>
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
#if !defined(NOMINMAX)
|
|
#define NOMINMAX
|
|
#endif
|
|
|
|
#if !defined(WIN32_LEAN_AND_MEAN)
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
|
|
// Do not change: Minimum target - Windows 7
|
|
#define _WIN32_WINNT 0x0601
|
|
#include <SDKDDKVer.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
// When I had ASIO in here for a few months (2020 experiments), it was a pain to include properly
|
|
#if defined(_AUHAS_ASIO)
|
|
#include <asio.hpp>
|
|
#endif
|
|
|
|
// High level Win32 APIs
|
|
#include <windows.h>
|
|
|
|
// Restricted public Nt-level APIs
|
|
#include <winternl.h>
|
|
|
|
// And of course, LoadLibrary and pattern scanning is going to be the best option for yoinking truely internal/undocumented functions.
|
|
#else
|
|
#if defined(_AUHAS_ASIO)
|
|
#include <asio.hpp>
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
|
#define AURORA_HAS_PTHREADS
|
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
#if !defined(_LARGEFILE64_SOURCE)
|
|
#define _LARGEFILE64_SOURCE
|
|
#endif
|
|
|
|
#include <pthread.h>
|
|
#include <semaphore.h>
|
|
#include <signal.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#define stricmp strcasecmp
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
#include <sys/eventfd.h>
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#include "AuProcAddresses.hpp"
|
|
|
|
#define GIMME_IOWAITABLEITEM
|
|
|
|
#include <AuroraRuntime.hpp>
|
|
|
|
inline Aurora::RuntimeStartInfo gRuntimeConfig;
|
|
inline int gRuntimeRunLevel {0};
|
|
|
|
using namespace Aurora::Logging;
|
|
|
|
namespace Aurora
|
|
{
|
|
#if defined(AU_CFG_ID_DEBUG)
|
|
static const bool kIsDebugBuild = true;
|
|
#else
|
|
static const bool kIsDebugBuild = false;
|
|
#endif
|
|
|
|
bool RuntimeIsMainThread();
|
|
}
|
|
|
|
#define RUNTIME_ASSERT_SHUTDOWN_SAFE(value, ...) \
|
|
if (gRuntimeRunLevel < 3) \
|
|
{ \
|
|
SysAssert(value, __VA_ARGS__); \
|
|
} \
|
|
else \
|
|
{ \
|
|
if (!bool(value)) \
|
|
{ \
|
|
try \
|
|
{ \
|
|
AuLogWarn("Error while shutting down: {}", fmt::format(__VA_ARGS__)); \
|
|
} \
|
|
catch (...) {} \
|
|
if (!kIsDebugBuild) SysPushErrorGeneric(__VA_ARGS__); \
|
|
if (RuntimeIsMainThread()) \
|
|
{ \
|
|
if (gRuntimeRunLevel < /*5*/ 4 /*i dont like this and i think i know the problem*/) \
|
|
{ \
|
|
SysPanic("Error while shutting down: {}", fmt::format(__VA_ARGS__));\
|
|
} \
|
|
} \
|
|
else \
|
|
{ \
|
|
Threading::Threads::TerminateCurrent(); \
|
|
} \
|
|
} \
|
|
} |