Unity Game Fixes - common/kernel: deliver guest signals only at safe points #215
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!215
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/215/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@StefanosCosta on GitHub · 2026-08-08 19:36 UTC · original
StefanosCosta:pr/guest-signal-safe-points→main· +376 −54 · 9 files · 3 commits · closed without mergingNOTE
These are commits from PR #156, compressed and cleaned up to be isolated from the rest of the changes that have either a) been committed or b) been identified as hacks/incomplete implementations.
These changes make Subnautica, Powerwash Simulator and cult of the lamb boot and enter in-game. I do not claim that these changes are objectively the correct implementation. This is just a PR separating commits from #156 so that they can be seen in the correct context and provide better insight as to what their purpose is. More details below:
Summary
A guest signal handler could run nested inside a host wait, or while the thread held an
emulator-global lock. Either one deadlocks the emulator: the handler blocks, the frame never
unwinds, and the state it holds is stranded. This leaves the signal queued in both cases and
dispatches it once the frame has unwound.
What's included
Guest signal delivery —
libKernel.cpp,memory.cpp,graphicsRun.cppKernelDispatchPendingSignalForCurrentThreadonce the frame unwinds. Running IL2CPP's GC-suspendhandler nested inside a host wait strands glibc's condvar group reference, after which every later
broadcast on that variable blocks forever — the hard freeze on Subnautica's loading screen.
g_memory_operation_mutexsites and the GPU submission lock as critical sections,and refuse to dispatch inside one. A handler that blocks while holding either stalls every other
guest thread; both mutexes were confirmed owned by a single parked thread via
__data.__owner.previous path did a read-modify-write per signal number.
Condition variables —
threads.cpp,threads.hSignalThread's targets with the registry lock released. A broadcast can block until thewaiters it is retiring have left, and they leave through
UnregisterCondWaiter, which needs thatsame mutex — so the waker deadlocked against every waiter it was trying to wake.
Signal()andSignalAll()already woke without the lock.shared_ptr. Between the collect and the wake, a waiter can return,unregister and have its owning
CondVardestroyed, so the wake touched freed memory.CondVar::WaitFor. It had none, so a deferred signal sat undelivered forthe whole of an arbitrarily long timeout.
Build and tests —
CMakeLists.txt,tests/SignalSafetyTests.cppsignal_safety_tests, covering both the deadlock and the use-after-free. The use-after-freeoracle is ASan: built with
-fsanitize=addressit reportsheap-use-after-freeinWakeCondVarreached from
SignalThread, on memory freed by~CondVar, and is clean with the fix. Aregression in the deadlock hangs the test rather than failing it, which is the honest shape for a
deadlock.
Platform impact
CondVar::WaitFordispatch point sits in the non-KYTY_WIN_CSarm, and theHostSignalDispatchHandlerdeferral is inside#if KYTY_PLATFORM != KYTY_PLATFORM_WINDOWS && defined(__x86_64__). Windows keeps its own APCpath (
SignalApcHandler/nt_queue_apc_thread_ex), untouched. Everything else compiles there:the
SignalThreadfix, theshared_ptrwaiter lifetime,HleCriticalSection, the 33MemoryOperationLocksites, and the dispatcher's two new early returns.Testing
Built on Linux (Clang, Ninja).
ctest27/27 including the newsignal_safety.@svoboda18 on GitHub · 2026-08-09 02:20 UTC · original · approved these changes
@Nmzik on GitHub · 2026-08-29 06:47 UTC · original
@StefanosCosta Is it still needed? All the games are running successfully on Linux, and the main development is now happening on Linux. Powerwash Simulator is definitely goes in-game
@StefanosCosta on GitHub · 2026-09-02 01:17 UTC · original
Hey @Nmzik. I checked your question around 3 days ago with the main of that day. I couldn't load the games on ubuntu far enough into the game to test if this is still needed. Subnautica didn't even boot to menu, though I guess it could be a problem on my side because powerwash simulator didn't boot for me either. I made sure to pull all recent changes from main though and created a new build. I'm going to be taking care of a few personal things so i'm going to be away from github for a while. Hope all goes well.
@Nmzik on GitHub · 2026-09-12 11:32 UTC · original
Should be good on Linux
Pull request closed