feat(libkernel): implement sigaltstack #2107

Merged
LeandroLP23 merged 1 commit from upstream-pr/2107 into main 2026-10-09 21:56:02 +00:00
LeandroLP23 commented 2026-10-09 08:41:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-09T08:41:29Z.


What

PICO-8 for PS5 (PPSA99808 v0.1.2, RafaelNGP/pico8-ps5, GPL-3.0) stops at start-up on this import once its earlier stops resolve (chain in #1578):

FAIL: unresolved ELF import sHziAegVp74 from libkernel.prx

sHziAegVp74 is sigaltstack (tools/nid_names.py). It follows FreeBSD's kern_sigaltstack with the amd64 stack_t (ss_sp, ss_size, ss_flags at 16, 24 bytes):

  • each thread has its own alternate stack, disabled at start (SS_DISABLE, null and 0);
  • flags other than SS_DISABLE give EINVAL, a size below MINSIGSTKSZ (2048) gives ENOMEM; on error it returns -1 with errno set and writes nothing;
  • SS_DISABLE keeps the recorded pointer and size and only marks the stack disabled, and the old stack is reported as it was before the call.

Handlers never run on the alternate stack here, so SS_ONSTACK and EPERM are never reported; recorded in TechnicalDebt.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, Release, main d70b8998:

  • PICO-8, with the earlier stops' pull requests merged locally, gets past this import and stops at the next one, ZSnX-xZBGCg from libSceLibcInternal.prx (stpcpy, #1812).
  • New guest_sigaltstack test: the initial state, the three error cases with the old stack untouched, installing at exactly 2048 bytes, replacing, a second thread seeing its own disabled stack, and disabling. Removing the size check makes it fail.
  • tools/check_conventions.py passes.

Fork CI on this head rebased onto main d70b8998 (with the build workflow from before 0ab2a04d, since the new one needs an upstream pull request number): https://github.com/LeandroLP23/AnyPS5/actions/runs/37921144213, all jobs pass (Windows 508/508, Linux 517/517).

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4798130584 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2107). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-09T08:41:29Z. --- ### What PICO-8 for PS5 (PPSA99808 v0.1.2, [RafaelNGP/pico8-ps5](https://github.com/RafaelNGP/pico8-ps5), GPL-3.0) stops at start-up on this import once its earlier stops resolve (chain in [#1578](https://github.com/boykopovar/AnyPS5/issues/1578#issuecomment-6077078296)): ``` FAIL: unresolved ELF import sHziAegVp74 from libkernel.prx ``` `sHziAegVp74` is `sigaltstack` (`tools/nid_names.py`). It follows FreeBSD's `kern_sigaltstack` with the amd64 `stack_t` (`ss_sp`, `ss_size`, `ss_flags` at 16, 24 bytes): - each thread has its own alternate stack, disabled at start (`SS_DISABLE`, null and 0); - flags other than `SS_DISABLE` give `EINVAL`, a size below `MINSIGSTKSZ` (2048) gives `ENOMEM`; on error it returns -1 with `errno` set and writes nothing; - `SS_DISABLE` keeps the recorded pointer and size and only marks the stack disabled, and the old stack is reported as it was before the call. Handlers never run on the alternate stack here, so `SS_ONSTACK` and `EPERM` are never reported; recorded in TechnicalDebt. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, Release, `main` d70b8998: - PICO-8, with the earlier stops' pull requests merged locally, gets past this import and stops at the next one, `ZSnX-xZBGCg` from `libSceLibcInternal.prx` (`stpcpy`, #1812). - New `guest_sigaltstack` test: the initial state, the three error cases with the old stack untouched, installing at exactly 2048 bytes, replacing, a second thread seeing its own disabled stack, and disabling. Removing the size check makes it fail. - `tools/check_conventions.py` passes. Fork CI on this head rebased onto `main` d70b8998 (with the build workflow from before 0ab2a04d, since the new one needs an upstream pull request number): https://github.com/LeandroLP23/AnyPS5/actions/runs/37921144213, all jobs pass (Windows 508/508, Linux 517/517). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 (Claude Code)
github-actions[bot] commented 2026-10-09 08:56:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T08:56:19Z.


Progress report (2e375a5 → c54143d)

📈 System libraries: 85.23% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel sigaltstack_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077728094 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2107#issuecomment-6077728094). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T08:56:19Z. --- <!-- progress-report --> ### Progress report (2e375a5 → c54143d) 📈 **System libraries**: 85.23% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sigaltstack_nid_postfix` | </details>
adriadam10 commented 2026-10-09 21:55:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:55:59Z.


Checked against FreeBSD kern_sigaltstack (flag check before size check, old stack reported with SS_DISABLE keeping the recorded pointer/size, nothing written on error) and the amd64 stack_t layout; built on current main, full ctest green, guest_sigaltstack passes and does not link without the change. TechnicalDebt entry covers SS_ONSTACK/EPERM. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089915330 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2107#issuecomment-6089915330). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:55:59Z. --- Checked against FreeBSD `kern_sigaltstack` (flag check before size check, old stack reported with `SS_DISABLE` keeping the recorded pointer/size, nothing written on error) and the amd64 `stack_t` layout; built on current `main`, full ctest green, `guest_sigaltstack` passes and does not link without the change. TechnicalDebt entry covers `SS_ONSTACK`/`EPERM`. Merging.
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!2107
No description provided.