feat(libc): implement feholdexcept #8863

Merged
UnhealthyKraken merged 3 commits from upstream-pr/8863 into main 2026-10-24 18:37:11 +00:00
UnhealthyKraken commented 2026-10-21 03:41:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T03:41:25Z.


What

Provide feholdexcept (1kduKXMqx7k, libSceLibcInternal implemented by shared libc). It saves the current thread's 32-byte x87/MXCSR environment, clears pending exceptions and masks traps in both units while retaining other controls. Null output throws before any state changes.

The public SDK declaration and amd64 layout, public 3.20 symbol table and independently matching NID database establish interface evidence. Behavior follows FreeBSD 11 amd64 fenv.c, alongside the existing fegetenv implementation. Console equivalence and module/library versions remain unverified and are recorded in libc debt. No proprietary module or capture is included.

Tested

Windows x86-64, GCC 15.2, Release. No games or GPU execution.

  • Added regression before implementation; baseline 05f9995704ce700749880024243469924ad1db9a fails on the missing export. Exactly the same test binaries, swapping only saved baseline/candidate libc, yield baseline one expected failure plus two passing math suites; candidate three passing suites.
  • Existing guest_floating_point now checks 1,024 combinations of x87/SSE masks, independently set rounding controls, DAZ/FTZ and pending masked flags. Checks the complete saved environment, cleared flags, masked traps, unchanged other controls/tags/instruction state, errno preservation, output sentinels and a trailing no-access page. Also checks null rejection before state changes and concurrent thread isolation. Size32/alignment4/MXCSR offset28 are asserted.
  • Full Windows libs target built; patched NID verified. Final patched_libraries (354 loaded), guest_floating_point, guest_math and guest_math_exact: 4/4 pass, no skips. Library loading verifies linkage, not every library's behavior.
  • Independent read-only review found no actionable ABI, bounds, state or test issue; reviewer did not rerun tests. No PS5 hardware or Linux/macOS execution, so reference behavior is not described as console-measured.
  • Conventions, whitespace and test-registration checks passed. Required pr_overlap completed twice: no confirmed duplicate export or merge collision. It could not compare shared files for 17 already-conflicted PRs; saved and manually inspected those shared-file diffs. None implements feholdexcept. #6044 reorganizes tests, and #6879 adds WebAssembly handling beside fegetenv; these need integration if they land later. #8520 has multiple merge bases, so its saved diff uses Git's selected base. This is not an unconditional clean-overlap claim.
  • Rebased onto the overlap check's main snapshot 4f24b6a64c4d62ce01da251820d159a25d6b23fb. The libc sources/test/debt did not change from the original tested base; subsequent main changes were AGC, VideoOut and SystemService work.

