Skip to content

feat(libc): implement feupdateenv - #9232

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
UnhealthyKraken:feat/libc-feupdateenv
Oct 24, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
UnhealthyKraken:feat/libc-feupdateenv

Conversation

@UnhealthyKraken

@UnhealthyKraken UnhealthyKraken commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Progress report (a59b2a4 → 4a6e013)

➖ System libraries: 48.62% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc feupdateenv_nid_postfix

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9850 docs/dev/debt/libc.md L21

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/Math.cpp
PR 7544 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 7715 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8150 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8417 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 8730 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9527 docs/dev/debt/libc.md
PR 9552 docs/dev/debt/libc.md
PR 9648 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 9669 docs/dev/debt/libc.md
PR 9833 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 9873 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 9929 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 10007 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md
PR 10453 docs/dev/debt/libc.md
PR 10467 core/libs/prx/libc/src/Math.cpp
docs/dev/debt/libc.md

@UnhealthyKraken

Copy link
Copy Markdown
Contributor Author

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 harisibrar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against main a6646f8 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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@UnhealthyKraken

Copy link
Copy Markdown
Contributor Author

Refreshed onto main d6e7ab4 in 5dfd505. The new conflict was only the expected adjacent debt insertion from merged #9296: both entries are preserved, and I placed feupdateenv next to fegetenv as suggested. The original runtime implementation and GuestUpdateEnv test source are retained.

Rebuilt affected Windows libraries and environment/math/loader targets; all 23 selected tests pass, including the 18 pending-exception source/flag cases. Current conventions, whitespace and registration pass (1178 executables, none unregistered). The first build command referenced a nonexistent math target; the corrected invocation built the actual targets before these results. No Linux/macOS/console retest, and the POSIX SIGFPE branch remains unrun locally. Thank you for the source review; the description preserves those validation limits. @harisibrar1

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 22, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 23, 2026
danielradosa added a commit to danielradosa/AnyPS5 that referenced this pull request Oct 24, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 24, 2026
@oneandonlydean
oneandonlydean merged commit 25b744d into boykopovar:main Oct 24, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants