Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@2Swagger thanks, the safe-point design reads well: the epoch loop that re-checks
Small wording point for the same entry: it says a target blocked in a host call is suspended only after the call returns. Please add that |
|
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.
|
…export Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@oneandonlydean thanks for the careful review. All three points are addressed:
Tested at 1126f64, merged onto
I also added #10817 and #11441 to Depends on. Both are older, and |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
One more fix, found while planning A title's main thread isn't created with New case in
Tested at 7831f0e, merged onto
|
|
@2Swagger the loader-lock fix reads right to me: FrozenCode only uses VirtualQuery and the cached image kinds while the target is frozen, and ClassifyImage runs after ResumeThread. One small robustness point on Linux, not blocking: the retry loop in RequestGuestThreadPark stops only when the target parks, the suspend is withdrawn, or pthread_kill returns ESRCH. It doesn't check that the target is still live, as the Windows loop does with Exited(). For an adopted thread, SuspendGuestThread also holds no reference while it polls, and that PthreadPrivate is freed when the host thread exits. So a target that exits in host code while it is being suspended can be read after it is freed, or signalled after its pthread_t is gone. Could you check GuestThreadIsLive in that loop (and send the signal while holding the live-thread lock)? |
…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>
|
@oneandonlydean thanks, you were right. AddressSanitizer confirmed it, and it's fixed. Fix (a7fb496):
Also fixed:
New case in
Tested at 039d7c7, merged onto
|
|
Windows check of head Setup: Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 (r7), Ninja, Release,
AI-assisted: yes. |
|
Linux and Windows check of head Linux 6.18, GCC 16, Release.
Windows, WinLibs GCC 15, Release. The 9 Nov check above saw the test time out at 30 s in 2 of 3 runs, in a build that also carried other open PRs. With only this PR on
No run came near the 30 s limit, so the earlier timeouts look tied to that combined build or that machine, not to this head on its own. Not covered: macOS, the console, and the stacked #12642. AI-assisted: yes. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this; the points below are optional. The review read the diff of all 12 changed files at head 56e24d1b14647cdd7111772e2d7686827c521837, but no build or test was run and the full file text was not read.
What I ran
- Head
56e24d1b14647cdd7111772e2d7686827c521837, basemain. No merged-preview check. - Read the change description, commit list, manifest, exclusion list and
diff.patch. - Read the house rules sections for readable reviews, the standard response format and accuracy and evidence.
- Read head context with the repository reader:
Commands
python3 repo_read.py cat core/libs/prx/libkernel/System/src/Exception.cpp 1640 1672
python3 repo_read.py cat core/libs/prx/libkernel/Time/TimedWait.cpp 336 352
python3 repo_read.py cat core/libs/prx/libkernel/Time/TimedWait.cpp 484 494
python3 repo_read.py search SIGUSR2
python3 repo_read.py search DeliverDeferred
python3 repo_read.py search SleepNanos
Results
| Check | Result | Note |
|---|---|---|
| Diff of 12 files | passed | Read from diff.patch |
| Full file text | not run | Nothing read from files/ |
| Build and tests | not run | Builds are out of scope for this review |
| Author's test runs | not applicable | Reported in the description, not reproduced |
Findings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/System/src/Exception.cpp:1656(Windows only): the throw is reached only when the compare-exchange onpendingExceptionfails and the stored value is 0 or less. A new raise on a suspended thread takes the first branch and returns 0 without throwing. The Linux branch has no suspended check at all. So the claim thatsceKernelRaiseExceptionon a suspended thread throws does not match the code as read, unlesspendingExceptioncan hold a negative value, which I did not check. See the debt entry atdocs/dev/debt/libkernel_sys.md:391, which says it throws without a platform qualifier.core/libs/prx/libkernel/System/src/Exception.cpp:40-44: the new__linux__block adds<link.h>and<string_view>, which the existing__linux__block below already includes. Harmless, but a duplicate.
Sources
- Exception check, head:
AnyPS5/core/libs/prx/libkernel/System/src/Exception.cpp
Lines 1653 to 1660 in 56e24d1
- Debt entry, head:
AnyPS5/docs/dev/debt/libkernel_sys.md
Line 391 in 56e24d1
Not verified
- Full text of all 12 files, read only as diff. No file under
files/was read. - The Windows park path (
SuspendThread,GetThreadContext, the APC park, theosParkedhandoff withResumeThread): read as diff only, and the race reasoning was not checked against a run. - Linux
SIGUSR2: the only production host use in the head isException.cpp, but I did not check whether guest signal delivery uses a hostSIGUSR2anywhere else. The head search matched a test inlibSceAgcDriverand a guest signal number inGuestSignalList.cpp. - Whether
ParkCurrentGuestThread_nid_no_patchis visible fromTime.cpp(the include list was not read). - Console behaviour is unmeasured, as the description says. The author's Windows and Linux test runs were not reproduced here.
To get this to a good state
Nothing is required.
Optional, once:
- Make the debt entry and the
sceKernelRaiseExceptioncheck agree: state the throw is Windows-only and for the negative-pending case, or move the check ahead of the compare-exchange. - Remove the duplicate
<link.h>and<string_view>includes inException.cpp.
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
|
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.
This head conflicts in the fault-delivery code in Exception.cpp and overlaps #21464 on the exported pthread_suspend_np implementation. Please coordinate those entry points and preserve the current signal-delivery setup when rebasing the narrower change.
AI-assisted: yes.
What
Implements
pthread_suspend_npin libkernel_sys, following FreeBSD 11.4 libthr (thr_suspend_np.c):EINVALfor a null thread,ESRCHfor a finished one,EDEADLKfor the caller, otherwise 0 once the target is suspended. It builds on the create-suspended and resume side from #9573, sopthread_resume_np,pthread_resume_all_npandpthread_multi_npresume it unchanged.A running thread is only ever stopped at a safe point, where it holds no host lock, so suspending a thread can't stall the emulator itself (the kind of freeze #10666 describes for exception delivery):
SuspendThreadand stays frozen until resumed; on Linux aSIGUSR2handler parks it when the interrupted address is in the main executable or a*.guest.prx(code ranges collected withdl_iterate_phdroutside the handler).TimedWaitdelivery scope, and a newTimedWait::SuspendSafeWaitscope marks the Linux mutex waits inMutex.cppthe same way.sceKernelUsleep,nanosleep,usleepandsceKernelSleep(all throughCancellableSleep) park a thread with a pending suspend.Parked threads wait on a per-thread epoch word (a raw futex on Linux, so the signal handler stays async-signal-safe), and threads created suspended now park through the same function. A start flag closes the race between
pthread_createand the first suspend.docs/dev/debt/libkernel_sys.mdgets an entry for the gaps: a thread that spends nearly all its time in host calls is suspended late (withscePthreadRenamecalled back to back: median 160-205 ms and worst 1.3 s per suspend on Windows 11, median under 0.1 ms and worst 3 ms on Linux), a thread blocked in a host call outside the libkernel waits is suspended only after the call returns while FreeBSD suspends it at once, andsceKernelRaiseExceptionon a suspended thread throws, as for one created suspended.pthread_suspend_all_np,pthread_single_npand the sce forms still throw.Tested
guest_pthread_suspend: error codes; a thread created suspended stays parked; a spinner in guest code, a thread looping onsceKernelUsleep(200), and a thread that renames itself under its name lock while the caller reads that name during each suspend (40 suspend/resume rounds each, checking the target makes no progress while suspended and continues after resume); a thread blocked on a mutex stays suspended after the mutex is released and takes it only after resume; a cancel sent to a suspended thread takes effect only after resume; a spinner is suspended and resumed 40 times while another thread keeps creating and joining threads; a host thread that became a guest thread throughscePthreadSelf(as a title's main thread does) is suspended and resumed 40 times; such a thread makes a 2 ms host call and exits while it is being suspended, 200 times (also run 20 times under AddressSanitizer on Linux, no reports). About 3 s per run.mainfd9b3f6. Windows 11 (WinLibs GCC 15.2.0, Release):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 pass, 73 of 73. Linux (Ubuntu 24.04 under WSL2, GCC 13.3.0, Release): the same set as registered there, 69 of 69.guest_pthread_suspendandguest_pthread_create_suspendedpassed 20 consecutive runs each on both platforms with the code of b09a133 (ctest --repeat until-fail:20), and 200 each at 039d7c7, before the 256-segment check. The check itself is defensive: no practical test loads 257 executable guest segments.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