feat(libc): export _setjmp and _longjmp #12149
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12149"
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 AlexFigas on 2026-10-27T23:44:35Z.
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
88f89fcdd6mergesmain1a5267fd3finto the previous head03c2195878(main4ac683fe02), which had merged into4ce41adcaf(main98ddd9c179before 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: #12682 adds the context save and restore to_setjmpand_longjmp, and #12682, #12688, #12700 and #12965 declareDepends on: #12149, so the overlap the tool reports with them (_setjmp,_longjmpandGuestUnderscoreJumps.cpp) is this PR's commit inside their stack.main, #5021 (ARM64 AOT, which touchesJumpBuffer.cpp) among them. Merged with this branch, all give the same conflicts as merged withmain(git merge-tree) except #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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:48:52Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The implementation and test report are detailed, but this branch is based on
main2227f13661, while currentmainis52c09d567d2fa453494dd720fcf53a98149468e4(500 commits ahead of the branch).CONTRIBUTING.mdrequires each branch to be based on currentmain. The reportedguest_underscore_jumpsandguest_signal_setsruns therefore do not validate the current integration state.What I ran
081d5fd372ca845f8fef72a3623cefeec589bfaband its declared base.git diff --checkagainst currentmain.Results
mainis not in the branch historygit diff --check2227f13661; no run against current52c09d5is reportedPlease refresh the branch onto current
mainand 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.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T11:07:49Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The new report supplies exact-head runs for
guest_underscore_jumpsandguest_signal_sets, plus the two exports. The branch is based on1b580f13cf; currentmainisba5b5330b3. Since that base, current main changed this PR'slibkernel/CMakeLists.txtanddocs/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 on056c4b4f4a; they do not validate the current-main integration.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T10:06:27Z.
Review: CHANGES_REQUESTED
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 upstreammainb7488e1ff53e6cfca82af972df1d09fa71e7051d; it merged cleanly. Environment: Linux 6.1.0-54-amd64, x86_64; no compiler or build was run.Results
libc___cxa_finalizealias warning is unrelated. I inspected the assembly definitions manually.${LIBS_INCLUDE_DIR}; the PR explicitly registersguest_underscore_jump_testsandguest_underscore_jumps.guest_underscore_jumps.guest_underscore_jumpsandguest_signal_setseach 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
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 showsJumpBufferSaveMask_nid_no_patchstores a per-jump context at offset 92 andJumpBufferRestoreMask_nid_no_patchrestores it. This PR's new_setjmponly writes the flag at offset 88 and_longjmpdoes 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 saysDepends on: noneand 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
Not verified
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.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T03:42:47Z.
Review: APPROVED
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, base98ddd9c1792bbab016ceed5db267a93d1d61f00a, 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.Results
guest_underscore_jumpsandguest_signal_setseach passed three runs on head4ce41adcafb39c2bb083fd2574a9a5533c6833f9under WSL2.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
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.