feat(libc): implement atol and atoll #2932

Merged
reyani-dev merged 1 commit from upstream-pr/2932 into main 2026-10-10 21:53:29 +00:00
reyani-dev commented 2026-10-10 18:33:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T18:33:46Z.


Resubmission of #2186, which was closed because no title was shown stopping on it. The title evidence has since been posted there by @babyhuey (run):

On main c963432d, PSXS5 (PPSA97510), SwanStationPS5 (PPSA98510), EVO Player (PPSA99039) and Nuvio PS5 (PPSA99997) stop at atoll (fLcU5G6Qrjs), and ProsperoPuzzles (PPSA99006) and PSBox Cloud Gaming (PPSA99810) stop at atol (+my9jdHCMIQ): Windows FAIL: unresolved ELF import fLcU5G6Qrjs (atoll) from libSceLibcInternal.prx, Linux undefined symbol: fLcU5G6Qrjs. With this change each moves on to its next import, and OpenRCT2 (PPSA99728) reaches atol after llroundf.

The function is still absent on current main, and no open PR implements it. The branch is rebased onto current main. Windows 11 (WinLibs GCC 15.2.0), Release: guest_math passes 3/3, check_conventions.py passes, and pr_overlap.py reports no overlap.


What

Exports atol and atoll. FreeBSD defines them as strtol(str, NULL, 10) and strtoll(str, NULL, 10). The guest long is 64 bits (as strtol_nid_postfix already assumes), so atol calls std::strtoll rather than the host atol, whose long is 32 bits on Windows.

Titles: from the #1578 audit, imported from libSceLibcInternal (resolved through libc.prx):

  • atoll (fLcU5G6Qrjs): PPSA99039 EVO Player, which stops on Windows with FAIL: unresolved ELF import fLcU5G6Qrjs from libSceLibcInternal.prx; also Stremio Plus, RetroArch, PS5MC, Porpoise
  • atol: PPSA74126 Stremio Plus, PPSA92280 Capy Mobile, PPSA99169 RetroArch, PPSA99420 PS5MC

I haven't run any of these titles.

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Release, -DBUILD_TESTING=ON:

  • New checks in guest_math_tests, next to the strtol cases:
    • leading white space and sign;
    • values beyond 32 bits (-4294967296, INT64_MAX, INT64_MIN, 4294967297x);
    • base 10 only ("0x10" → 0, "010" → 10);
    • empty and non-numeric input → 0.
  • Mutation check: the host std::atol (32-bit long on Windows) and strtoll(..., 0) each make guest_math fail.
  • cmake --build build --target libs: the patched libc.prx exports +my9jdHCMIQ (atol) and fLcU5G6Qrjs (atoll).
  • tools/check_conventions.py passes, and tools/pr_overlap.py --branch reports no overlap.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813520744 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2932). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T18:33:46Z. --- Resubmission of #2186, which was closed because no title was shown stopping on it. The title evidence has since been posted there by @babyhuey ([run](https://github.com/boykopovar/AnyPS5/pull/2186#issuecomment-6092621656)): On `main` c963432d, PSXS5 (PPSA97510), SwanStationPS5 (PPSA98510), EVO Player (PPSA99039) and Nuvio PS5 (PPSA99997) stop at `atoll` (`fLcU5G6Qrjs`), and ProsperoPuzzles (PPSA99006) and PSBox Cloud Gaming (PPSA99810) stop at `atol` (`+my9jdHCMIQ`): Windows `FAIL: unresolved ELF import fLcU5G6Qrjs (atoll) from libSceLibcInternal.prx`, Linux `undefined symbol: fLcU5G6Qrjs`. With this change each moves on to its next import, and OpenRCT2 (PPSA99728) reaches `atol` after `llroundf`. The function is still absent on current `main`, and no open PR implements it. The branch is rebased onto current `main`. Windows 11 (WinLibs GCC 15.2.0), Release: `guest_math` passes 3/3, `check_conventions.py` passes, and `pr_overlap.py` reports no overlap. --- ### What Exports `atol` and `atoll`. FreeBSD defines them as `strtol(str, NULL, 10)` and `strtoll(str, NULL, 10)`. The guest `long` is 64 bits (as `strtol_nid_postfix` already assumes), so `atol` calls `std::strtoll` rather than the host `atol`, whose `long` is 32 bits on Windows. Titles: from the #1578 audit, imported from `libSceLibcInternal` (resolved through `libc.prx`): - `atoll` (`fLcU5G6Qrjs`): PPSA99039 EVO Player, which stops on Windows with `FAIL: unresolved ELF import fLcU5G6Qrjs from libSceLibcInternal.prx`; also Stremio Plus, RetroArch, PS5MC, Porpoise - `atol`: PPSA74126 Stremio Plus, PPSA92280 Capy Mobile, PPSA99169 RetroArch, PPSA99420 PS5MC I haven't run any of these titles. ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Release, `-DBUILD_TESTING=ON`: - New checks in `guest_math_tests`, next to the `strtol` cases: - leading white space and sign; - values beyond 32 bits (`-4294967296`, `INT64_MAX`, `INT64_MIN`, `4294967297x`); - base 10 only (`"0x10"` → 0, `"010"` → 10); - empty and non-numeric input → 0. - Mutation check: the host `std::atol` (32-bit `long` on Windows) and `strtoll(..., 0)` each make `guest_math` fail. - `cmake --build build --target libs`: the patched `libc.prx` exports `+my9jdHCMIQ` (`atol`) and `fLcU5G6Qrjs` (`atoll`). - `tools/check_conventions.py` passes, and `tools/pr_overlap.py --branch` reports no overlap. ### 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 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
