feat(libc): implement feupdateenv #9232

Merged
UnhealthyKraken merged 3 commits from upstream-pr/9232 into main 2026-10-24 14:52:38 +00:00
UnhealthyKraken commented 2026-10-21 15:54:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T15:54:36Z.


What

libSceLibcInternal imports of feupdateenv (YXQ4gXamCrY) have no implementation in the shared libc provider. Restore the supplied 32-byte x87/MXCSR environment, then raise the union of the previously pending flags in both units and execute fwait, following FreeBSD 11.4 amd64 fenv.c. This preserves the saved rounding, precision, masks, tags and instruction state while delivering enabled x87 exceptions during the call.

The name/NID is corroborated by the public 3.20 inventory and symbol database; the signature and layout follow the public SDK fenv.h. Console behavior and module/library versions remain unmeasured and are recorded in debt. Null inputs and host-unsupported MXCSR bits throw before changing state. No host default-environment sentinel is substituted for the still-missing __fe_dfl_env object.

This implementation builds independently of the other open fenv contributions.

Tested

Windows x86-64, GCC 15.2 Release. No games or GPU workloads were run.

  • Added the behavioral regression first: current main failed at the missing export; both existing math suites passed. Final identical test binaries against the preserved current-main libc give 19 expected missing-export failures plus 2 math passes, then 21/21 passes on this contribution.
  • The main test checks 262,144 old-flag/saved-flag/rounding combinations with three x87 precision settings, 4,096 independent mask pairs, supported DAZ/FTZ, a read-only 32-byte guard-boundary input, null/unsupported-MXCSR rejection, input/state/errno preservation, nonempty tags/TOP/instruction state, guest fegetenv round trips and two concurrent host threads.
  • Eighteen subprocess cases verify traps for all six x87 exception types: flags originating in old x87 state, old SSE state, or the restored environment. Windows verifies the active x87 flag and exception code; denormal may be reported as invalid-operation with active denormal status.
  • Full Windows libs build and final CTest selection: 22/22 pass, including 360 patched libraries loaded, 0 failed. A separate single-libc host fixture also passes the main test and all 18 traps through canonical NIDs. Its first attempt mixed patched/unpatched libc instances and terminated on the null-input exception; correcting the fixture's imports to use the patched personality and canonical dependency exports resolves that harness failure without a library change.
  • Independent read-only review found no remaining actionable defects after adding restored-pending-flag trap coverage and debt. Conventions and whitespace checks pass; shared-file overlap warnings were inspected manually and direct insertion conflicts were removed.

Linux/macOS and console execution are unavailable here. The POSIX trap source checks SIGFPE without inspecting the specific signal-context flag; it was not run here. Compilation and export presence are not claimed as console behavior proof.

Current-main review follow-up

Merged main d6e7ab42dfe191818721c6c5ad9aee4070b434aa without rewriting published history; head 5dfd50502a067ef8b4c141bb030fc78a35803789. Resolved only the adjacent libc debt conflict with merged #9296, preserving its snprintf/vsnprintf entry and this PR's feupdateenv note. Moved the latter next to the existing fegetenv entries as suggested in review. The original feupdateenv runtime/test implementation is retained.

Rebuilt affected Windows libraries and the environment/math/loader targets: 23/23 selected tests pass, including all 18 pending-exception source/flag cases. Current conventions, whitespace and registration checks were repeated. No fresh Linux/macOS/console execution; in particular, the POSIX SIGFPE branch remains unrun locally. The initial build invocation named a nonexistent math-bits target and stopped before compilation; corrected to the actual guest_math/guest_math_exact targets for the passing build above.

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
  • 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:4954448622 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9232). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T15:54:36Z. --- ### What `libSceLibcInternal` imports of `feupdateenv` (`YXQ4gXamCrY`) have no implementation in the shared libc provider. Restore the supplied 32-byte x87/MXCSR environment, then raise the union of the previously pending flags in both units and execute `fwait`, following [FreeBSD 11.4 amd64 fenv.c](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/lib/msun/amd64/fenv.c). This preserves the saved rounding, precision, masks, tags and instruction state while delivering enabled x87 exceptions during the call. The name/NID is corroborated by the public [3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c) and [symbol database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv); the signature and layout follow the [public SDK fenv.h](https://github.com/ps5-payload-dev/sdk/blob/a7685ce8e97ce1f8a4f38253a41d54241c9124f1/include/freebsd/fenv.h). Console behavior and module/library versions remain unmeasured and are recorded in debt. Null inputs and host-unsupported MXCSR bits throw before changing state. No host default-environment sentinel is substituted for the still-missing `__fe_dfl_env` object. This implementation builds independently of the other open fenv contributions. ### Tested Windows x86-64, GCC 15.2 Release. No games or GPU workloads were run. - Added the behavioral regression first: current main failed at the missing export; both existing math suites passed. Final identical test binaries against the preserved current-main libc give **19 expected missing-export failures plus 2 math passes**, then **21/21 passes** on this contribution. - The main test checks 262,144 old-flag/saved-flag/rounding combinations with three x87 precision settings, 4,096 independent mask pairs, supported DAZ/FTZ, a read-only 32-byte guard-boundary input, null/unsupported-MXCSR rejection, input/state/errno preservation, nonempty tags/TOP/instruction state, guest `fegetenv` round trips and two concurrent host threads. - Eighteen subprocess cases verify traps for all six x87 exception types: flags originating in old x87 state, old SSE state, or the restored environment. Windows verifies the active x87 flag and exception code; denormal may be reported as invalid-operation with active denormal status. - Full Windows `libs` build and final CTest selection: **22/22 pass**, including **360 patched libraries loaded, 0 failed**. A separate single-libc host fixture also passes the main test and all 18 traps through canonical NIDs. Its first attempt mixed patched/unpatched libc instances and terminated on the null-input exception; correcting the fixture's imports to use the patched personality and canonical dependency exports resolves that harness failure without a library change. - Independent read-only review found no remaining actionable defects after adding restored-pending-flag trap coverage and debt. Conventions and whitespace checks pass; shared-file overlap warnings were inspected manually and direct insertion conflicts were removed. Linux/macOS and console execution are unavailable here. The POSIX trap source checks `SIGFPE` without inspecting the specific signal-context flag; it was not run here. Compilation and export presence are not claimed as console behavior proof. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Current-main review follow-up Merged main `d6e7ab42dfe191818721c6c5ad9aee4070b434aa` without rewriting published history; head `5dfd50502a067ef8b4c141bb030fc78a35803789`. Resolved only the adjacent libc debt conflict with merged #9296, preserving its snprintf/vsnprintf entry and this PR's feupdateenv note. Moved the latter next to the existing fegetenv entries as suggested in review. The original feupdateenv runtime/test implementation is retained. Rebuilt affected Windows libraries and the environment/math/loader targets: **23/23 selected tests pass**, including all 18 pending-exception source/flag cases. Current conventions, whitespace and registration checks were repeated. No fresh Linux/macOS/console execution; in particular, the POSIX SIGFPE branch remains unrun locally. The initial build invocation named a nonexistent math-bits target and stopped before compilation; corrected to the actual guest_math/guest_math_exact targets for the passing build above. ### 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 - [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
