fix(libc): throw for __std_min/max ranges that fault on a device #12605
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12605"
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 KernelPanicNT on 2026-10-28T22:33:53Z.
What
__std_min_{4,8}{i,u}and__std_max_{4,8}{i,u}now throwstd::invalid_argumentfor null, empty, reversed and partial-element ranges instead of callingNotImplemented_nid_no_patch. On a device the same NIDs faulted for every such input the probe tried (table below); other null, reversed or partial ranges are assumed to fault the same way, so there is no return value to reproduce. Throwing where the console faults follows thefeholdexceptandfeupdateenventries in thelibcdebt. Nonempty ranges are unchanged.Source of the behaviour
Measured with a homebrew probe as a payload process on a device (firmware 13.00). The probe resolved all eight names in the system
libSceLibcInternal.sprxand called each one on its own stack arrays, with a fault handler around every call:{5, -3, 7, 2}-3/7signed;2/-3as unsigned, i.e.0xfffffffdfor 4-byte and0xfffffffffffffffdfor 8-byte)first == laston a valid bufferNotImplementedstd::invalid_argumentnullptr, nullptrNotImplementedstd::invalid_argumentNotImplementedstd::invalid_argumentNotImplementedstd::invalid_argumentThe same result held for all eight functions. The empty range faults even when both pointers are inside a valid buffer.
VectorAlgorithms.cpp#L161(__std_min_4i; the other seven have the same guard).libc.md#L37-L38(feholdexcept,feupdateenv)._Minmax_implreads*_Firstand walks the tail until_Ptr != _Lastfails (vector_algorithms.cpp#L3342-L3351); this is the library these helpers come from, not a disassembly of the console module.REVERSE_ENGINEERING.md#L9.The eight debt entries keep their disassembly notes and are cut to the remaining gap: these inputs throw here where the console faults.
Tested
Linux (Ubuntu, GCC, Release), on
main(b11c7bf84f) with this branch applied.guest_vector_algorithmspasses. Its newCheckInvalidRangescalls all eight functions with an empty range on a valid buffer, null bounds, a range reversed by one element and two partial-element ranges, and requiresstd::invalid_argumenteach time, plus a one-element range that must return its value. WithVectorAlgorithms.cppfrommainthe test aborts (__std_min_4i_nid_postfix not implemented).tools/progress.py: +8 implemented functions (libc 1628/1647 -> 1636/1647).tools/check_conventions.pypasses.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)