J Reece Wilson
766be57a46
[+] ProcessSectionViewReserved.Unix.cpp [*] Fix missing ::Flush() member on ViewWriter
197 lines
4.3 KiB
C++
197 lines
4.3 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: Entrypoint.cpp
|
|
Date: 2021-5-13
|
|
Author: Reece
|
|
***/
|
|
#define _AURORA_RUNTIME_BUILD_API_INTERFACES
|
|
#include <AuroraCommon.hpp>
|
|
#include <AuroraRuntime.hpp>
|
|
#include "RuntimeInternal.hpp"
|
|
#include "AuCrypto.hpp"
|
|
#include "Processes/AuProcesses.hpp"
|
|
#include "RNG/AuRNG.hpp"
|
|
#include "Locale/Locale.hpp"
|
|
#include "Console/Console.hpp"
|
|
#include "IO/FS/FS.hpp"
|
|
#include "IO/IO.hpp"
|
|
#include "IO/Net/Net.hpp"
|
|
#include "Hashing/AuHashing.hpp"
|
|
#include "Debug/Debug.hpp"
|
|
#include "Async/Async.hpp"
|
|
#include "HWInfo/AuHWInfo.hpp"
|
|
#include "Telemetry/Telemetry.hpp"
|
|
#include "Threading/Threads/AuOSThread.hpp"
|
|
#include "SWInfo/AuSWInfo.hpp"
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
#include "Extensions/Win32/DarkTheme.hpp"
|
|
#include <timeapi.h>
|
|
#endif
|
|
#include "Debug/MemoryCrunch.hpp"
|
|
#include "Process/Process.hpp"
|
|
#include "Exit/AuExit.hpp"
|
|
#include "CmdLine/CmdLine.hpp"
|
|
#include "Grug/AuGrug.hpp"
|
|
#include "Threading/AuSleep.hpp"
|
|
#include "Memory/Cache.hpp"
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
void LinuxSuperSecretIOTick();
|
|
#endif
|
|
|
|
namespace Aurora::IO::TLS
|
|
{
|
|
void TLSInit();
|
|
}
|
|
|
|
static thread_local bool tlsHackIsMainThread {};
|
|
|
|
static void Init()
|
|
{
|
|
gRuntimeRunLevel = 1;
|
|
tlsHackIsMainThread = true;
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
::timeBeginPeriod(1);
|
|
|
|
Aurora::Extensions::Win32::InitDarkMode();
|
|
#endif
|
|
|
|
Aurora::Memory::Cache::InitCache();
|
|
Aurora::RNG::Init();
|
|
|
|
Crypto::InitCrypto();
|
|
Aurora::IO::TLS::TLSInit();
|
|
|
|
Aurora::Threading::InitSleep();
|
|
Aurora::Process::InitProcess();
|
|
Aurora::SWInfo::InitSwInfo();
|
|
Aurora::Threading::Threads::InitThreading();
|
|
Aurora::Exit::InitExit();
|
|
Aurora::IO::Net::InitNetworking();
|
|
Aurora::Console::Init();
|
|
Aurora::IO::FS::InitResources();
|
|
Aurora::IO::Init();
|
|
Aurora::Console::Init2();
|
|
Aurora::HWInfo::Init();
|
|
Aurora::Telemetry::Init();
|
|
Aurora::Grug::InitGrug();
|
|
Aurora::Debug::InitDebug();
|
|
Aurora::Locale::Init();
|
|
Aurora::CmdLine::Init();
|
|
Aurora::Processes::Init();
|
|
Aurora::Hashing::InitHashing();
|
|
Aurora::Async::InitAsync();
|
|
gRuntimeRunLevel = 2;
|
|
}
|
|
|
|
static void Pump()
|
|
{
|
|
Aurora::Console::Pump();
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
::LinuxSuperSecretIOTick();
|
|
#endif
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
::timeBeginPeriod(1);
|
|
#endif
|
|
}
|
|
|
|
static void RuntimeLateClean();
|
|
|
|
static void Deinit()
|
|
{
|
|
//tlsHackIsMainThread = true;
|
|
gRuntimeRunLevel = 3;
|
|
Aurora::Exit::PostLevel(AuThreads::GetThread(), Aurora::Exit::ETriggerLevel::eSafeTermination);
|
|
gRuntimeRunLevel = 4;
|
|
Aurora::RNG::Release();
|
|
Aurora::Async::ShutdownAsync();
|
|
Aurora::Grug::DeinitGrug();
|
|
RuntimeLateClean();
|
|
}
|
|
|
|
static void RuntimeLateClean() // strictly IO flushing + DeinitGrug can sometimes fail under POSIX
|
|
{
|
|
Aurora::Console::Exit();
|
|
Aurora::Processes::Deinit();
|
|
Aurora::Exit::DeinitExit();
|
|
Aurora::IO::Deinit();
|
|
|
|
AuDebug::gReservePoolStart = 0;
|
|
AuDebug::gReservePoolEnd = 0;
|
|
AuDebug::gReserveHeap.reset();
|
|
|
|
gRuntimeRunLevel = 5;
|
|
}
|
|
|
|
namespace Aurora
|
|
{
|
|
static bool gRuntimeHasStarted {};
|
|
|
|
bool RuntimeIsMainThread()
|
|
{
|
|
return tlsHackIsMainThread;
|
|
}
|
|
|
|
AUKN_SYM void RuntimeStart(const RuntimeStartInfo &info)
|
|
{
|
|
gRuntimeConfig = info;
|
|
|
|
if (gRuntimeHasStarted)
|
|
{
|
|
SysPanic("Do not nest RuntimeStart/RuntimeShutdowns. Modules should respect RuntimeHasStarted()");
|
|
}
|
|
|
|
try
|
|
{
|
|
Init();
|
|
}
|
|
catch (...)
|
|
{
|
|
SysPanic("A fatal error occurred during the initialization of Aurora Runtime");
|
|
}
|
|
|
|
gRuntimeHasStarted = true;
|
|
}
|
|
|
|
AUKN_SYM bool RuntimeHasStarted()
|
|
{
|
|
return gRuntimeHasStarted;
|
|
}
|
|
|
|
AUKN_SYM void RuntimeShutdown()
|
|
{
|
|
RuntimeSysPump();
|
|
gRuntimeHasStarted = false;
|
|
Deinit();
|
|
}
|
|
|
|
AUKN_SYM void RuntimeSysPump()
|
|
{
|
|
Pump();
|
|
}
|
|
|
|
void RuntimeLateClean()
|
|
{
|
|
::RuntimeLateClean();
|
|
}
|
|
}
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
|
|
BOOL WINAPI DllMain(
|
|
HINSTANCE hinstDLL,
|
|
DWORD fdwReason,
|
|
LPVOID lpReserved)
|
|
{
|
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
|
{
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
#endif |