fix(libc): fmod leaves errno unchanged #3600

Merged
CouchRiv merged 1 commit from upstream-pr/3600 into main 2026-10-12 05:20:20 +00:00
CouchRiv commented 2026-10-11 14:07:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-11T14:07:46Z.


What

fmod(1.0, 0.0) sets errno to 33 on main. FreeBSD msun reports math errors through floating-point exceptions only and never sets errno (math.h#L67-L69), so a caller that checks errno after fmod sees a stale error on main.

fmod now saves errno before the host call and restores it after; the result and the floating-point flags do not change.

Tested

CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), lavapipe for CI parity.

  • guest_math: the new fmod_nid_postfix checks fail on main and pass with the change; 1/1 on NVIDIA, RADV and lavapipe.
  • tools/check_conventions.py --base origin/main and git diff --check: clean.
  • Windows and macOS not run.

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 in TechnicalDebt
  • 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

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819648845 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3600). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-11T14:07:46Z. --- ### What `fmod(1.0, 0.0)` sets errno to 33 on `main`. FreeBSD msun reports math errors through floating-point exceptions only and never sets errno ([math.h#L67-L69](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/msun/src/math.h#L67-L69)), so a caller that checks errno after `fmod` sees a stale error on `main`. `fmod` now saves errno before the host call and restores it after; the result and the floating-point flags do not change. ### Tested CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV), lavapipe for CI parity. - guest_math: the new `fmod_nid_postfix` checks fail on `main` and pass with the change; 1/1 on NVIDIA, RADV and lavapipe. - `tools/check_conventions.py --base origin/main` and `git diff --check`: clean. - Windows and macOS not run. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 AI-assisted: yes
blawesom commented 2026-10-11 15:20:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T15:20:13Z.


Independent pre-review on Linux (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • Builds; tools/check_conventions.py --base origin/main passes.
  • Full suite: 832/832 passed (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110521766 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3600#issuecomment-6110521766). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T15:20:13Z. --- Independent pre-review on **Linux** (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - Builds; `tools/check_conventions.py --base origin/main` passes. - Full suite: **832/832 passed** (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).
github-actions[bot] commented 2026-10-11 22:10:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T22:10:40Z.


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
#3725 core/libs/tests/GuestMath.cpp L178, L618-619
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114411681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3600#issuecomment-6114411681). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T22:10:40Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #3725 | `core/libs/tests/GuestMath.cpp` [L178](https://github.com/boykopovar/AnyPS5/blob/6d9a680fbb7cf535e9e48cc52195b6c0fa8f284a/core/libs/tests/GuestMath.cpp#L178), [L618-619](https://github.com/boykopovar/AnyPS5/blob/6d9a680fbb7cf535e9e48cc52195b6c0fa8f284a/core/libs/tests/GuestMath.cpp#L618-L619) | | |
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!3600
No description provided.