fix(libkernel): refuse to detach or rejoin a thread that is being joined #6487
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6487"
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 klosixgaming-arch on 2026-10-15T17:09:13Z.
What
EA SPORTS FC 27 (PPSA34015) stopped once on Windows with:
The join comes from the title's thread wrapper (eboot
0x1d4b365,scePthreadJoin(handle, NULL)after its status poll).scePthreadJoinwaits for_finishedand then for the native handle. If another call releases the thread in the meantime, the join waits on a closed handle in freed memory. That other call is ascePthreadDetach, or a secondscePthreadJoinwhoseReleaseThreadfrees the thread.WaitForSingleObjectthen fails withERROR_ACCESS_DENIED.FreeBSD 11.4 libthr keeps a
joinerfield for this case (thr_join.c, thr_detach.c). This PR follows it, under_join_mtx:scePthreadDetachreturnsEINVALwhile a thread waits to join the target.scePthreadJoinreturnsEOPNOTSUPP(ENOTSUP, 45), asjoin_commondoes.backout_join)._joinedunder the same lock, so a detach racing with its end returnsEINVALinstead of releasing the thread a second time.The libkernel debt entry for
scePthreadJoinrecords this.mainnow has the_joinedflag (second join after a completed one →ESRCH); this PR keeps it and adds the lock, so a detach cannot close the handle while a joiner waits.Tested
guest_pthread_join_detach:EINVAL.EOPNOTSUPP.EINVAL.guest_pthread_startstill passes on both.main66702f1cff:guest_pthread_join_detachpasses again on Windows 11. The Linux runs andguest_pthread_startabove are from before the rebase.v_readlane_b32 of lane 63 is outside the 32-lane host subgroup, see #6344), so I could not run it to the point of this race again. A run with this change and a log on the refused paths reached that earlier stop without the join error, which does not prove much either way.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T17:29:23Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/include/Pthread.hppcore/libs/prx/libkernel/Pthread/src/Thread.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Pthread/include/Pthread.hppcore/libs/prx/libkernel/Pthread/src/Thread.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Pthread/include/Pthread.hppcore/libs/prx/libkernel/Pthread/src/Thread.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/include/Pthread.hppcore/libs/prx/libkernel/Pthread/src/Thread.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Pthread/src/Thread.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-15T19:17:33Z.
No dependency: this PR builds on neither of them.
ESRCH. It does that by keeping the joined thread alive and checking_joined.pthread_getname_npon a joined thread returnESRCH, on top of the same_joinedstate.joinerrule under_join_mtx.They edit the same lines in
scePthreadJoinandscePthreadDetach, so whichever merges second needs a small rebase. If #4481 lands first, its_joinedearly return can sit before the_join_mtxblock here unchanged. The remaining PRs in the list are the AOT stack and CMake-only overlaps.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T14:31:44Z.
Rebase handoff, with one contract repair — rebased onto current
main(authorship unchanged). The conflicts weremain's newer atomic thread state (std::atomic<bool> _joined,_handleStorage) meeting this PR's mutex-guarded_joiningflag: the merged version keepsmain's atomics plus your_joiningflag under_join_mtx, and the detach check is the union (detached, joining, or already joined).The repair: your join completion set
_detached = true, which made a secondscePthreadJoinreturnEINVALwheremain'sguest_pthread_second_joinrequiresESRCH. The join no longer marks the thread detached — the detach-after-join refusal your change is after is already covered by the_joinedatomic in the detach path, and that test passes.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
785ae9120.