feat(libc): export the std::__sce_v2 _Stollx, _Stoullx, _Stolx and _Stoulx parsers #15683

Merged
Danigamer05 merged 1 commit from upstream-pr/15683 into main 2026-11-07 16:37:57 +00:00
Danigamer05 commented 2026-11-04 04:25:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-04T04:25:00Z.


What

Export the versioned std::__sce_v2 _Stollx, _Stoullx, _Stolx and _Stoulx from libc.

Export NID Original RVA
_ZNSt8__sce_v27_StollxEPKcPPciPi 9kHKVS+3PzY 0x10A7D0
_ZNSt8__sce_v28_StoullxEPKcPPciPi XORecIx0t+c 0x10A910
_ZNSt8__sce_v26_StolxEPKcPPciPi bearuT1s7C0 0xF4090
_ZNSt8__sce_v27_StoulxEPKcPPciPi l9qFfwjoLF0 0xF41C0

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).

They are not forwards to the unversioned _Stollx family. In the module, the versioned calls are the older Dinkumware parser, built on the module's fixed C-locale tables, and they differ from the unversioned ones: an invalid base returns 0 with no error, where the unversioned calls report EINVAL. #9526 lists these four as left out of that PR. As in the module:

  • the unsigned calls skip the C spaces (tab to carriage return and space), take one sign, accept bases 0 and 2 to 36, and skip a 0x or 0X prefix for base 16 (base 0 picks 16, 8 or 10 from the prefix);
  • a text with no digits, a prefix with nothing after it, and an invalid base all return 0 and set the end to the start of the text;
  • overflow is found with the Dinkumware digit-count table, sets errno to ERANGE and the error to 1, and returns all ones; a negative text is negated otherwise;
  • the signed calls skip spaces and their own sign, then call the unsigned one on the rest, so - 5 parses as -5 and --5 overflows. A result out of the signed range returns the lowest or highest value with ERANGE;
  • _Stolx and _Stoulx work on 32 bits, with the 32-bit table, and return the value zero-extended to 64 bits, as the module's 32-bit registers do. So _Stolx("-5") returns 0xFFFFFFFB.

