feat(libkernel): implement siglongjmp #2935

Merged
reyani-dev merged 1 commit from upstream-pr/2935 into main 2026-10-10 20:09:19 +00:00
reyani-dev commented 2026-10-10 18:34:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T18:34:52Z.


PokeMMO Prospero (PPSA98001) stops at siglongjmp (pebqbE5ws8s, libkernel.prx) on main, per @babyhuey's catalog run in #1578 (table, row siglongjmp, PPSA98001). This was posted there as a ready branch while intake was limited; it is still absent on current main, and no open PR implements it.

What

The title links its own (FreeBSD) sigsetjmp and imports only siglongjmp, so siglongjmp must read FreeBSD's amd64 sigjmp_buf layout. That layout is:

  • the return address at 0;
  • rbx, rsp (pointing at the return slot), rbp and r12–r15;
  • the x87 control word at 64;
  • the saved mask at 72;
  • the save-mask flag at 88.

The function is a direct translation of FreeBSD's __siglongjmp (lib/libc/amd64/gen/sigsetjmp.S), written in assembly in SignalSets.cpp:

  • when the flag is nonzero, it restores the saved mask through _sigprocmask(SIG_SETMASK, …);
  • it reloads the registers and the control word, then returns to the saved address with val, or 1 for 0.

It differs from FreeBSD in one respect: it tests the 32-bit val rather than all of %rsi, since the upper half is undefined for an int argument.

Tested

guest_signal_sets has a verbatim copy of FreeBSD's sigsetjmp in test assembly, standing in for the title's own. It checks that:

  • siglongjmp(buf, 0) returns 1 and siglongjmp(buf, 7) returns 7;
  • with the save flag set, the mask saved at sigsetjmp comes back even after another mask was set;
  • with the flag clear, the current mask is left alone.

Without the change the test does not link. A mutant that skips the mask restore fails it.

Windows 11 (WinLibs GCC 15.2.0), Release: guest_signal_sets passes 5/5 (--repeat until-fail:5), ctest -E "^agc_|video_out" 297/297, check_conventions.py passes, and pr_overlap.py reports no overlap. On the fork CI run, the Linux job passes, which covers the @PLT call path. The first Windows attempt hit guest_video_out_resolution_status (0xc0000374), which also fails on unmodified main here and passed in another run today. The rerun of the Windows job passes 573/573.

Static check on the title. I relinked PPSA98001 v1.0.2 (sha256 checked against the catalog record, eboot.bin and libc.prx unwrapped) with --registry on Windows and compared the imports with the built libraries using tools/import_audit.py. The absent imports go from 11 on main (c72d5ce1, and the same 11 on bc40a6b5) to 10 with this branch, and siglongjmp is no longer among them. The remaining 10 are atol, atoll, getprogname, malloc_usable_size, sqrt, sqrtf, frexpl, _umtx_op, pthread_sigmask and pthread_set_name_np, so the next runtime stop will be one of those. I did not execute the title.

The branch is rebased onto current main, and guest_signal_sets passes 3/3 there on Windows.

