From 42bfeec2e903ce5acad05957170ee51a2c6d7037 Mon Sep 17 00:00:00 2001 From: Mehmet Cambaz <52370708+MehmetCambaz@users.noreply.github.com> Date: Sat, 29 Aug 2026 03:44:40 +0300 Subject: [PATCH] emulator: run cleanup handlers on the quick_exit path (#334) Run() registers KytyClose with atexit(), but Execute() ends the process with std::quick_exit(), which invokes at_quick_exit handlers only. Nothing registered one, so the cleanup never ran and neither did the emergency shutdown handlers that close open guest files and flush the log. Register a quick-exit handler that runs the emergency shutdown. It deliberately skips RuntimeLinker::Clear(): guest threads are still live at that point and tearing the linker down there deadlocks against a thread parked in a condition wait. --- src/emulator.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/emulator.cpp b/src/emulator.cpp index cae03c583..50dd75988 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -200,6 +200,10 @@ void Run(const RunOptions& options) { int ok = atexit(KytyClose); EXIT_NOT_IMPLEMENTED(ok != 0); + // Guest threads are still running, so skip KytyClose() and only flush emergency state. + ok = at_quick_exit(Common::Subsystems::EmergencyShutdownActive); + EXIT_NOT_IMPLEMENTED(ok != 0); + Libs::LibKernel::FileSystem::Mount(options.app0_dir, "/app0"); Libs::LibKernel::FileSystem::Mount(options.app0_dir, "/hostapp");