feat(libc): export __fe_dfl_env as measured on a PS5 #11177

Merged
orezraey merged 1 commit from upstream-pr/11177 into main 2026-10-26 22:02:07 +00:00
orezraey commented 2026-10-25 20:40:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T20:40:07Z.


What

This exports __fe_dfl_env, the default floating-point environment that FE_DFL_ENV points at, with the 32 bytes the system libSceLibcInternal of a retail PS5 (firmware 13.60) exports. Until now the debt file said the object "remains unimplemented" and its initializer was unknown. A title that calls fesetenv(FE_DFL_ENV) or feupdateenv(FE_DFL_ENV) imports it.

Measured with a homebrew probe from a payload process; the source and console log are in this gist (pfeupdate).

  • libSceLibcInternal.sprx exports __fe_dfl_env. Its bytes are 7f03ffff 0000ffff ffffffff 00000000 00000000 00000000 0000ffff c09f0000: x87 control 0xffff037f, status 0xffff0000, tag 0xffffffff, 0xffff at offset 26 of the fnstenv block, and MXCSR 0x9fc0.
  • feupdateenv(&__fe_dfl_env) succeeds there. The same probe confirmed what feupdateenv already does here: the flags pending before the call are raised in both units, and an unmasked pending flag traps.
  • The console faults for a null environment (SIGSEGV) and for MXCSR 0xffff9fc0 (SIGBUS); AnyPS5 keeps throwing for both. The debt entry, which said that fault behaviour was unknown, now records it with the gap first.

The object is a const GuestFloatingPointEnvironment __fe_dfl_env_nid_postfix next to feholdexcept in Math.cpp, with its declaration in Api.hpp.

Before and after

Case PS5 AnyPS5 before AnyPS5 now
__fe_dfl_env export exported, 32 bytes as listed above not exported exported, the same 32 bytes
feupdateenv(&__fe_dfl_env) succeeds title could not import it succeeds
null environment, MXCSR 0xffff9fc0 faults throws throws

Tested

Windows 11, WinLibs GCC 15.2. The 19 guest_update_env tests pass 3 times out of 3. The new DefaultEnvironment check looks the export up by name in the built libc, compares its 32 bytes with the console's, and calls feupdateenv with it from a disturbed environment (round toward zero, precision 24-bit). It then checks that the x87 control is 0x037f and MXCSR 0x9fc0 with no flags. tools/check_conventions.py passes.

Head 2fd60d3ebd on main 5a2744c55e. Linux (WSL, GCC 16.2.1, Release) at the same head: the 19 guest_update_env tests pass 3 times out of 3.

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: #11121 (mine, it edits the feholdexcept entry next to this one) and #10903 (it edits the end of GuestUpdateEnv.cpp); merge order only. #8937 (fesetenv) merges cleanly with this PR.
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5008491187 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11177). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-25T20:40:07Z. --- ### What This exports `__fe_dfl_env`, the default floating-point environment that `FE_DFL_ENV` points at, with the 32 bytes the system `libSceLibcInternal` of a retail PS5 (firmware 13.60) exports. Until now the debt file said the object "remains unimplemented" and its initializer was unknown. A title that calls `fesetenv(FE_DFL_ENV)` or `feupdateenv(FE_DFL_ENV)` imports it. Measured with a homebrew probe from a payload process; the source and console log are in [this gist](https://gist.github.com/orezraey/abe633b3df29c1f2074c6ff884cd6a57) (`pfeupdate`). - `libSceLibcInternal.sprx` exports `__fe_dfl_env`. Its bytes are `7f03ffff 0000ffff ffffffff 00000000 00000000 00000000 0000ffff c09f0000`: x87 control `0xffff037f`, status `0xffff0000`, tag `0xffffffff`, `0xffff` at offset 26 of the `fnstenv` block, and MXCSR `0x9fc0`. - `feupdateenv(&__fe_dfl_env)` succeeds there. The same probe confirmed what `feupdateenv` already does here: the flags pending before the call are raised in both units, and an unmasked pending flag traps. - The console faults for a null environment (`SIGSEGV`) and for MXCSR `0xffff9fc0` (`SIGBUS`); AnyPS5 keeps throwing for both. The debt entry, which said that fault behaviour was unknown, now records it with the gap first. The object is a `const GuestFloatingPointEnvironment __fe_dfl_env_nid_postfix` next to `feholdexcept` in `Math.cpp`, with its declaration in `Api.hpp`. **Before and after** | Case | PS5 | AnyPS5 before | AnyPS5 now | |---|---|---|---| | `__fe_dfl_env` export | exported, 32 bytes as listed above | not exported | exported, the same 32 bytes | | `feupdateenv(&__fe_dfl_env)` | succeeds | title could not import it | succeeds | | null environment, MXCSR `0xffff9fc0` | faults | throws | throws | ### Tested <!-- 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. --> Windows 11, WinLibs GCC 15.2. The 19 `guest_update_env` tests pass 3 times out of 3. The new `DefaultEnvironment` check looks the export up by name in the built libc, compares its 32 bytes with the console's, and calls `feupdateenv` with it from a disturbed environment (round toward zero, precision 24-bit). It then checks that the x87 control is `0x037f` and MXCSR `0x9fc0` with no flags. `tools/check_conventions.py` passes. Head `2fd60d3ebd` on `main` `5a2744c55e`. Linux (WSL, GCC 16.2.1, Release) at the same head: the 19 `guest_update_env` tests pass 3 times out of 3. ### 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: #11121 (mine, it edits the `feholdexcept` entry next to this one) and #10903 (it edits the end of `GuestUpdateEnv.cpp`); merge order only. #8937 (`fesetenv`) merges cleanly with this PR. - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 20:46:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T20:46:22Z.

Review: COMMENTED


Reviewed head 2fd60d3ebd309f137ae2a838af30e7c401f34ff1. I checked the linked probe log: it resolves __fe_dfl_env from libSceLibcInternal.sprx and reports 7f03ffff0000ffffffffffff0000000000000000000000000000ffffc09f0000, matching the 32-byte initializer and the test's expected bytes. The dependencies named in the PR (#11121, #10903, #8937) are currently open and clean; the declared merge-order dependencies are explicit.

Local C++20 syntax compilation of Math.cpp and GuestUpdateEnv.cpp, conventions, and git diff --check passed. Hosted Linux relinker, ASan, and Ubuntu register-context checks pass; Windows and macOS jobs remain pending. The author reports three passing runs of the 19 focused guest_update_env tests on Windows. I found no concrete issue, and am leaving a comment-only review until the remaining checks complete.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645196954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11177#pullrequestreview-5645196954). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T20:46:22Z. **Review:** COMMENTED --- Reviewed head `2fd60d3ebd309f137ae2a838af30e7c401f34ff1`. I checked the linked probe log: it resolves `__fe_dfl_env` from `libSceLibcInternal.sprx` and reports `7f03ffff0000ffffffffffff0000000000000000000000000000ffffc09f0000`, matching the 32-byte initializer and the test's expected bytes. The dependencies named in the PR (#11121, #10903, #8937) are currently open and clean; the declared merge-order dependencies are explicit. Local C++20 syntax compilation of `Math.cpp` and `GuestUpdateEnv.cpp`, conventions, and `git diff --check` passed. Hosted Linux relinker, ASan, and Ubuntu register-context checks pass; Windows and macOS jobs remain pending. The author reports three passing runs of the 19 focused `guest_update_env` tests on Windows. I found no concrete issue, and am leaving a comment-only review until the remaining checks complete.
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!11177
No description provided.