diff --git a/Source/AuRTEntrypoint.cpp b/Source/AuRTEntrypoint.cpp index 08529633..865ffd18 100644 --- a/Source/AuRTEntrypoint.cpp +++ b/Source/AuRTEntrypoint.cpp @@ -107,27 +107,50 @@ 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(); + RuntimeLateClean(); } static void RuntimeLateClean() { - Aurora::Console::Exit(); - Aurora::Grug::DeinitGrug(); // TODO: this was once broken above "deinit" for some unix crash reason. - Aurora::Processes::Deinit(); // now that the runtime is far more stable, im putting this down here to ensure - Aurora::Exit::DeinitExit(); // console exit doesnt slam into a deadlocked grug thread. - Aurora::IO::Deinit(); + // TODO: elevate leval, freeze all threads + Aurora::Console::Exit(); // Final flush (i hope? coping?) + + Aurora::Grug::DeinitGrug(); // TODO: this was once broken above "deinit" for some unix crash reason. + // now that the runtime is far more stable, im putting this down here to ensure + // console exit doesnt slam into a deadlocked grug thread. + + Aurora::Processes::Deinit(); + + // Static variables we should probably manually release -> + // (there is no real logic under the following functions) + Aurora::IO::Deinit(); + Aurora::Exit::DeinitExit(); + + Aurora::RNG::Release(); // RNG and crypto should remain alive whilst IO work is ongoing. + // At this point, we should assume libtomcrypt and mbedtls wont be called + // The default gFastDevice shouldn't be hit for any reason + // ...we should be clear to start freeing those contexts and related system handles + + // Exterminate reserve debug memory which may very well be in use + // So long as we assume aurora runtime users are dead, bye bye underlying (low-memory condition) heap AuDebug::gReservePoolStart = 0; AuDebug::gReservePoolEnd = 0; AuDebug::gReserveHeap.reset(); gRuntimeRunLevel = 5; + + // TODO: forcefully terminate spawned threads + + + // TODO: debate terminate process for safety reasons i cant be bothered to explain (including AuDebug heap) } namespace Aurora