fix(libc): safely probe the output pointers of modfl and remquol #20589
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20589"
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 milescoviello on 2026-11-15T10:36:41Z.
What
modflpassed the guest pointer to the hoststd::modf, andremquolstored the quotient bits straight through it, so an output pointing at unmapped memory faulted the host.Both now compute the value on the host and write it with
GuestCopyOut_nid_no_patch. They have no error result, so an unwritable output is skipped and the return value is still correct, the way the other no-error-channel exports handle an unwritable output. The values,errno(EDOMforremquol) and the floating-point exceptions for valid pointers are unchanged.The float and double versions (
modf,modff,remquo,remquof,sincosf) keep the direct store. They run per element in game math loops, and the probe is aprocess_vm_writevper store on Linux: measured below, it tooksincosffrom about 4 ns to about 670 ns a call. The long double versions are rarely called.The debt entry goes in a fragment under
docs/dev/debt/changes/. It records this as a host-safety fallback (console behaviour on unmapped memory isn't measured) and why the float and double versions keep the direct store.Tested
Linux (Ubuntu 26.04.1), GCC 15.2, Release.
guest_math_exact:remquol(-7, 2)with an unmapped quotient (0x10) returns 1;modfl(2.5)stores 2 and returns 0.5, and returns 0.5 with an unmapped integral. The existing signalling-NaN,EDOMand quotient checks still pass.guest_mathstill passes.Negative control: with
MathExact.cppfrommainand these tests,guest_math_exactsegfaults.Per-call cost, 1M calls with a valid pointer on one pinned core (
taskset -c 4), three interleaved runs per side:mainsincosfmodflremquolThe first version of this PR probed every output; there
sincosfmeasured 665-676 ns (vs 3.7-3.8),modf/modff332-340 ns (vs 1.3-1.4), andremquo/remquof349-357 ns (vs 12.9-13.3).git merge-treeagainst the open PRs that touchMathExact.cpporGuestMathExact.cpp(#18524, #15143): no new conflicts.tools/check_conventions.pypasses on the branch and this body;tools/debt_fold.py --checkpasses with the fragment applied tomain.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)