feat(libc): implement feraiseexcept #8903
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8903"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T05:20:34Z.
What
Implement the missing
feraiseexceptexport (NIfFNcyeCTo) by accumulating requested flags in both x87 and MXCSR, preserving other state and errno, and delivering enabled x87 exceptions withfwait. All six defined exception bits are supported; unverified bits throw before changing state. This deliberately does not call_Feraise, whose errno and range/inexact behavior differs.The signature is from the public SDK fenv.h. The public 3.20 table and symbol database corroborate the NID. For the six supported bits, behavior follows FreeBSD amd64 fenv.c; console equivalence and module/library versions remain unmeasured and are recorded in debt.
Unknown bits are explicitly rejected before changing state, unlike the FreeBSD reference, which does not mask or validate the requested bits. This rejection is an unsupported-path policy; PS5 behavior for those bits is unknown.
Tested
Windows x86-64, GCC15.2 Release, isolated checkout based on
1ff5c8ac5c3050d71360957c5ff1be38aaac7114. Regression first: seven new tests fail baseline's missing export while the existing floating-point test passes. With the same final executables and only the unpatched libc swapped, baseline is 1 pass/7 fail; candidate is 8/8 pass.The main case checks 196608 flag/control combinations: all 64 requested and prior flag sets, independent x87/SSE flags, 16 rounding combinations and three x87 precision modes. It checks errno, other control/status/tag/pointer fields, rejected masks, differing exception masks, and thread isolation. Six separate cases check enabled x87 traps; Windows validates the saved unmasked cause as well as the exception code. A direct native x87 load of the smallest subnormal and the implementation both produce Windows
0xc0000090on this host, so the denormal case accepts that code only when the saved active flag is DE, not invalid.At the original submitted head
2d22f777, the full Windowslibsbuild succeeded; validation was 9/9 pass, including all 354 patched libraries loading with zero failures. The expected NID is verified in patched shared libc, which supplies the interface for libSceLibcInternal under the existing provider convention. Loading verifies linkage only. No Linux/macOS or console execution by this contributor. The POSIX trap handler confirms SIGFPE but does not inspect its saved cause. No games run.Conventions, whitespace and registration checks pass (1148 targets, none unregistered). Independent read-only review found no actionable defect and did not rerun tests. The overlap report's 14 base-conflicted shared-file warnings were reviewed manually: no competing export. #6044 reorganizes tests; #6879 changes host math callers rather than adding this export. The original overlap run had no compared-file conflict or duplicate export. The review-correction scan also has none; its 14 current base-conflicted shared-file warnings were inspected at their fetched heads and concern unrelated stack/runtime, formatting, environment, archive, directory and test-reorganization work. #6044 remains a test-directory migration consideration when rebased. The debt paragraph was relocated away from #8397/#8287 documentation changes.
Review correction: the thread test now sets its errno sentinel after the first host barrier and captures errno immediately after the export, before the second barrier. The floating-point isolation checks and distinct thread sentinels are retained; no runtime code changed. Filip722's Linux review reports 22/30 original runs passing, barrier-induced errno changes, and 30/30 passing with this test correction; those are attributed reviewer results, not execution on this Windows host.
Locally, a deterministic temporary probe makes both barriers set errno to 789: the original test fails and the repaired test passes against the same preserved DLL. A negative control that changes errno inside the called export still fails the repaired assertion. The rebuilt eight Windows tests pass, the main test passes 30 consecutive runs, and identical final executables pass 8/8 against both preserved baseline and candidate DLLs (byte-identical SHA256
bf4a81f2a272152f4886821d3c432b6ce14b98302037c5439a91297888ad8a75). These review checks rebuild the affected targets, not the entire library collection. Conventions and whitespace checks pass; independent read-only review found no actionable issue and did not rerun tests.Checklist
Based on current
main; no other open PR implements the same functionsOne 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 fileNo notes, investigation
.mdfiles 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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:22:17Z.
I ran an additional native Linux check on exact head
2d22f777ebwith GCC 12.2. I compiled the PR’sFloatingPoint.cppinto a temporary shared object and its existingGuestRaiseExcept.cppinto a host harness, supplying only a temporary__error_nid_postfixstub for this isolated test. The normal state/errno/thread cases pass, and all six enabled-x87 trap invocations exit through the test’s SIGFPE handler. The PR conventions checker andgit diff --checkalso pass. This validates the implementation on this Linux host; it does not validate the built AnyPS5 libc or inspect the POSIX trap cause.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:23:44Z.
Review: APPROVED
Reviewed the new export and regression coverage. The implementation updates x87 and MXCSR flags independently, rejects unsupported bits before changing state, preserves errno/control fields, and uses
fwaitfor enabled x87 exceptions. I independently ran the PR test on Linux with GCC 12.2 through a temporary host harness; the state, errno, thread, and six trap cases passed. Console behavior remains unmeasured and is clearly recorded in debt. The platform jobs still running are not covered by this approval.Imported from boykopovar/AnyPS5. Originally posted by r1p0N on 2026-10-21T07:30:32Z.
The implementation matches FreeBSD's amd64 feraiseexcept (fesetexceptflag on x87 status and MXCSR, then __fwait()), so valid masks behave the same way.
One difference worth stating in the debt entry: FreeBSD neither masks nor validates excepts, while this throws std::invalid_argument for bits outside the six exceptions. That is consistent with the throw-on-unknown rule and avoids writing reserved MXCSR bits, but it is a deliberate deviation from the console's likely behaviour, and the debt note should say so if it does not already.
Not run: the tests (they dlopen the built libc and need the full build).
Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-21T10:13:27Z.
Native Linux full-project validation on exact head
2d22f777eb4b4928df17f0aeeb211f61ae2d70f9found an intermittent issue in the new test'sThreads()errno assertion. The export itself preserved errno in the instrumented runs; the host barriers changed it outside the call.Environment: Debian 13.7 x86-64, kernel 7.2.9-x64v3-xanmod1, Ryzen 5 7640HS, GCC/libstdc++ 15.2.0, CMake 3.31.6, Release, bundled dependencies,
BUILD_TESTING=ON,ANYPS5_RELINKER_ONLY=OFF, two build jobs. Built the actuallibc,guest_raise_except_tests,guest_floating_point_tests, andnid_patcher; no stubbed errno provider.Repro / diagnosis:
guest_raise_exceptexecutable passed 22/30 runs and aborted 8/30 withferaiseexcept: thread-local errno. The focused CTest run also reproduced it.ready.arrive_and_wait(). Failing examples wereflag=4 before=104 after=104 afterBarrier=11andflag=1 before=11 after=11 afterBarrier=11. Thus either host barrier can spoil the sentinel; the export preserves the value it receives. The real project's__error_nid_postfix()returns&errno; this libstdc++ uses futex waits in the barrier's atomic-wait path and allows EAGAIN (11) without restoring errno.Additional passing evidence:
guest_floating_pointcontrol passed three consecutive runs each.sigaction(SA_SIGINFO)and checkedSIGFPEplusuc_mcontext.fpregs->swd & ~uc_mcontext.fpregs->cwd & 0x3fagainst exactly the requested bit. All six bits, including denormal, passed three runs each. This checks the saved active cause in addition to signal delivery.nm -D --defined-onlycontains exactly oneNIfFNcyeCToexport. This is packaging verification, not a full patched-runtime/title test.FloatingPoint.cppfrom merge-base1ff5c8ac5c3050d71360957c5ff1be38aaac7114and rebuilt libc, retaining the final test executables. The seven new cases failed with the missing-export assertion; the existing floating-point case passed. After restoring the exact PR implementation, the six trap cases and old control passed again, while the original main case reproduced the barrier/errno failure. The corrected temporary test and saved-cause checks passed against the restored library.Build/repro commands:
All diagnostic variants stayed under
/tmp; repository sources are restored to the exact head. No Windows, console or game execution in this check. AI-assisted testing/reporting: yes.Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T18:03:05Z.
Addressed both review points in
35c508e9a.The thread test now sets its distinct errno sentinel after barrier one and captures it immediately after
feraiseexcept, before barrier two. The floating-point checks remain unchanged. A deterministic barrier-side errno injection fails the old test and passes the repaired test using the same DLL; an export-side errno mutation still fails the repaired assertion. On Windows, all eight relevant tests pass, the main test passes 30 consecutive runs, and identical final executables pass 8/8 against both preserved and candidate DLLs. The DLLs are byte-identical; no runtime code changed. Filip722's Linux results remain attributed reviewer evidence; I have not run Linux here.The debt entry now explicitly states that FreeBSD does not mask or validate the requested exception bits, whereas this implementation rejects unknown bits before modifying state. Console behavior for those bits remains unknown. Conventions and whitespace checks pass. The PR description separates the original full-library validation from these focused review checks.