fix(libkernel): report an ended adopted host thread as gone on Windows #14190
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14190"
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 JJenkx on 2026-10-31T22:44:43Z.
What
On Windows,
scePthreadAttrGetandpthread_attr_get_npkept answering 0 for a host thread the guest had adopted, even after that thread ended.The guest adopts a host thread when it calls
scePthreadSelfon a thread it never created. On Windows that path:PthreadPrivate, which registers itself in the live-thread registry;adopted.release()).When the host thread ended without
scePthreadExit, nothing marked that record finished or removed it, so both calls kept answering 0. FreeBSD 11.4's_pthread_attr_get_npanswersESRCHfor a thread_thr_find_threadno longer finds.On Linux the adopted record is a
thread_localunique_ptr. Its destructor removes it from the registry when the thread ends, so the same calls already answerESRCHthere.The "scePthreadAttrGet and pthread_attr_get_np" debt entry notes that Monster Hunter Wilds (PPSA24191) reuses a slot of its thread table only when
scePthreadAttrGetreturns0x80020003. On Windows, an adopted thread's slot would never become free.The change:
hostAdoptedflag.LockLiveGuestThreadnow treats such a thread as ended once its duplicated handle is signalled (WaitForSingleObject(handle, 0) == WAIT_OBJECT_0). That handle is never closed for an adopted thread, so the check is always valid.GuestThreadEndedapplies the same answer to every registry scan inThread.cpp, after review: the by-id affinity and scheduling lookups and setters,LiveGuestThreadExists, the affinity mask scans, the main-thread lookup and the CPU time lookup._finishedcheck, and Linux and macOS are unchanged.Tested
Current-main integration — 2026-11-09 UTC. Head
56c7372672508f17d29c4922567d75e4ba6aa587preserves public headd9ba1fbf5aadf2b9800048c10d274cf4e5c7eda8and integrates pinned main7259cce11195f360698772da8c0b3af756bf7c8f. Conflict resolution retains both the topic and main's newer source/test/debt changes; maintainer commits and attribution remain intact.Linux x86-64, GCC 16.2.1, Ninja Release: actual libc/libkernel and focused fixture owners rebuilt. 12/12 CPU executions pass, zero skips (4 groups × three repetitions):
guest_pthread_attr,guest_pthread_attr_stack,guest_pthread_attr_errors,guest_pthread_schedparam.public_headers, conventions and whitespace checks pass. The matching plain-main control passed 102 selected CPU executions and its header audit. CPU fixtures execute unpatched production libraries; this is not a full SDK or patched-title runtime qualification.The Linux attribute/scheduling fixtures do not execute the Windows-only adopted-handle check. Its production additions/removals are unchanged from the previously tested public head; older Windows evidence retains its original head and base. No new Windows/macOS, console, GPU, title or performance result is claimed. Source checks preserve the existing production topic; historical reports below retain their original pins.
Build/test logs, exact heads, source/ancestry checks and provider pins, SHA-256
52727be6594b9c15bf9a5535fef374b985e9526aabe5f3ef5cf5857dfeeb1a0d. The public archive and all 178 manifest files were download/hash verified.Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, full build with
BUILD_TESTING=ON, onmain7a5d9bf02a.guest_pthread_attrCheckEndedThreads: astd::threadcallsscePthreadSelf()and returns, and the test joins it.scePthreadAttrGetmust then reportESRCHwithin 5 s (the existingReportedEndedhelper), and so mustpthread_attr_get_np.guest_pthread_attr,guest_pthread_attr_stackandguest_pthread_attr_errorspass 3/3.Thread.cpprestored tomain(the control build relinkedlibkernel.prx):guest_pthread_attraborts after 5.65 s, because the adopted thread is still reported live.d9ba1fbf5a: the check also requirescpuset_getaffinitywith the ended thread's id to fail withESRCH. It aborts withThread.cppat7122664e7eand passes 3/3 with the follow-up.ctest -R "pthread|thread|kernel|mutex|cond|sema|equeue|cpuset|affinity|sched" -j8 --repeat until-fail:3passes 169/169.ctest -R "pthread|thread|kernel|mutex|cond|sema|equeue" -j8 --repeat until-fail:3: 167/167 pass.thread_localrecord's destructor, but I have not run it; CI will.Independent reports on this head (their runs, summarised here):
d9ba1fbf5amerged intomain5bae1a4bc2:guest_pthread_attrpasses 5/5; withThread.cppandPthread.hppfrommainand this test kept it aborts 5/5.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 MarcZX10 on 2026-10-31T23:06:44Z.
Review: APPROVED
Reviewed — looks good
The Windows-specific handle check now recognizes an adopted host thread as ended, and the exact-head Windows CI run passed the test that covers it.
What I ran
Reviewed head
7122664e7e93e8de67af2e611659937d8124c190against currentmain381891927c2b3ff494a9853cb79fde8d5342b92d; the merge preview is clean. Environment: Debian Linux x86_64, glibc 2.36, Python 3.11.2, GCC/G++ 12.2.0. I did not build locally.Results
ResetOnce, which is astaticfunction and therefore intentionally has no public header declaration.GuestPthreadAttr.cppasguest_pthread_attr, so this is a heuristic false positive.guest_pthread_attrpassed, and the changed-test run passed 2,539/2,539 tests.Thread.cpptomain; I did not independently run that control.Unedited check output
Conventions:
Merge preview tree:
ABI audit:
Windows CTest:
Negative control
ESRCHThread.cpptomainand relinkinglibkernel.prxon Windows.Findings
Blocking
None found.
Non-blocking
None found in the reviewed change.
Sources
guest_pthread_attrNot verified
I did not build or run tests locally. Hosted Linux and specialized product jobs were skipped; the author did not run Linux/macOS or a console test.
To get this to a good state
No further change is needed for the reviewed behavior. If the head changes, I will rerun the same checks against the new head.