feat(libc): implement fegetenv #5563

Merged
karimibrahim07 merged 4 commits from upstream-pr/5563 into main 2026-10-14 12:59:27 +00:00
karimibrahim07 commented 2026-10-13 23:57:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-13T23:57:50Z.


What

Java 25 LAN / DNS (PPSA99869, #5501) imports fegetenv (psx0YiAKm7k) from libSceLibcInternal.prx, and no AnyPS5 library exports it. With #5502 (sysctlnametomib, the current stop on main) applied, the loader stops here:

FAIL: unresolved ELF import psx0YiAKm7k from libSceLibcInternal.prx

fegetenv follows FreeBSD 11 amd64 fenv.c and the 32-byte fenv_t of x86/fenv.h (unchanged on main): fnstenv stores the 28-byte x87 environment, fldcw reloads the control word because fnstenv masks every x87 exception, MXCSR goes at 0x1c, and it returns 0. It is implemented in libc, since the loader also resolves libSceLibcInternal imports against libc.prx, as for atanhf. A null pointer throws. The technical-debt entry records that the console's libSceLibcInternal is assumed to have the same code and layout.

Tested

Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Release. The branch is rebased onto feddf7f4. fegetenv and its test sit next to _Fltrounds and CheckNearbyint, out of the lines #5495 changes, and tools/pr_overlap.py --branch reports no overlap with open pull requests.

  • guest_math gains CheckFegetenv. It sets the x87 control word to 0x0f7e (IE unmasked, round toward zero) and MXCSR to 0x7fa0, leaves a pending x87 divide-by-zero flag, then checks the control word, status word and MXCSR stored in the guest fenv_t, that the control word and MXCSR are unchanged afterwards, and that a null pointer throws. With the fldcw removed the test fails (0xc0000409).
  • Java 25 LAN / DNS PPSA99869 01.000.000 (PPSA99869-lan-dns-pass-01.000.000.zip, SHA-256 3cfeed2f…11cc, as in #5501), run on main 30f96126 before the rebase. I unwrapped eboot.bin and sce_module/libc.prx from their fSELF containers and relinked with --windows --to-intel --trap-sdk-syscall-stubs --registry:
    • on main: FAIL: unresolved ELF import UkEV4hvMo1E from libkernel.prx (sysctlnametomib)
    • main + #5502: FAIL: unresolved ELF import psx0YiAKm7k from libSceLibcInternal.prx (fegetenv)
    • main + #5502 + this PR: FAIL: unresolved ELF import +hFjyohmOU0 from libkernel.prx (mincore, the next absent import #5501 lists)
  • Full ctest (--parallel 4 --timeout 120) on the current head: 1108 of 1109 pass. windows_trace_imports fails locally only because Defender deletes its generated output.exe (WinError 225); it fails the same way on main.
  • python tools/check_conventions.py --base origin/main passes.

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 (#5502 is only needed for PPSA99869 to reach this import)
  • Unblocks: PPSA99869 #5501
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4851001861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5563). Originally posted by [karimibrahim07](https://github.com/karimibrahim07) on 2026-10-13T23:57:50Z. --- ### What Java 25 LAN / DNS (PPSA99869, #5501) imports `fegetenv` (`psx0YiAKm7k`) from `libSceLibcInternal.prx`, and no AnyPS5 library exports it. With #5502 (`sysctlnametomib`, the current stop on `main`) applied, the loader stops here: ``` FAIL: unresolved ELF import psx0YiAKm7k from libSceLibcInternal.prx ``` `fegetenv` follows FreeBSD 11 amd64 [`fenv.c`](https://github.com/freebsd/freebsd-src/blob/4554bee35405b36ea19e9e60d6abe6ea534e36e0/lib/msun/amd64/fenv.c) and the 32-byte `fenv_t` of [`x86/fenv.h`](https://github.com/freebsd/freebsd-src/blob/4554bee35405b36ea19e9e60d6abe6ea534e36e0/lib/msun/x86/fenv.h) (unchanged on `main`): `fnstenv` stores the 28-byte x87 environment, `fldcw` reloads the control word because `fnstenv` masks every x87 exception, MXCSR goes at 0x1c, and it returns 0. It is implemented in libc, since the loader also resolves `libSceLibcInternal` imports against `libc.prx`, as for `atanhf`. A null pointer throws. The technical-debt entry records that the console's `libSceLibcInternal` is assumed to have the same code and layout. ### Tested Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Release. The branch is rebased onto feddf7f4. `fegetenv` and its test sit next to `_Fltrounds` and `CheckNearbyint`, out of the lines #5495 changes, and `tools/pr_overlap.py --branch` reports no overlap with open pull requests. - `guest_math` gains `CheckFegetenv`. It sets the x87 control word to `0x0f7e` (IE unmasked, round toward zero) and MXCSR to `0x7fa0`, leaves a pending x87 divide-by-zero flag, then checks the control word, status word and MXCSR stored in the guest `fenv_t`, that the control word and MXCSR are unchanged afterwards, and that a null pointer throws. With the `fldcw` removed the test fails (`0xc0000409`). - Java 25 LAN / DNS PPSA99869 01.000.000 (`PPSA99869-lan-dns-pass-01.000.000.zip`, SHA-256 `3cfeed2f…11cc`, as in #5501), run on `main` 30f96126 before the rebase. I unwrapped `eboot.bin` and `sce_module/libc.prx` from their fSELF containers and relinked with `--windows --to-intel --trap-sdk-syscall-stubs --registry`: - on `main`: `FAIL: unresolved ELF import UkEV4hvMo1E from libkernel.prx` (`sysctlnametomib`) - `main` + #5502: `FAIL: unresolved ELF import psx0YiAKm7k from libSceLibcInternal.prx` (`fegetenv`) - `main` + #5502 + this PR: `FAIL: unresolved ELF import +hFjyohmOU0 from libkernel.prx` (`mincore`, the next absent import #5501 lists) - Full `ctest` (`--parallel 4 --timeout 120`) on the current head: 1108 of 1109 pass. `windows_trace_imports` fails locally only because Defender deletes its generated `output.exe` (`WinError 225`); it fails the same way on `main`. - `python tools/check_conventions.py --base origin/main` passes. ### Checklist - [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 (#5502 is only needed for PPSA99869 to reach this import) - [x] Unblocks: PPSA99869 #5501 - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
pipe1os commented 2026-10-14 05:42:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-14T05:42:04Z.


Built and ran this on Windows: head 81104f731 merged onto main f5424b4db (no conflicts), Windows 11, WinLibs GCC 15.2.0, Ninja Release.

  • guest_math passes. With Math.cpp put back to main and the test kept, it doesn't link (undefined reference to fegetenv_nid_postfix).
  • Java 25 LAN / DNS (PPSA99869): with #5502 the loader stops at psx0YiAKm7k from libSceLibcInternal.prx; adding this PR it moves on to +hFjyohmOU0 (mincore, #5643). So the libc.prx export does satisfy the libSceLibcInternal import on Windows.
  • Checked against FreeBSD 11.0 amd64/fenv.c L86-L97 and the amd64 fenv_t in x86/fenv.h L81-L89: same steps (fnstenv, MXCSR at 0x1c, fldcw of the saved control word) and the same 32-byte layout. Doing the fldcw before reading MXCSR doesn't change anything. Nothing to add from my side.

AI-assisted.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161763624 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5563#issuecomment-6161763624). Originally posted by [pipe1os](https://github.com/pipe1os) on 2026-10-14T05:42:04Z. --- Built and ran this on Windows: head `81104f731` merged onto `main` `f5424b4db` (no conflicts), Windows 11, WinLibs GCC 15.2.0, Ninja Release. - `guest_math` passes. With `Math.cpp` put back to `main` and the test kept, it doesn't link (`undefined reference to fegetenv_nid_postfix`). - Java 25 LAN / DNS (PPSA99869): with #5502 the loader stops at `psx0YiAKm7k from libSceLibcInternal.prx`; adding this PR it moves on to `+hFjyohmOU0` (`mincore`, #5643). So the `libc.prx` export does satisfy the `libSceLibcInternal` import on Windows. - Checked against FreeBSD 11.0 [`amd64/fenv.c` L86-L97](https://github.com/freebsd/freebsd-src/blob/release/11.0.0/lib/msun/amd64/fenv.c#L86-L97) and the amd64 `fenv_t` in [`x86/fenv.h` L81-L89](https://github.com/freebsd/freebsd-src/blob/release/11.0.0/lib/msun/x86/fenv.h#L81-L89): same steps (`fnstenv`, MXCSR at 0x1c, `fldcw` of the saved control word) and the same 32-byte layout. Doing the `fldcw` before reading MXCSR doesn't change anything. Nothing to add from my side. AI-assisted.
github-actions[bot] commented 2026-10-14 12:00:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T12:00:06Z.


Progress report (afc8541 → 81104f7)

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

✅ 1 implemented
Library Name
libc fegetenv_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167835875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5563#issuecomment-6167835875). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T12:00:06Z. --- <!-- progress-report --> ### Progress report (afc8541 → 81104f7) 📈 **System libraries**: 88.19% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `fegetenv_nid_postfix` | </details>
adriadam10 commented 2026-10-14 12:05:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:05:48Z.


Checked fegetenv against FreeBSD amd64 fenv.c and the 32-byte fenv_t (fnstenv, control word reloaded, MXCSR at 0x1c). guest_math passes with the change and fails to link without it. Null pointer throws, TechnicalDebt entry records the assumption about the console's library.

Added one commit: moved the TechnicalDebt line out of the end of its section to avoid adjacency conflicts. Rebased onto current main; merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167933215 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5563#issuecomment-6167933215). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T12:05:48Z. --- Checked `fegetenv` against FreeBSD amd64 `fenv.c` and the 32-byte `fenv_t` (fnstenv, control word reloaded, MXCSR at 0x1c). `guest_math` passes with the change and fails to link without it. Null pointer throws, TechnicalDebt entry records the assumption about the console's library. Added one commit: moved the TechnicalDebt line out of the end of its section to avoid adjacency conflicts. Rebased onto current main; merging once CI is green.
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!5563
No description provided.