reyani-dev commented 2026-10-10 18:57:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T18:57:47Z.


Full Linux and Windows builds and tests for this head (90915850), using the project's Build workflow. I can't start the upstream manual run, so I ran the same build.yml in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current main (bf6e25a1):

Job Result
linux success; full build, ctest: 703/703 passed
windows success; full build, ctest: 711/711 passed
relinker (Linux, Windows, macOS) success

Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/38076396830

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101053634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2932#issuecomment-6101053634). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T18:57:47Z. --- Full Linux and Windows builds and tests for this head (`90915850`), using the project's Build workflow. I can't start the upstream manual run, so I ran the same `build.yml` in my fork through a mirror PR. Like the upstream run, the jobs check out the PR head merged into current `main` (`bf6e25a1`): | Job | Result | |---|---| | [linux](https://github.com/AchrafReyani/AnyPS5/actions/runs/38076396830/job/114284151307) | success; full build, `ctest`: 703/703 passed | | [windows](https://github.com/AchrafReyani/AnyPS5/actions/runs/38076396830/job/114284151397) | success; full build, `ctest`: 711/711 passed | | relinker (Linux, Windows, macOS) | success | Run: https://github.com/AchrafReyani/AnyPS5/actions/runs/38076396830
github-actions[bot] commented 2026-10-10 19:00:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T19:00:14Z.


Progress report (1476f76 → 9091585)

📈 System libraries: 84.57% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libc atol_nid_postfix
libc atoll_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101075875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2932#issuecomment-6101075875). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T19:00:14Z. --- <!-- progress-report --> ### Progress report (1476f76 → 9091585) 📈 **System libraries**: 84.57% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `atol_nid_postfix` | | libc | `atoll_nid_postfix` | </details>
babyhuey commented 2026-10-10 19:09:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T19:09:32Z.


Heads-up so the evidence here isn't read against the wrong layout: the runs of mine linked in the description are from main c963432d, before #2605. Since #2605 each title's sce_module/libc.prx has to be unwrapped, and that module is the SDK shim whose exports point 1872 libc functions at one return-0 stub (#2652). So on current main (9c5d67fb, catalog run with the module unwrapped) PSXS5 (PPSA97510) and SwanStationPS5 (PPSA98510) stop at utime (#2967), ProsperoPuzzles (PPSA99006) at _umtx_op (#1482) and EVO Player (PPSA99039) at Tf9-yOJwF-A (#2887), none at atol or atoll. The stop comes back once the shim's return-0 exports are left out, which is what the closed #2705 did; its table lists PSXS5, SwanStationPS5 and EVO Player at atoll and ProsperoPuzzles at atol.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101159559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2932#issuecomment-6101159559). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T19:09:32Z. --- Heads-up so the evidence here isn't read against the wrong layout: the runs of mine linked in the description are from `main` c963432d, before #2605. Since #2605 each title's `sce_module/libc.prx` has to be unwrapped, and that module is the SDK shim whose exports point 1872 libc functions at one return-0 stub (#2652). So on current `main` (9c5d67fb, catalog run with the module unwrapped) PSXS5 (PPSA97510) and SwanStationPS5 (PPSA98510) stop at `utime` (#2967), ProsperoPuzzles (PPSA99006) at `_umtx_op` (#1482) and EVO Player (PPSA99039) at `Tf9-yOJwF-A` (#2887), none at `atol` or `atoll`. The stop comes back once the shim's return-0 exports are left out, which is what the closed #2705 did; its table lists PSXS5, SwanStationPS5 and EVO Player at `atoll` and ProsperoPuzzles at `atol`.
reyani-dev commented 2026-10-10 19:17:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T19:17:28Z.


Thanks @babyhuey, that's an important caveat. These titles' imports declare libSceLibcInternal, so on current main they bind to the bundled SDK shim's return-0 export (#1497/#2652) instead of failing at load, which hides the stop. Once #1529 keeps libSceLibcInternal-declared imports host-bound, the stop comes back, as the closed #2705 table showed. Either way, these titles call the real function, so on main they currently get 0 from it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101231312 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2932#issuecomment-6101231312). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-10T19:17:28Z. --- Thanks @babyhuey, that's an important caveat. These titles' imports declare `libSceLibcInternal`, so on current `main` they bind to the bundled SDK shim's return-0 export (#1497/#2652) instead of failing at load, which hides the stop. Once #1529 keeps `libSceLibcInternal`-declared imports host-bound, the stop comes back, as the closed #2705 table showed. Either way, these titles call the real function, so on `main` they currently get 0 from it.
adriadam10 commented 2026-10-10 21:53:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T21:53:26Z.


Checked on current main: guest_math passes, and without the change the test fails to link (atol/atoll undefined). atol/atoll as strtoll(str, nullptr, 10) matches FreeBSD's strtol(str, NULL, 10) with a 64-bit guest long. Edge rows (±2^63, >32 bits, base 10 only, empty) are pinned. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102571121 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2932#issuecomment-6102571121). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T21:53:26Z. --- Checked on current main: `guest_math` passes, and without the change the test fails to link (`atol`/`atoll` undefined). `atol`/`atoll` as `strtoll(str, nullptr, 10)` matches FreeBSD's `strtol(str, NULL, 10)` with a 64-bit guest `long`. Edge rows (±2^63, >32 bits, base 10 only, empty) are pinned. Merging.
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!2932
No description provided.