Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…export Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nded Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-np # Conflicts: # docs/dev/debt/libkernel_sys.md
…eave the thread list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gle_np Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Progress report (3a2b919 → 4a30c0b)📈 System libraries: 45.93% (+0.02%, +3 implemented functions) ✅ 3 implemented
Changed libraries (implemented exports)
|
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
|
Windows run of this head (
AI-assisted: yes (Claude Code). |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: unblock or otherwise reliably deliver the Linux park signal to targets whose inherited signal mask blocks it.
What I ran
Reviewed head 4a30c0bf9f5d8dcd374d8b9bfa8fe3ddded6c4ed using the prepared diff and repo_read.py; I ran no commands or tests. The test results in the PR description are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | Found a Linux signal-mask hang risk |
| Tests in this review | not run | No execution environment was available |
| Console behavior | not run | PR also reports this as untested |
Negative control
Not run; no test execution was available.
Findings
Blocking
- On Linux,
RequestGuestThreadParkrelies onSIGUSR2to interrupt the target, but guest threads inherit their creator’s signal mask and restore it before running. If that mask blocksSIGUSR2, the handler cannot run and the suspend call keeps resending the blocked signal while waiting for the target to park. Ensure the park signal is deliverable to guest threads even when inherited masks block it, while preserving the guest-visible signal mask. The signal handler installation and reliance onSIGUSR2are introduced atcore/libs/prx/libkernel/System/src/Exception.cpp:410andcore/libs/prx/libkernel/System/src/Exception.cpp:1234. Pinned source
Non-blocking
None.
Not verified
No tests or console checks were run. I read the prepared description, commits, manifest, and diff; targeted source ranges in Thread.cpp, Exception.cpp, TimedWait.cpp, TimedWait.hpp, Pthread.hpp, Mutex.cpp, Export.Discovery.cpp, and Time.cpp; and the opening portion of GuestPthreadSuspendAll.cpp. I did not read the full text of every changed file, including the complete test sources. files.json was unavailable through the reader, so excluded-file details are not verified.
To get this to a good state
Make the Linux park signal reliably deliverable despite inherited signal masks, add coverage for a target created while that signal is blocked, and rerun the relevant suspend tests.
|
For information: CodeRabbit's review of #21464, which is stacked on this PR, flagged several suspension races in code that comes from this PR. Fixes for them are on #21464's branch ( |
ligmaSec
left a comment
There was a problem hiding this comment.
SuspendAllGuestThreads_nid_no_patch marks every live peer suspended before waiting for individual acknowledgements. On an exception from the host park path, the slot is released by RAII, but there is no corresponding rollback for the other peers whose state was changed in the first pass. Please restore only the suspensions owned by this invocation on failure, preserving peers already suspended by a prior call. The trial merge conflicts in Thread.cpp and Exception.cpp, and the debt change needs a fragment.
AI-assisted: yes.
|
I am closing this draft as stale: there has been no push since 28 Oct and it is still unfinished. The change implements pthread_suspend_all_np and pthread_single_np in libkernel_sys, and it still needs a rebase and the open review points. It can be reopened or re-pushed on a fresh main any time and we will look at it again. |
Stacked on #12130: this diff includes #12130's commits until it merges. PR B's own change is commit 1a0176a.
What
Implements
pthread_suspend_all_npandpthread_single_npin libkernel_sys, following FreeBSD 11.4 libthr (thr_suspend_np.c,thr_single_np.c).pthread_suspend_all_npsuspends every other thread and returns once all of them are suspended;pthread_single_npcalls it and returns 0. It builds onpthread_suspend_npfrom #12130 and reuses its safe points, so a thread is only ever stopped in guest code, in a libkernel wait or when a libkernel sleep returns._single_threadlock, only one thread at a time may runpthread_suspend_all_nporpthread_resume_all_np(which now takes the same slot, asthr_resume_np.cdoes). A thread waiting for the slot checks it every 1 ms and parks there if it has been suspended. So when two threads callpthread_suspend_all_npat once, the first one suspends the second, and the second goes on only after the first resumes everyone.check_suspend. Apthread_suspend_npaimed at the caller takes effect after the caller leavespthread_suspend_all_np. While a thread waits inpthread_suspend_npit can be suspended itself, so a suspend-all never waits on a thread that is waiting on it.scePthreadSelfand has since exited, which stays in the thread list on Windows.no_cancel) and then calls_thr_testcancel. Here cancellation is not switched off: nothing insidepthread_suspend_all_npis a cancellation point, so a cancel cannot take effect midway, and the pending-cancel check at the end (scePthreadTestcancel, as the existingpthread_resume_all_npexport does) gives the same result.The
pthread_suspend_npdebt entry indocs/dev/debt/libkernel_sys.mdnow covers both functions. It adds thatpthread_suspend_all_npwaits for each thread in turn, so one that is busy in host calls delays the whole call.scePthreadSuspendAllandscePthreadSinglestill throw; their sce error values are unmeasured.Tested
guest_pthread_suspend_all, about 1 s per run:sceKernelUsleep(200)loop, ascePthreadRenameloop) stop underpthread_suspend_all_npand continue afterpthread_resume_all_np, 20 rounds.pthread_single_npreturns 0 and stops a spinner and a thread blocked on a mutex; the blocked thread does not take the mutex released meanwhile.pthread_multi_nplets both continue.pthread_suspend_npand a thread created suspended stay stopped through suspend-all, and both run after resume-all.pthread_suspend_all_npat once, and both finish.pthread_suspend_all_np. It exits as cancelled, and its cleanup handler sees every other thread stopped before it resumes them.pthread_suspend_npon another while that one is in a 50 ms host call just before callingpthread_suspend_all_np. Either the suspend lands before the suspend-all, or the suspend-all suspends the waiting thread and the suspend lands after it returns. In both casespthread_suspend_npreturns with the target stopped. A followingpthread_resume_all_npfrom the main thread would block if a suspended thread still held the slot. The test doesn't record which order happened.main35f59e4):guest_pthread_suspend_all,guest_pthread_suspend,guest_pthread_create_suspended,guest_exception_handler,guest_raise_exception,guest_raise_nested_sleep,guest_mutex_raise_exception,guest_raise_in_host_code,guest_raise_leaves_host_codeandpublic_headerswith its compile batches, 74 of 74 passed.guest_pthread_suspend_all,guest_pthread_suspendandguest_pthread_create_suspendedpassed 200 consecutive runs each (ctest --repeat until-fail:200).main319621b, before the latest merge ofmain: the same set as registered there, 70 of 70 passed, and the same three tests passed 200 consecutive runs each. That merge brought no change to the suspend code.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)🤖 Generated with Claude Code