VersionedUnsigned and VersionedSigned sit in DinkumwareInternals.cpp beside the unversioned calls, templated on the 64- or 32-bit unsigned type.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main c2eafe4461b. Exact tested commit: 5aef7e58920.

  • Built libc, libkernel, their NID-patched production libraries and the related tests. The new guest_sce_v2_string_to_integer, guest_dinkumware_internals, public_headers, guest_math_exact and the other guest_dinkumware_* CTests pass, along with the other guest_sce_v2_* CTests.

  • The new test checks 43 texts through all four calls, with the value, the end, the error and errno, and again with null end and error pointers: decimal, signed, hexadecimal and octal texts, base 36, bases 1, 37 and -1, empty texts, a sign alone, a space after the sign, two signs, every C space and a no-break space, leading zeros, and the edges of the 64- and 32-bit signed and unsigned ranges in bases 2, 10, 16 and 36. Every expected value was taken from the original module, not from this implementation.

  • The original functions were loaded from the bundled module with their relocations applied. Their imports were bound by NID to this branch's libc and libkernel, with __stack_chk_guard pointing at a local value; the module's own _Getpctype, _Getptolower and memchr ran from the module.

  • Side by side with the patched production library, the value, the end, the error, an unchanged text, errno, MXCSR and the x87 control and status words agree in all 20,020,800 calls over two seeds. The inputs mixed fixed edge texts, random bytes, spaces, one to three signs, prefixes, runs of zeros, digit counts around both overflow limits, mixed-case digits and trailing characters, with bases 0 to 36, invalid and random bases, and null or real end and error pointers.

  • Negative control: five lines were altered one at a time:

    • a carriage return was no longer a space;
    • a signed lowest value was reported as an overflow;
    • the overflow check at the digit limit was removed;
    • the 32-bit calls used the 64-bit digit table;
    • the signed calls kept the inner end when no digits followed the sign.

    The new CTest failed on each, and the side-by-side run reported differences each time. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again.

  • Code conventions and git diff --check pass.

  • tools/pr_overlap.py read 1,831 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 49 branches that already conflict with main. None of them adds a line naming these exports or helpers; #13486 is a relinker change that also touches DinkumwareInternals.cpp. Merging each of the 49 with this branch and with main using git merge-tree gives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614 and #15667.

Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5148840824 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15683). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-04T04:25:00Z. --- ### What Export the versioned `std::__sce_v2` `_Stollx`, `_Stoullx`, `_Stolx` and `_Stoulx` from libc. | Export | NID | Original RVA | | --- | --- | --- | | `_ZNSt8__sce_v27_StollxEPKcPPciPi` | `9kHKVS+3PzY` | `0x10A7D0` | | `_ZNSt8__sce_v28_StoullxEPKcPPciPi` | `XORecIx0t+c` | `0x10A910` | | `_ZNSt8__sce_v26_StolxEPKcPPciPi` | `bearuT1s7C0` | `0xF4090` | | `_ZNSt8__sce_v27_StoulxEPKcPPciPi` | `l9qFfwjoLF0` | `0xF41C0` | The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`). They are not forwards to the unversioned `_Stollx` family. In the module, the versioned calls are the older Dinkumware parser, built on the module's fixed C-locale tables, and they differ from the unversioned ones: an invalid base returns 0 with no error, where the unversioned calls report `EINVAL`. #9526 lists these four as left out of that PR. As in the module: - the unsigned calls skip the C spaces (tab to carriage return and space), take one sign, accept bases 0 and 2 to 36, and skip a `0x` or `0X` prefix for base 16 (base 0 picks 16, 8 or 10 from the prefix); - a text with no digits, a prefix with nothing after it, and an invalid base all return 0 and set the end to the start of the text; - overflow is found with the Dinkumware digit-count table, sets `errno` to `ERANGE` and the error to 1, and returns all ones; a negative text is negated otherwise; - the signed calls skip spaces and their own sign, then call the unsigned one on the rest, so `- 5` parses as -5 and `--5` overflows. A result out of the signed range returns the lowest or highest value with `ERANGE`; - `_Stolx` and `_Stoulx` work on 32 bits, with the 32-bit table, and return the value zero-extended to 64 bits, as the module's 32-bit registers do. So `_Stolx("-5")` returns `0xFFFFFFFB`. `VersionedUnsigned` and `VersionedSigned` sit in `DinkumwareInternals.cpp` beside the unversioned calls, templated on the 64- or 32-bit unsigned type. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows x86-64, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, main `c2eafe4461b`. Exact tested commit: `5aef7e58920`. - Built libc, libkernel, their NID-patched production libraries and the related tests. The new `guest_sce_v2_string_to_integer`, `guest_dinkumware_internals`, `public_headers`, `guest_math_exact` and the other `guest_dinkumware_*` CTests pass, along with the other `guest_sce_v2_*` CTests. - The new test checks 43 texts through all four calls, with the value, the end, the error and `errno`, and again with null end and error pointers: decimal, signed, hexadecimal and octal texts, base 36, bases 1, 37 and -1, empty texts, a sign alone, a space after the sign, two signs, every C space and a no-break space, leading zeros, and the edges of the 64- and 32-bit signed and unsigned ranges in bases 2, 10, 16 and 36. Every expected value was taken from the original module, not from this implementation. - The original functions were loaded from the bundled module with their relocations applied. Their imports were bound by NID to this branch's libc and libkernel, with `__stack_chk_guard` pointing at a local value; the module's own `_Getpctype`, `_Getptolower` and `memchr` ran from the module. - Side by side with the patched production library, the value, the end, the error, an unchanged text, `errno`, MXCSR and the x87 control and status words agree in all 20,020,800 calls over two seeds. The inputs mixed fixed edge texts, random bytes, spaces, one to three signs, prefixes, runs of zeros, digit counts around both overflow limits, mixed-case digits and trailing characters, with bases 0 to 36, invalid and random bases, and null or real end and error pointers. - Negative control: five lines were altered one at a time: - a carriage return was no longer a space; - a signed lowest value was reported as an overflow; - the overflow check at the digit limit was removed; - the 32-bit calls used the 64-bit digit table; - the signed calls kept the inner end when no digits followed the sign. The new CTest failed on each, and the side-by-side run reported differences each time. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again. - Code conventions and `git diff --check` pass. - `tools/pr_overlap.py` read 1,831 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 49 branches that already conflict with main. None of them adds a line naming these exports or helpers; #13486 is a relinker change that also touches `DinkumwareInternals.cpp`. Merging each of the 49 with this branch and with main using `git merge-tree` gives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614 and #15667. Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!15683
No description provided.