fix(libc): set ERANGE and raise overflow in both units when coshf overflows as measured on a PS5 #11109
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11109"
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 orezraey on 2026-10-25T18:00:50Z.
What
coshffrom the systemlibSceLibcInternal.sprxmeasured on a retail PS5 (firmware 13.60) with a homebrew probe from a payload process (MXCSR 0x9fc0): 18 edge values with theirerrnoand x87/SSE status flags, and a sweep of 2,310,537,216 of the 2^32 input bit patterns: |x| below 90 completes, x from 90 stops at 0x47040000 when the probe's time budget expires, and x from -90 down is not reached. The source and console log are in this gist (pcoshf).Overflow. For |x| from 0x42b2d4fd (the first input past the largest finite result) up to
FLT_MAX, the console returns +inf, setserrnotoERANGE(34) and raises overflow and inexact (0x28) in both the x87 status word and MXCSR. AnyPS5 returnedhuge * huge: +inf with the flags only in MXCSR and noerrno. The overflow path now calls_Feraisewith overflow, which raises overflow and inexact in both units and setsERANGE, and returns +inf._Feraisetakes the guest's bit for overflow (0x08). The Windows host'sFE_OVERFLOWis 4 (MinGW'sfenv.hnumbers the exceptions differently), so the guest value is spelled out.Already matching: 0x42b2d4fc gives
0x7f7fffecwith inexact in MXCSR and noerrno; ±inf give +inf and quiet NaNs come back unchanged, with no flags and noerrno.Not changed: the hash of the console's results over [2^-12, 90) differs from AnyPS5's over the same inputs, while [0, 2^-12) and the swept part from 90 hash the same, but the probe does not log which inputs differ. The AnyPS5 side is its
coshfcopied into a host program (g++-O2 -ffp-contract=off, MXCSR 0x9fc0, the probe's FNV-1a):pos_densegives 0x3e24546359ffa5f4 against the console's 0x140826a84f2b20dd, andpos_lowand the partialpos_highgive the console's 0x49cae1d47d9d0383 and 0x06308f18855d0383. The console's negative ranges hash like the positive ones. The debt entry records that; finding them needs a probe that embeds AnyPS5'scoshfand logs the mismatching inputs.A follow-up probe (gist,
pcoshf2) ran the console'scoshfagainst an exact copy of this one on the console for every input in [2^-12, 90) of each sign. 31,585 of 154,402,816 per sign differ, all by 1 ulp, spread over every branch. The console's results match neither the older five-term fdlibmexpf/expm1f(3 of the 2,000 logged inputs) nor(float)cosh((double)x)(1,105 of 2,000). Its code is execute-only, so it cannot be read from a payload. The debt entry now records this instead of "not identified yet"; changing the non-overflow path stays out of this PR.Before and after
coshfFLT_MAXerrnoERANGE, overflow and inexact in x87 and MXCSRerrnoerrnoERANGE, overflow and inexact in x87 and MXCSRTested
Head
8500fa8fdd(merge ofmain5a36b2df1e; the only conflict wasdocs/dev/debt/libc.md, keeping main's newpowfentry and this PR'scoshfentry), Windows 11 Pro 26200, WinLibs GCC 15.2, Release, and Linux (WSL Ubuntu, GCC).guest_mathchecks 0x42b2d4fd, 0x42b30000, -0x42b30000, 0x42b40000 andFLT_MAX: +inf, guesterrno34, and 0x28 in both the x87 status word and MXCSR (cleared withfnclexandldmxcsrbefore each call, since the host'sfeclearexceptleaves the denormal bit). It also checks that 0x42b2d4fc, ±inf and a NaN raise no overflow and leaveerrnoalone.guest_math_exact; on the previous code it fails (noerrno, no x87 flags).tools/check_conventions.pypasses. At8500fa8fdd,guest_mathpasses three runs in a row on Windows and three on Linux.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)libc.mdentries next to thecoshfone; merge order only; #10247, #10265 and #10317 have merged); #8417 edits the same lines ofMath.cpp,GuestMath.cppandlibc.md(merge order only); #7544 (ionut27001) rewrites thelgamma and signgamentry right above thecoshfone inlibc.md(merge order only)Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T18:33:59Z.
Review: CHANGES_REQUESTED
Reviewed exact head
894cbf6dd8c4e6250630e00e6c963d678cb9209d. The overflow-path change passes my native checks; I request one correction to the measurement-coverage wording in the debt entry and PR description (inline).The linked primary console log, revision
5b4b44ab28536d90398a8a155192cc596bbd1905, records firmware13.60, the system module and resolved function, MXCSR0x9fc0 and the expected overflow edge behavior. It also explicitly records an expired budget: 2,310,537,216 inputs checked, not all4,294,967,296. Four dense/low ranges finish; positive-high is partial and negative-high has no result. Please retain that boundary in the coverage claim, or add the missing completed evidence. I have not reproduced the console measurement myself.Independent Windows11 build26200 / MSYS2 UCRT GCC16.2.0-6 checks:
Math.cppfrom head and unchanged base7a25f87620a9b862dc194dd0f659686b0f6cc8b0, linked with the actualFloatingPoint.cppandMathExact.cpp. The external harness supplies__error_nid_postfixasreturn &errno;(the same body asProcess.cpp) and an unused throwing unimplemented hook. No math or_Feraiseresult/flag behavior is mocked. This is an isolated executable harness, not the full shared libc/guest TLS integration.coshf_nid_postfixcalls per version /6,360 total: the18 recorded edge inputs plus256 deterministic finite overflow magnitudes of both signs, under MXCSR0x1f80 and0x9fc0, with clean flags or a pre-existing invalid/divide-by-zero flag in both units. Rounding is nearest and traps are masked.GuestMathExact.cppfixture passes in this isolated harness (one locally registered CTest,0.06s). I did not independently run the fullGuestMath.cppproduct fixture or the repository's registered product targets; the PR's reported runs remain author evidence. No Linux/macOS, title, GPU, hosted workflow or alternative-rounding/unmasked-trap console behavior is certified.Relevant math/fenv/process production and math test inputs are unchanged from the base above through fetched main
baabfbc2046a850e54e60af3a7fd9949f4669e1d; only this PR's stated math/test/debt patch is under review. Current conventions and whitespace checks pass; author checkout is clean. Existing documentation merge-order coordination remains as recorded in the PR, not newly resolved by this review.AI-assisted review and native probe; the stated local checks actually executed.
Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T18:55:22Z.
Review: APPROVED
Re-reviewed exact head
f82f0ccefba719274c035d2aae7c412abacd0bd3and the updated description. Approve: my measurement-coverage finding is corrected.The description now gives 2,310,537,216 of2^32 inputs, states that both below90 ranges completed, limits positive-high to the recorded stop at0x47040000, and states that negative-high was not reached. The debt entry also records the expired time budget instead of claiming an all-pattern sweep. These bounds agree with the previously reviewed console log at gist revision5b4b44ab28536d90398a8a155192cc596bbd1905. The description supplies the local host-comparison build settings and hashes; I have not independently repeated those hash sweeps.
Git confirms that only
docs/dev/debt/libc.mdchanged from reviewed894cbf6. Production math/fenv and test inputs are identical, so the earlier6,360-call native head/base comparison and18 recorded-edge comparisons still apply to the unchanged code. I did not rerun them for this documentation-only revision. Their existing scope remains: isolated Windows native harness, nearest rounding and masked traps, with the disclosed errno interface adapter; no new console/full-product/Linux/macOS or exhaustive numeric result is claimed.Current conventions against main
e1ef22e888d7fd09cffbe71042676d6a5910787b, whitespace and clean-checkout checks pass. The code path already passed my checks, and the unsupported coverage wording has now been removed. The corrected inline thread is still marked unresolved; please resolve it from the author/maintainer side.AI-assisted re-review. No remaining finding from my prior review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T07:54:36Z.
Review: APPROVED
Reviewed — looks good
The change matches the documented PS5 overflow behavior for
coshf, and the added tests check the overflow result,errno, and exception flags.What I ran
Reviewed head
81e964909314a227856c46c17f618f1bae7fa65e. No commands or tests were run in this review; the reader was used to inspect the prepared diff and pinned repository files.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Physical console behavior and the reported Windows and Linux test runs were not independently verified. All changed files listed in the manifest were read:
core/libs/prx/libc/src/Math.cpp,core/libs/tests/GuestMath.cpp, anddocs/dev/debt/libc.md. No changed files were excluded;review/files.jsonwas unavailable through the reader.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T20:10:55Z.
Review: APPROVED
Reviewed — looks good
Nothing in the reviewed change blocks merging; the overflow path and regression checks align with the stated behavior.
What I ran
Reviewed head
9ab03b5f47f2f3e69db2930ec7ac478c6df284ddusingrepo_read.pyfor changed lines and targeted context. No build or tests were run; results reported in the description are author supplied.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No independent build, test run, or console measurement was performed. Reviewed all changed files listed in the manifest:
core/libs/prx/libc/src/Math.cpp,core/libs/tests/GuestMath.cpp, anddocs/dev/debt/libc.md; none were excluded. The PR description's reported test and console results were not independently verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:25:14Z.
Review: COMMENTED
Built the focused checks against the existing Linux runtime. The exact
coshfboundary and floating-point flag checks passed when run alone. The broader math fixture stopped in a separate_FCoshcase in this standalone setup.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.