UnhealthyKraken commented 2026-10-22 02:42:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T02:42:30Z.


Reviewed the overlap with #9296 at head 595dcacdf2db34a283be4716ef7d3ddaf50014ec. Its runtime/test changes concern snprintf/vsnprintf capacity overflow; this PR changes feupdateenv. The reported overlap is two independent additions immediately before ### Functional in docs/dev/debt/libc.md. Neither relies on the other's code or exports, so Depends on remains none. If either merges first, preserve both debt entries when integrating the other; this PR currently merges cleanly into main. No runtime change is needed for this overlap.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331391557 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9232#issuecomment-6331391557). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T02:42:30Z. --- Reviewed the overlap with #9296 at head `595dcacdf2db34a283be4716ef7d3ddaf50014ec`. Its runtime/test changes concern snprintf/vsnprintf capacity overflow; this PR changes feupdateenv. The reported overlap is two independent additions immediately before `### Functional` in docs/dev/debt/libc.md. Neither relies on the other's code or exports, so Depends on remains none. If either merges first, preserve both debt entries when integrating the other; this PR currently merges cleanly into main. No runtime change is needed for this overlap.
harisibrar1 commented 2026-10-22 18:17:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T18:17:08Z.

Review: APPROVED


Checked against main a6646f8464 and FreeBSD amd64 fenv.c / x86 fenv.h @d106002967:

  • The sequence matches FreeBSD's feupdateenv: save fnstsw|stmxcsr, fesetenv (fldenv + ldmxcsr), then feraiseexcept (fnstenv/OR/fldenv, MXCSR OR, fwait). An unmasked pending x87 exception traps at the same fwait, and masked ones only set flags in both units, as on FreeBSD.
  • It uses main's guest GuestFloatingPointEnvironment (28-byte x87 env + MXCSR at 0x1c) with raw fnstenv/fldenv, so MinGW's host fenv_t and FE_DFL_ENV sentinel never come into play. Good.
  • The fxsave MXCSR_MASK read (dword 7, 0xFFBF fallback) is the right offset.
  • NID YXQ4gXamCrY hashes from feupdateenv, and the branch still merges cleanly into current main.
  • Nit, optional: the debt entry might sit better next to the existing fegetenv/fe* entries at the top of "Unknown function info" than as a separate paragraph above ### Functional.
  • FYI: the linux/windows libs CI jobs were skipped on this PR, so the POSIX SIGFPE side of the new trap tests hasn't run anywhere yet.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5618842455 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9232#pullrequestreview-5618842455). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T18:17:08Z. **Review:** APPROVED --- Checked against main a6646f8464 and FreeBSD amd64 fenv.c / x86 fenv.h @d106002967: - The sequence matches FreeBSD's `feupdateenv`: save `fnstsw|stmxcsr`, `fesetenv` (`fldenv` + `ldmxcsr`), then `feraiseexcept` (`fnstenv`/OR/`fldenv`, MXCSR OR, `fwait`). An unmasked pending x87 exception traps at the same `fwait`, and masked ones only set flags in both units, as on FreeBSD. - It uses main's guest `GuestFloatingPointEnvironment` (28-byte x87 env + MXCSR at 0x1c) with raw `fnstenv`/`fldenv`, so MinGW's host `fenv_t` and `FE_DFL_ENV` sentinel never come into play. Good. - The `fxsave` MXCSR_MASK read (dword 7, 0xFFBF fallback) is the right offset. - NID `YXQ4gXamCrY` hashes from `feupdateenv`, and the branch still merges cleanly into current main. - Nit, optional: the debt entry might sit better next to the existing `fegetenv`/fe* entries at the top of "Unknown function info" than as a separate paragraph above `### Functional`. - FYI: the `linux`/`windows` libs CI jobs were skipped on this PR, so the POSIX `SIGFPE` side of the new trap tests hasn't run anywhere yet. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!9232
No description provided.