fix(kernel,audioout,relinker): thread/mutex correctness fixes and --windows-gui #25
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25"
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?
Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-09-27T05:45:41Z.
Summary
Fixes a set of verified bugs in
libkernel,libSceAudioOutand the relinker CLI, and adds a--windows-guirelinker option andsceKernelDeleteSema.libkernel (threads, mutexes, condition variables)
scePthreadCondTimedwait(normal/error-check mutexes):_ownerwas not restored after the wait. If another thread locked and unlocked the mutex during the wait, the waiter woke up owning the mutex while_ownerwas empty. Its nextscePthreadMutexUnlockreturnedEPERM, leaving the mutex locked forever (lock → timedwait → unlockpattern).SCE_KERNEL_ERROR_ETIMEDOUTinCond.cppwas0x80020062; it is0x8002003C(FreeBSDETIMEDOUT= 60, matchingSemaphore.hpp).scePthreadSelf()returnednullptron Linux, and on both platforms for threads not created byscePthreadCreate(including the main thread). Such threads now get a lazily adopted, non-joinable handle (scePthreadJoin/Detachon it returnEINVAL).scePthreadExitskippedFinishThread, soscePthreadJoingot a garbage return value. Cleanup now runs from an RAII guard, so it survives glibc forced unwinding.std::recursive_timed_mutex::unlock). It now returnsSCE_KERNEL_ERROR_EPERM, and_owner/_countare also saved and restored around a recursive cond wait.sceKernelLseekreturnedintinstead ofoff_t; offsets aboveINT_MAXthrew.sceKernelDeleteSemaimplemented: waiters are woken withSCE_KERNEL_ERROR_EACCESand the object is freed once they leave.libSceAudioOut
sceAudioOutOpenacceptedfreq == 0/len == 0; the frequency was later used as a divisor. It now returnsSCE_AUDIO_OUT_ERROR_INVALID_SAMPLE_FREQ/INVALID_SIZE.Relinker
--autorunneeded two Enter presses (cin.ignore+cin.get). On POSIX it also returned the rawsystem()wait status frommain, so a guest exit code of 1 (status 256) became 0.--windows-gui(requires--windows) writesIMAGE_SUBSYSTEM_WINDOWS_GUIso the game does not open a console window (TechnicalDebt: "opens the console when launched"). The default is unchanged because stderr diagnostics are invisible with the GUI subsystem.Tests
New tests:
guest_thread_self:scePthreadSelfon the main and a created thread, join value viascePthreadExit, recursive unlock from a non-owner returnsEPERM.guest_cond_timedwait: regression for the deadlock above. I checked that it aborts with the_ownerrestore reverted and passes with it.windows_gui: PE subsystem is 3 by default, 2 with--windows-gui, and the flag is rejected without--windows.Results:
x86_64-ucrt-posix-seh, r7):mainpasses 31/31; this branch passes 34/34./W4 /permissive-), and its 5 tests pass there.Not tested on Linux. The Linux
#elsebranches inThread.cpp(RAII guard, reference counting,pthread_exitpath) need a run there.Notes for review
scePthreadExitfrom an adopted thread (e.g. the main thread) now reaches_endthreadexinstead of throwing. This is closer to FreeBSD semantics but untested.sceKernelDeleteSemadoes not protect against a new call on the handle racing with the delete. There is no handle registry for semaphores, same as the rest ofSemaphore.cpp.EQUEUE_ERROR_ETIMEDOUTinEqueue.hppis0x80020023(EAGAIN) rather than0x8002003C; worth checking against real behaviour.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-27T13:11:21Z.
PR #10 changed files in
core/libs/prx/libkernel/Pthread/src/. Conflicts need to be resolved. Apparently, this affected several of your public PRs. But those changes were extremely important.Imported from boykopovar/AnyPS5. Originally posted by QDarkRex on 2026-09-28T07:48:57Z.
Thanks for the heads-up! I merged the latest main into #25, #26 and #27 and resolved the conflicts with #10. None of them conflict now.
#25: #10 already covered the cond-wait deadlock, the ETIMEDOUT code and the mutex-unlock ownership check, so I kept your versions of Cond.cpp and Mutex.cpp. On top of your new Thread.cpp I re-applied the POSIX thread fixes: reference-counted release on join/detach/exit, rejecting self-join, and scePthreadSelf for threads the emulator didn't create. I also re-applied sceKernelDeleteSema on top of TimedWait::Condition. I also fixed scePthreadExit on Linux. pthread_exit's forced unwind ran libc.prx's __gxx_personality_v0, which aborted, so it now jumps back to the thread start routine instead, like _endthreadex on Windows.
#26: #10 already fixed the mutex EDEADLK code, so I took your version. The equeue and direct-memory error-code fixes are unchanged.
#27: Still stacked on #25 and #26. I re-applied the KernelErrors.hpp refactor to the rewritten files.
On Linux, every test passes except agc_driver, agc_driver_flip and agc_driver_pm4, which fail the same way on current main.