fix(libkernel): reject ended threads in pthread_attr_get_np #9482
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9482"
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 valenciana-nc on 2026-10-21T23:04:07Z.
What
Fix the documented ended-thread gap in
pthread_attr_get_np: acquire the existingLockLiveGuestThreadguard before reading the thread, and return guestESRCH(3) when it is no longer live. Holding the registry lock through the attribute copy prevents detached-thread destruction from freeing the object during the read. The SCE sibling already uses this guard; validation order and live-thread attribute values are unchanged.Extend
GuestPthreadAttr.cppto cover joined, finished-but-unjoined and detached threads, null arguments, unchanged stack-size attributes on failure, preserved guest errno, and successful self-queries during thread-specific-data destruction. Trim the resolved debt statement while retaining the unverified console behavior and Windows adopted-thread limitation.The behavior follows the FreeBSD 11.4 implementation already cited by the debt entry:
_pthread_attr_get_npcalls_thr_find_threadwith dead threads excluded. No new console measurement or title fix is claimed.Refreshed head
271d428b2d1e55d9f38fdaa6af4b92876e83817c, based on audit-start mainf57ceaad6bceeb00a7f4f09975f5932b2f20e28e. This supersedes the earlier rebase tob7d1d47a5f/head6298429beb;git range-diffconfirms the patch is unchanged. Unrelated upstream changes are preserved.2026-10-24 status audit (no code update): head remains
271d428b2d; it still merges cleanly with fetched main379b1dca32. No new implementation review request was posted. The earlier rebase/retest request was addressed in the comments below; re-review and maintainer-triggered runtime CI remain outstanding. No new execution result or unnecessary rebase is claimed.The current overlap report still has debt-only hunks with #9684 and #9938. The #9684 author already agreed this PR first. The #9938 author documents either order as possible, specifically requiring its new joined-thread query case to expect
ESRCHafter this lifetime fix. Keeping #9482 first is consistent with its existing #9684 ordering; there is no new runtime dependency. Their supplied-stack implementation is not imported here, and no combined runtime test is claimed.Previous audit's overlap review (historical integration observations):
core/libs/tests/threads/GuestPthreadAttr.cpp, byte-for-byte identical to this PR's test, without a conflict in that file. The relocation is not merged into this PR prematurely; #6044 still has unrelated pre-existing conflicts.Depends on: noneremains correct.Pthread/Posix/Attr.cpp; its debt edit concerns a separate exception entry. #8041 and #9160 concern other attribute fields, not this guard.Tested
Windows 11 x86-64 (build 26300.9711), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON.Last executed validation of
271d428b2d, basef57ceaad6b(not a new run against 2026-10-24 main):guest_pthread*_testsexecutable targets, including current libkernel/libc. These register 27 pthread test cases.ctest --test-dir build -R '^guest_pthread' --output-on-failure --parallel 4: 27/27 passed.ctest --test-dir build -R '^guest_pthread_attr$' --repeat until-fail:25 --output-on-failure: 25 consecutive passes.git diff --exit-code main -- core/libs/prx, rebuilt, and reproducedpthread_attr_get_np returned 0, expected 3(CTest exit 8). Restored the guard, rebuilt and reran the entire pthread group: 27/27 passed. Working tree clean afterward.origin/main,git diff --check main...HEAD, and overlap checker pass, with the limitations and manual review above.Historical full-suite validation, old head
892138ed5c, basea6dcea9279(not results for this rebased head):ImageArrayWindowPastLayerLimit.cpp:33: alignment 65536 exceeded the Windows object-file maximum 8192. That source has since changed upstream; this is not a claim about its current build status.agc_driver_image_array_window_past_layer_limit. Failures wereagc_driver_sample_order,agc_driver_sample_order_grid_reference, andagc_driver_sample_order_recipe_depth_locations(depth/clear-value checks on the NVIDIA GeForce RTX 4060 Laptop GPU). All three reproduced with identical diagnostics after removing this fix and confirming runtime-library sources matched that main. No GPU code was changed.No author-performed console, title, Linux or macOS testing for this PR. Independent Linux and WSL reviewers report red/green checks on old head
892138ed5c; they are not retests of the latest head. Hosted product builds require a maintainer-triggered run.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-21T23:18:48Z.
Review: APPROVED
Reviewed the lifetime guard and failure-path tests. The function validates null arguments first, holds
LockLiveGuestThreadfor the full attribute copy, and returns POSIXESRCHwhen the registry no longer contains a live thread; this prevents detached-thread cleanup from racing the read. The test covers joined, finished-unjoined and detached threads, self-query from a thread-specific-data destructor, null inputs, unchanged destination attributes and unchanged guest errno. The author reports the focused pthread group passing 27/27 and 25 repeat runs, with full-suite failures reproduced on unchanged main and unrelated to this change. I compared the combined PR tree with #8041: the guard-size assignment and liveness check compose cleanly in the shared query, and both PRs’ separate focused tests remain present. Conventions, intake, eligibility, labels and report checks pass; hosted product jobs were skipped.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T00:04:38Z.
Review: COMMENTED
Linux run of the current change, since the description lists only Windows ("No console, title, Linux or macOS testing").
Machine: Linux x86_64, i7-8700 (6 cores / 12 threads), Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON. Head892138ed5merged ontomaina6dcea927(the merge touches onlyAttr.cpp,GuestPthreadAttr.cppand the debt doc).guest_pthread_attrpasses with the change (joined, finished-but-unjoined and detached threads, null arguments, preserved errno and the self-query cases).libkernel/Pthread/Posix/Attr.cpptomainand keeping the test abortsguest_pthread_attr: onmainpthread_attr_get_npreturns 0 for an ended thread where the test expects guestESRCH(3). So the regression reproduces on Linux as well and the test covers the change.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:16:25Z.
Review: APPROVED
Rechecked the lifetime guard and latest follow-up test report.
LockLiveGuestThreadremains held for the full attribute copy, returns POSIXESRCHfor ended threads, and the new tests preserve validation order, guest errno and output attributes on failure. The author reports the Windows 27-test pthread group and 25 repeats; a later reviewer also reports a Linux build/test pass and a main-runtime negative control that reproduces the bug. Full-suite GPU failures are reported as reproducible on main and unrelated. Hosted policy checks pass; product jobs are skipped. I did not run local tests.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T04:12:02Z.
Linux data point for
892138ed5c: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release,BUILD_TESTING=ON, PR head alone (not merged ontomain; its merge-base isa6dcea927).ctest -R '^guest_pthread_attr$'passes 3 of 3.libkernel/Pthread/Posix/Attr.cpprestored to the merge-base (the PR's tests kept): fails (Subprocess aborted).Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:29:52Z.
Review: DISMISSED
The lifetime fix and tests are well covered:
LockLiveGuestThreadstays held for the attribute read, ended threads returnESRCH, and tests include joined, finished-unjoined, detached, TSD-destructor, null-input and output/errno preservation cases. The Windows focused pthread group/repeats and WSL red-green reports are detailed; unrelated GPU failures are clearly distinguished and reproduced on the main baseline. The branch/test base isa6dcea9279, while current upstream main isab347d144d. Please rebase onto current main, rerun the focusedguest_pthread_attrgroup and conventions/overlap checks, preserving the #6044 test relocation and unrelated debt edits. Hosted product jobs are skipped; I did not run local tests.Imported from boykopovar/AnyPS5. Originally posted by valenciana-nc on 2026-10-22T15:33:24Z.
@MarcZX10 Addressed the rebase/retest request: rebased onto
b7d1d47a5f9f32c9c388ad8d47a0055a90ae6e33(new head6298429beb).git range-diffshows the same single-commit patch; no implementation/test changes beyond replaying it onto current main.Windows 11 x86-64 / WinLibs GCC 15.2.0 r7 / Release /
BUILD_TESTING=ON:ctest --test-dir build -R '^guest_pthread' --output-on-failure --parallel 4: 27/27 passed.guest_pthread_attr --repeat until-fail:25: 25 passes.core/libs/prxsources matchupstream/main, rebuilt and reproducedpthread_attr_get_np returned 0, expected 3. Restored the guard, rebuilt, and passed 27/27 again.origin/main, diff whitespace check, and overlap checker completed successfully. The overlap checker still has warnings, not an entirely clean report.Manual overlap verification: #6044's combined merge-tree places this test at
core/libs/tests/threads/GuestPthreadAttr.cpp, byte-for-byte identical to this PR's test; no conflict in that file (that PR still has unrelated pre-existing conflicts). Other upstream debt edits are preserved. #9684 has one documentation-only conflict because its stack-alignment entry is immediately adjacent to this PR's lifetime entry; no code/test conflict. Requested merge-order coordination on #9684, proposing this PR first and then retaining both debt updates on its rebase. No runtime dependency, and no agreed order is claimed.Updated the description to separate these new focused results from the historical full-suite run. Full suite, title execution, Linux and macOS were not rerun by me on the rebased head. Working tree clean. Ready for another review; hosted product builds still require a maintainer's manual run.
AI-assisted execution and report.