Repository navigation
feat(libc): export _setjmp and _longjmp - #12149
Conversation
|
Windows run of
AI-assisted: yes (Claude Code) |
|
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.
|
5f05c8e to
6c33498
Compare
6c33498 to
081d5fd
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
The implementation and test report are detailed, but this branch is based on main 2227f13661, while current main is 52c09d567d2fa453494dd720fcf53a98149468e4 (500 commits ahead of the branch). CONTRIBUTING.md requires each branch to be based on current main. The reported guest_underscore_jumps and guest_signal_sets runs therefore do not validate the current integration state.
What I ran
- Reviewed exact head
081d5fd372ca845f8fef72a3623cefeec589bfaband its declared base. - Ran a merge preview and
git diff --checkagainst currentmain. - Checked the exact-head test report and current hosted-check scope.
Results
| Check | Result |
|---|---|
| Current-main merge preview | Clean, but current main is not in the branch history |
git diff --check |
Passed |
| Focused tests | Author reports 3 runs each on base 2227f13661; no run against current 52c09d5 is reported |
| Windows/macOS behavior | Not tested in the report |
Please refresh the branch onto current main and rerun the focused jump/signal tests on that exact head. I have not independently built or run the C++ tests, so I am not approving the stale integration snapshot.
They save and restore what setjmp and longjmp do without the signal mask. _longjmp keeps the current MXCSR exception flags and takes the other MXCSR bits from the buffer, as the bundled libc.prx's _longjmp (J03093718, 0x1153e0) and FreeBSD's ___longjmp do, and on Windows it moves the TEB stack bounds as longjmp does. _setjmp writes 0 where setjmp marks a saved mask, so longjmp restores none from its buffer.
081d5fd to
056c4b4
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — changes requested
The new report supplies exact-head runs for guest_underscore_jumps and guest_signal_sets, plus the two exports. The branch is based on 1b580f13cf; current main is ba5b5330b3. Since that base, current main changed this PR's libkernel/CMakeLists.txt and docs/dev/debt/libc.md. Please merge current main and rerun the focused tests and export check on the resulting exact head. I am not disputing the reported results on 056c4b4f4a; they do not validate the current-main integration.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
I reviewed head 4ce41adcafb39c2bb083fd2574a9a5533c6833f9; before approval, the required landing-order agreement with open PR #12688 needs to be resolved because its jump-buffer context changes affect the new underscore variants.
What I ran
Head: 4ce41adcafb39c2bb083fd2574a9a5533c6833f9; PR base: 98ddd9c1792bbab016ceed5db267a93d1d61f00a. I also previewed the PR against current upstream main b7488e1ff53e6cfca82af972df1d09fa71e7051d; it merged cleanly. Environment: Linux 6.1.0-54-amd64, x86_64; no compiler or build was run.
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 12149
git diff --check 98ddd9c1792bbab016ceed5db267a93d1d61f00a...refs/review/pr-12149-current
python3 tools/check_conventions.py --base 98ddd9c1792bbab016ceed5db267a93d1d61f00a --head refs/review/pr-12149-current --title 'feat(libc): export _setjmp and _longjmp' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-12149-4ce41adcafb3/pr-body.md
python3 tools/pr_abi_audit.py --base 98ddd9c1792bbab016ceed5db267a93d1d61f00a --head refs/review/pr-12149-current --json
python3 tools/pr_test_quality.py --root /marc/AnyPS5 --json core/libs/tests/GuestUnderscoreJumps.cpp core/libs/prx/libkernel/CMakeLists.txt
git merge-tree --write-tree refs/remotes/upstream/main refs/review/pr-12149-currentResults
| Check | Result |
|---|---|
| Precheck, diff, conventions, dependency/mergeability | Precheck completed on the exact head/base; diff and conventions pass; current-main merge preview is clean. |
| ABI audit | Passed with lexical warnings: assembly-defined jump symbols are not recognized by the audit; the separate libc___cxa_finalize alias warning is unrelated. I inspected the assembly definitions manually. |
| Test quality and registration | Heuristic flagged the new test path because CMake uses ${LIBS_INCLUDE_DIR}; the PR explicitly registers guest_underscore_jump_tests and guest_underscore_jumps. |
| Hosted Windows | Job passed, but its log says no changed guest test sources were found, so it did not run guest_underscore_jumps. |
| Hosted macOS write-watch | Both jobs failed during separate write-watch CMake configuration because duplicate test names were declared; these jobs do not test this PR's changed paths. |
| Hosted Linux | Skipped. |
| Author-reported focused tests | The author reports guest_underscore_jumps and guest_signal_sets each passed 3 runs on this exact head under WSL2; I did not run these tests locally. |
Unedited output from local checks and relevant CI log lines
git diff --check: [no output; exit code 0]
All conventions checks passed.
ABI audit summary:
status: passed_with_warnings
_longjmp_nid_postfix: definition-not-found — No APS5_VABI definition was found in the head tree; check assembly aliases, generated definitions, and platform guards.
_setjmp_nid_postfix: definition-not-found — No APS5_VABI definition was found in the head tree; check assembly aliases, generated definitions, and platform guards.
libc___cxa_finalize: nid-alias-differs-from-symbol-hash — Explicit NID H2e8t5ScQGc differs from computed symbol NID z5JcC5WSmyA; verify intentional aliasing.
longjmp_nid_postfix: definition-not-found — No APS5_VABI definition was found in the head tree; check assembly aliases, generated definitions, and platform guards.
setjmp_nid_postfix: definition-not-found — No APS5_VABI definition was found in the head tree; check assembly aliases, generated definitions, and platform guards.
Test-quality heuristic:
{
"findings": [
{
"path": "core/libs/tests/GuestUnderscoreJumps.cpp",
"line": 1,
"kind": "possible-unregistered-cpp-test",
"message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
}
],
"negative_control_candidates": [],
"limits": [
"Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
"A test that passes against base is not by itself proof that the PR test is inadequate.",
"Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
]
}
Current-main merge preview:
5203c1bb2dd09865d37cbe3b2aaf88c2615345ec
Windows test step:
No guest core/libs test sources changed
No guest core/libs test sources changed; the libs build still ran
macOS write-watch CMake errors:
CMake Error at CMakeLists.txt:42 (add_test):
add_test given test NAME "write_watch_execute-fault" which already exists
CMake Error at CMakeLists.txt:42 (add_test):
add_test given test NAME "write_watch_read-fault" which already exists in
Negative control
I did not run a local negative control: this no-build review did not compile the changed test or binary.
Findings
Blocking
The repository's overlap rule requires authors of PRs touching the same lines/files to agree on landing order and record any dependency. The overlap notice identifies #12688 as sharing core/libs/prx/libc/src/JumpBuffer.cpp; inspecting its exact head shows JumpBufferSaveMask_nid_no_patch stores a per-jump context at offset 92 and JumpBufferRestoreMask_nid_no_patch restores it. This PR's new _setjmp only writes the flag at offset 88 and _longjmp does not save or restore offset 92. If #12688 lands first, underscore jumps will not follow that context behavior; if this PR lands first, #12688's author needs to account for the new entry points. The checklist currently says Depends on: none and does not record an agreed order.
Please coordinate with #12688's author, record the agreed order and dependency (if any) in the checklist, and ensure the selected integration order covers context save/restore for the underscore variants where required. I found no separate blocking source defect in this PR's standalone current-main preview.
Non-blocking
The current hosted workflow does not exercise the new guest test on Windows, and Linux is skipped. The author's exact-head WSL2 results are useful but are not an independent run from this review environment.
Sources
- Repository overlap and dependency rule, pinned to current main
- This PR's underscore jump implementation at its reviewed head
- PR #12688 context save/restore implementation at its current head
- Author's exact-head focused test report
Not verified
- No local compilation or test execution; no physical-console or title run.
- The Windows hosted job did not execute the changed guest test, and Linux CI was skipped.
- macOS product behavior was not tested by the failed write-watch jobs; their failures occurred during CMake setup for that separate test project.
To get this to a good state
Please record the agreed #12149/#12688 order and the required underscore-buffer context handling in the PR checklist or code as appropriate. I will rerun the same relevant checks against the updated head.
|
@MarcZX10 Thanks, that's right: the context save and restore comes from #12682, and #12688 is stacked on it, both by Felipebmaitan. I asked him on #12682 to agree an order. The two options:
The Overlap section records this. I'll update the checklist once he answers. |
Re-checked — dependency still unresolvedThe head remains |
|
@AlexFigas Agreed on #12149 first. It is still open at |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — new evidence, looks good
The blocking order concern is resolved: #12682's author agreed that #12149 lands first and confirmed the dependent change will add the I/O context save/restore and declare Depends on: #12149.
What I ran
Rechecked live PR head 4ce41adcafb39c2bb083fd2574a9a5533c6833f9, base 98ddd9c1792bbab016ceed5db267a93d1d61f00a, and the new discussion reply. The no-build precheck below was previously run on this unchanged head/base; I did not rebuild or rerun C++ tests for this follow-up.
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 12149Results
| Evidence | Result |
|---|---|
| Existing exact-head review | Source, tests, conventions, and current-main merge preview were reviewed; no standalone blocking code finding was recorded. |
| Author-reported focused run | guest_underscore_jumps and guest_signal_sets each passed three runs on head 4ce41adcafb39c2bb083fd2574a9a5533c6833f9 under WSL2. |
| Hosted CI | Windows job passed but did not execute the changed guest test; Linux was skipped. macOS write-watch jobs failed during CMake setup on duplicate test names in that separate project. |
| Dependency discussion | #12682 author explicitly confirmed the landing order and the follow-up dependency/context work. |
Findings
Blocking: None. The agreed order allows this standalone export PR to land before the dependent I/O-context change.
Non-blocking: The author says #12682 will record the dependency and add context handling in that PR; its checklist/update is still pending there. This does not block #12149 under the agreed order.
Sources
- Author agreement on #12149 landing first and the dependent context changes
- Reviewed jump implementation
- Author's exact-head focused test report
Not verified
I did not independently rebuild or rerun the guest tests in this follow-up. The hosted Linux job is skipped, and the Windows job did not execute the changed guest test. No console/title behavior was tested.
|
@MarcZX10 The approved head 4ce41ad still merges cleanly into current |
|
@MarcZX10 #13220 has landed, so I merged |
|
@MarcZX10 Head 88f89fc merges current |
✅ AMD GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (15, not counted against this PR)Validation IDs already present on main (4 IDs in 769 tests)Skipped (61)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
What
AnyPS5's libc had
setjmpandlongjmpbut not_setjmpand_longjmp, the BSD forms that leave the signal mask alone. Thelibc.prxbundled with PPSA21564 (buildJ03093718) exports both, and this PR adds them.That binary's four functions differ only in the signal mask:
setjmp(0x548b0). It calls_sigprocmask(SIG_BLOCK, NULL, buffer + 0x48), then runs the same register saves as_setjmp(0x1153a0).longjmp(0x54900). It calls_sigprocmask(SIG_SETMASK, buffer + 0x48, NULL), then runs the same restores as_longjmp(0x1153e0)._longjmp. It keeps the current MXCSR exception flags and takes only the other MXCSR bits from the buffer. A value of 0 returns 1.This matches FreeBSD 11.4's
_setjmp.S._setjmpand_longjmphere aresetjmpandlongjmpfromJumpBuffer.cppwithout the signal-mask calls, in the same buffer layout. So a buffer from eithersetjmpis accepted by eitherlongjmp, as on FreeBSD._setjmpwrites 0 at 88, wheresetjmpmarks a saved mask. Alongjmpto its buffer therefore restores no mask, where the binary would read whatever is at 0x48._longjmpkeeps the current MXCSR exception flags as the binary does. On Windows it callsGuestStackSwitch_nid_no_patchwith the target stack pointer before switching, aslongjmpdoes.The debt entry records what still differs from the binary: the layout (the binary stores the stack pointer at the call, the x87 control word at 64 and MXCSR at 68), the 0 at 88, and that
longjmprestores the saved MXCSR exception flags where the binary's keeps the current ones.Tested
On Ubuntu 24.04.5 under WSL2 (GCC 13.3, Release). Head 88f89fc merges
main1a5267f into the previous head 03c2195 (main4ac683f), which had merged into 4ce41ad (main98ddd9c before it, merged into this PR's commit).mainhas #13220, so the macOSwrite-watchjobs no longer stop at their CMake configure, and it restoredcheck_skips.pyafter #14881, so thecheck_skipstests that failed the relinker jobs pass again.guest_underscore_jumps. It links libkernel so thatsigprocmaskis registered, and passes 3 runs on this head:rbx,rbpandr12-r15, calls_setjmp, clears them and_longjmps back with 42. All six come back._setjmpleaves offsets 72-87 and 92 of a filled buffer untouched and writes 0 at 88. After_longjmpthe mask set before the jump stays.longjmpto a_setjmpbuffer restores no mask, and_longjmpto asetjmpbuffer (flag 1 at 88) restores none either._setjmp, and round-to-nearest, 64-bit precision and the IE, ZE and PE flags at_longjmp, the jump restores round-toward-zero and 53-bit precision, keeps IE, ZE and PE, and leaves the exception masks unchanged.guest_signal_sets(setjmp,longjmp,sigsetjmp,siglongjmp) still passes (3 runs).libc.prxbuilt from this head exportssjpkrhugvVI(_setjmp) and+F+9hhi6k9Q(_longjmp).GuestStackSwitch_nid_no_patchcall aslongjmp.python3 tools/check_conventions.py --base origin/mainpasses.python3 tools/pr_overlap.py --branch feat/libc-underscore-setjmplists no pull request with the same exports or conflicting lines.setjmp, longjmpdebt line. The new entry sits one line below it, andgit merge-treemerges both with this branch without conflicts.setjmp,longjmp,sigsetjmpandsiglongjmpsave an I/O context at offset 92 and restore it throughGuestIoStackRestore_nid_no_patch. Neither conflicts with this PR, but_setjmpand_longjmpneed the same two calls. Its author agreed that this PR lands first: feat(libkernel): cancel blocked POSIX reads with owned operations #12682 adds the context save and restore to_setjmpand_longjmp, and feat(libkernel): cancel blocked POSIX reads with owned operations #12682, fix(libkernel): preserve blocking sockets over nonblocking native transport #12688, feat(libkernel): cancel blocked POSIX writes with partial progress #12700 and feat(libkernel): support deferred cancellation in POSIX accept #12965 declareDepends on: #12149, so the overlap the tool reports with them (_setjmp,_longjmpandGuestUnderscoreJumps.cpp) is this PR's commit inside their stack.main, feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021 (ARM64 AOT, which touchesJumpBuffer.cpp) among them. Merged with this branch, all give the same conflicts as merged withmain(git merge-tree) except docs(debt): separate entries with blank lines and drop derived export totals #14212, which rewrites every debt file and gets one more conflict hunk inlibc.md; it has no review yet and this PR does not wait for it.__std_min_8idebt line right below the new entry. It no longer conflicts withmain, so merged with this branch it conflicts in that onelibc.mdhunk, which keeps both lines. It has no review yet and this PR is approved, so I leave the order to be agreed there.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)