Side note, not changed here: the existing setjmp/longjmp in JumpBuffer.cpp use their own jmp_buf layout. It saves rsp after the return address, and puts MXCSR at 64 and the x87 control word at 68. FreeBSD saves the stack pointer at the return slot, with the control word at 64 and MXCSR at 68. That is fine while both halves are ours, but a title that pairs its own setjmp with our longjmp, or the reverse, would jump 8 bytes off. I can open an issue if that's worth tracking.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813527492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2935). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T18:34:52Z. --- PokeMMO Prospero (PPSA98001) stops at `siglongjmp` (`pebqbE5ws8s`, `libkernel.prx`) on `main`, per @babyhuey's catalog run in #1578 ([table](https://github.com/boykopovar/AnyPS5/issues/1578#issuecomment-6091750552), row `siglongjmp`, PPSA98001). This was posted there as a ready branch while intake was limited; it is still absent on current `main`, and no open PR implements it. ### What The title links its own (FreeBSD) `sigsetjmp` and imports only `siglongjmp`, so `siglongjmp` must read FreeBSD's amd64 `sigjmp_buf` layout. That layout is: - the return address at 0; - rbx, rsp (pointing at the return slot), rbp and r12–r15; - the x87 control word at 64; - the saved mask at 72; - the save-mask flag at 88. The function is a direct translation of FreeBSD's `__siglongjmp` (`lib/libc/amd64/gen/sigsetjmp.S`), written in assembly in `SignalSets.cpp`: - when the flag is nonzero, it restores the saved mask through `_sigprocmask(SIG_SETMASK, …)`; - it reloads the registers and the control word, then returns to the saved address with `val`, or 1 for 0. It differs from FreeBSD in one respect: it tests the 32-bit `val` rather than all of `%rsi`, since the upper half is undefined for an `int` argument. ### Tested `guest_signal_sets` has a verbatim copy of FreeBSD's `sigsetjmp` in test assembly, standing in for the title's own. It checks that: - `siglongjmp(buf, 0)` returns 1 and `siglongjmp(buf, 7)` returns 7; - with the save flag set, the mask saved at `sigsetjmp` comes back even after another mask was set; - with the flag clear, the current mask is left alone. Without the change the test does not link. A mutant that skips the mask restore fails it. Windows 11 (WinLibs GCC 15.2.0), Release: `guest_signal_sets` passes 5/5 (`--repeat until-fail:5`), `ctest -E "^agc_|video_out"` 297/297, `check_conventions.py` passes, and `pr_overlap.py` reports no overlap. On the [fork CI run](https://github.com/AchrafReyani/AnyPS5/actions/runs/38022700264), the Linux job passes, which covers the `@PLT` call path. The first Windows attempt hit `guest_video_out_resolution_status` (`0xc0000374`), which also fails on unmodified `main` here and passed in another run today. The rerun of the Windows job passes 573/573. **Static check on the title.** I relinked PPSA98001 v1.0.2 (sha256 checked against the catalog record, `eboot.bin` and `libc.prx` unwrapped) with `--registry` on Windows and compared the imports with the built libraries using `tools/import_audit.py`. The absent imports go from 11 on `main` (c72d5ce1, and the same 11 on bc40a6b5) to 10 with this branch, and `siglongjmp` is no longer among them. The remaining 10 are `atol`, `atoll`, `getprogname`, `malloc_usable_size`, `sqrt`, `sqrtf`, `frexpl`, `_umtx_op`, `pthread_sigmask` and `pthread_set_name_np`, so the next runtime stop will be one of those. I did not execute the title. The branch is rebased onto current `main`, and `guest_signal_sets` passes 3/3 there on Windows. Side note, not changed here: the existing `setjmp`/`longjmp` in `JumpBuffer.cpp` use their own `jmp_buf` layout. It saves rsp after the return address, and puts MXCSR at 64 and the x87 control word at 68. FreeBSD saves the stack pointer at the return slot, with the control word at 64 and MXCSR at 68. That is fine while both halves are ours, but a title that pairs its own `setjmp` with our `longjmp`, or the reverse, would jump 8 bytes off. I can open an issue if that's worth tracking. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
reyani-dev commented 2026-10-10 18:56:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T18:56:58Z.


Full Linux and Windows builds and tests for this head (0272f99a), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (bf6e25a1):

Job Result
linux success; full build, ctest: 703/703 passed
windows success; full build, ctest: 711/711 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/38076425655

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101046423 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2935#issuecomment-6101046423). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T18:56:58Z. --- Full Linux and Windows builds and tests for this head (`0272f99a`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`bf6e25a1`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/38076425655/job/114284809248) | success; full build, `ctest`: 703/703 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/38076425655/job/114284809263) | success; full build, `ctest`: 711/711 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/38076425655
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2935
No description provided.