Independent Windows validation by xXPBSXx, Windows10 Pro/Ryzen7 5800X3D/WinLibs GCC15.2 Release: the existing guest_floating_point case passes three runs on this PR, and the identical test fails three runs after replacing only Math.cpp with merge-base4f24b6a64c. Only that test target was built. This is attributed reviewer evidence, not an own rerun or a full-suite/other-platform/console result.

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 under Silent stubs in their library's technical debt file
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4946039798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8863). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T03:41:25Z. --- ### What Provide `feholdexcept` (`1kduKXMqx7k`, libSceLibcInternal implemented by shared libc). It saves the current thread's 32-byte x87/MXCSR environment, clears pending exceptions and masks traps in both units while retaining other controls. Null output throws before any state changes. The public SDK [declaration and amd64 layout](https://github.com/ps5-payload-dev/sdk/blob/a7685ce8e97ce1f8a4f38253a41d54241c9124f1/include/freebsd/fenv.h), public [3.20 symbol table](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c) and independently matching [NID database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv) establish interface evidence. Behavior follows [FreeBSD 11 amd64 fenv.c](https://github.com/freebsd/freebsd-src/blob/4554bee35405b36ea19e9e60d6abe6ea534e36e0/lib/msun/amd64/fenv.c), alongside the existing fegetenv implementation. Console equivalence and module/library versions remain unverified and are recorded in libc debt. No proprietary module or capture is included. ### Tested Windows x86-64, GCC 15.2, Release. No games or GPU execution. - Added regression before implementation; baseline `05f9995704ce700749880024243469924ad1db9a` fails on the missing export. Exactly the same test binaries, swapping only saved baseline/candidate libc, yield baseline one expected failure plus two passing math suites; candidate three passing suites. - Existing guest_floating_point now checks 1,024 combinations of x87/SSE masks, independently set rounding controls, DAZ/FTZ and pending masked flags. Checks the complete saved environment, cleared flags, masked traps, unchanged other controls/tags/instruction state, errno preservation, output sentinels and a trailing no-access page. Also checks null rejection before state changes and concurrent thread isolation. Size32/alignment4/MXCSR offset28 are asserted. - Full Windows libs target built; patched NID verified. Final patched_libraries (354 loaded), guest_floating_point, guest_math and guest_math_exact: 4/4 pass, no skips. Library loading verifies linkage, not every library's behavior. - Independent read-only review found no actionable ABI, bounds, state or test issue; reviewer did not rerun tests. No PS5 hardware or Linux/macOS execution, so reference behavior is not described as console-measured. - Conventions, whitespace and test-registration checks passed. Required pr_overlap completed twice: no confirmed duplicate export or merge collision. It could not compare shared files for 17 already-conflicted PRs; saved and manually inspected those shared-file diffs. None implements feholdexcept. #6044 reorganizes tests, and #6879 adds WebAssembly handling beside fegetenv; these need integration if they land later. #8520 has multiple merge bases, so its saved diff uses Git's selected base. This is not an unconditional clean-overlap claim. - Rebased onto the overlap check's main snapshot `4f24b6a64c4d62ce01da251820d159a25d6b23fb`. The libc sources/test/debt did not change from the original tested base; subsequent main changes were AGC, VideoOut and SystemService work. Independent [Windows validation by xXPBSXx](https://github.com/boykopovar/AnyPS5/pull/8863#issuecomment-6310802520), Windows10 Pro/Ryzen7 5800X3D/WinLibs GCC15.2 Release: the existing guest_floating_point case passes three runs on this PR, and the identical test fails three runs after replacing only Math.cpp with merge-base4f24b6a64c. Only that test target was built. This is attributed reviewer evidence, not an own rerun or a full-suite/other-platform/console result. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-21 04:14:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:14:23Z.

Review: APPROVED


Reviewed the x87/MXCSR save and mask sequence and the test matrix. fnstenv captures the x87 environment before its masking side effect, the explicit fnclex clears x87 pending exceptions, and the saved MXCSR is restored into the output before the new masked/cleared MXCSR is installed. The tests exercise bounds, null handling, errno, flags, controls and thread isolation. The implementation appropriately records that console equivalence is not measured. I found no blocking issue in the diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5594886234 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8863#pullrequestreview-5594886234). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T04:14:23Z. **Review:** APPROVED --- Reviewed the x87/MXCSR save and mask sequence and the test matrix. `fnstenv` captures the x87 environment before its masking side effect, the explicit `fnclex` clears x87 pending exceptions, and the saved MXCSR is restored into the output before the new masked/cleared MXCSR is installed. The tests exercise bounds, null handling, errno, flags, controls and thread isolation. The implementation appropriately records that console equivalence is not measured. I found no blocking issue in the diff.
xXPBSXx commented 2026-10-21 07:44:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T07:44:28Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only guest_floating_point_tests; ctest -N -R guest_floating_point lists exactly one test.

Results (3 runs each):

  • PR head: guest_floating_point passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libc/src/Math.cpp with the version from the PR's merge base (4f24b6a64c), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6310802520 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8863#issuecomment-6310802520). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T07:44:28Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` is clean. I built only `guest_floating_point_tests`; `ctest -N -R guest_floating_point` lists exactly one test. **Results (3 runs each):** - PR head: `guest_floating_point` passes 3/3. - Baseline: I kept the PR's test and replaced only `core/libs/prx/libc/src/Math.cpp` with the version from the PR's merge base (`4f24b6a64c`), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards. **Not run:** other platforms, the other tests in the same family, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
UnhealthyKraken commented 2026-10-22 03:16:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T03:16:32Z.


Recorded the independent Windows result and its limits: guest_floating_point passes three runs on the PR and fails three runs with the same test against merge-base Math.cpp. This corroborates the regression separately from my original Windows/full-library validation. It is not a full-suite, other-platform or console result. The review and test report identify no further implementation change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331808710 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8863#issuecomment-6331808710). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T03:16:32Z. --- Recorded the independent Windows result and its limits: `guest_floating_point` passes three runs on the PR and fails three runs with the same test against merge-base Math.cpp. This corroborates the regression separately from my original Windows/full-library validation. It is not a full-suite, other-platform or console result. The review and test report identify no further implementation change.
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!8863
No description provided.