fix(libSceLibcInternal): honor caller ctype facet tables #19547

Merged
fogydes merged 7 commits from upstream-pr/19547 into main 2026-11-14 16:02:24 +00:00
fogydes commented 2026-11-13 14:33:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-11-13T14:33:24Z.


What

Correct the four unversioned std::ctype<char> case methods to use the caller facet's lower/upper mapping tables. A custom table mapping A to z previously returned classic-locale a; it now returns z. Scalar and range methods use unsigned byte indices and the low byte of each short entry. Range calls include embedded NULs, reload the table pointer per element, preserve completed prefix writes on later faults, and return the original end pointer. Empty ranges return before reading the facet. Wide-character methods are unchanged.

Clean-room source: readable libc.prx, SDK 10.00, raw ELF addresses 0x84080 / 0x840c0 (scalar lower/upper), 0x84090 / 0x840d0 (ranges), table reloads 0x840a3 / 0x840e3, empty checks 0x84093 / 0x840d3. Signatures/layout: SDK 10.00 target/include/xlocale:2461-2486, target/include/xlocinfo:51-57. These are SDK observations, not console measurements. No reference binaries or extracts are attached or linked.

Unusable memory, null tables and inverted ranges throw std::invalid_argument as documented host-safety policy; the SDK itself does not validate these pointers. Full unversioned facet construction and global vtable population remain unverified.

Measured with tools/progress.py --module libSceLibcInternal: 424 implemented / 706 TODO / 1130 total, unchanged before/after. The four NIDs were already present: tools/export_gap.py reports 0 missing / 4 provided / 0 unknown before/after. This corrects behavior without claiming increased export coverage.

The original implementation and overlap audit used main snapshot 228330220ba. Required tools/pr_overlap.py --branch fix/libSceLibcInternal-ctype-facet-tables inspected 1510 open heads and 36 relevant branches; it exited 2 because seven stale PRs could not be compared cleanly. Their exact heads/shared diffs were manually checked: no competing table-driven implementation, facet-layout collision or behavior dependency. Same-export overlap with #17300 remains: it renames an old throwing scalar-uppercase stub already superseded by main's typed provider; retain that provider when rebasing it. The grouped CMake registration avoids the prior EOF conflicts. No conflict-free claim is made for those stale whole branches.

Tested

Current head 2d19cbcd13c3f8e3826139dd2b5113d31c880962, based on main ca6f82ff3d9: Windows 11 / WinLibs GCC 15.2 Release affected build and 6/6 selected CTests pass (guest_ctype_case, guest_libc_internal_ctype, guest_locale, guest_appcontent, guest_ces_wide, guest_ces_wide_module). Main includes the CES timeout fix bbc937d0553 and merged AppContent regression revert #20058. Current conventions and merge-tree checks pass. The ctype implementation/test blobs are unchanged; older measurements and validation below retain their original revision scope.

  • Windows x64 WinLibs MinGW/GCC 15.2 Release, full runtime configuration: built affected libc, libkernel, libSceLibcInternal and focused guest test targets. ctest -R '^guest_(ctype_case|libc_internal_ctype|locale)$' --output-on-failure passed 3/3 on the final implementation from D drive.
  • Tests cover all 256 byte values, custom signed/high-byte mappings, classic mappings, embedded NULs, subranges, empty ranges, readonly/unmapped memory, completed prefix effects, low-byte reads at a guarded boundary and aliased table-pointer reloads.
  • A standalone executable built from main's unchanged Ctype.cpp reproduced the bug: expected=z actual=a, exit 1; corrected table behavior passes the focused suite.
  • Public-header audit: 413 libraries / 34518 declarations, unique/reachable headers passed. Repository nid_patcher produced a patched copy whose PE export table contains all four exact NIDs.
  • Final check_conventions.py --base origin/main and git diff --check passed. Overlap limitations are disclosed above.
  • No Linux, console or commercial-title execution; no GPU change or performance claim.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5297307486 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19547). Originally posted by [fogydes](https://github.com/fogydes) on 2026-11-13T14:33:24Z. --- ### What Correct the four unversioned `std::ctype<char>` case methods to use the caller facet's lower/upper mapping tables. A custom table mapping `A` to `z` previously returned classic-locale `a`; it now returns `z`. Scalar and range methods use unsigned byte indices and the low byte of each short entry. Range calls include embedded NULs, reload the table pointer per element, preserve completed prefix writes on later faults, and return the original end pointer. Empty ranges return before reading the facet. Wide-character methods are unchanged. Clean-room source: readable `libc.prx`, SDK 10.00, raw ELF addresses `0x84080` / `0x840c0` (scalar lower/upper), `0x84090` / `0x840d0` (ranges), table reloads `0x840a3` / `0x840e3`, empty checks `0x84093` / `0x840d3`. Signatures/layout: SDK 10.00 `target/include/xlocale:2461-2486`, `target/include/xlocinfo:51-57`. These are SDK observations, not console measurements. No reference binaries or extracts are attached or linked. Unusable memory, null tables and inverted ranges throw `std::invalid_argument` as documented host-safety policy; the SDK itself does not validate these pointers. Full unversioned facet construction and global vtable population remain unverified. Measured with `tools/progress.py --module libSceLibcInternal`: **424 implemented / 706 TODO / 1130 total**, unchanged before/after. The four NIDs were already present: `tools/export_gap.py` reports **0 missing / 4 provided / 0 unknown** before/after. This corrects behavior without claiming increased export coverage. The original implementation and overlap audit used main snapshot `228330220ba`. Required `tools/pr_overlap.py --branch fix/libSceLibcInternal-ctype-facet-tables` inspected 1510 open heads and 36 relevant branches; it exited 2 because seven stale PRs could not be compared cleanly. Their exact heads/shared diffs were manually checked: no competing table-driven implementation, facet-layout collision or behavior dependency. Same-export overlap with #17300 remains: it renames an old throwing scalar-uppercase stub already superseded by main's typed provider; retain that provider when rebasing it. The grouped CMake registration avoids the prior EOF conflicts. No conflict-free claim is made for those stale whole branches. ### 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. --> Current head `2d19cbcd13c3f8e3826139dd2b5113d31c880962`, based on main `ca6f82ff3d9`: Windows 11 / WinLibs GCC 15.2 Release affected build and 6/6 selected CTests pass (`guest_ctype_case`, `guest_libc_internal_ctype`, `guest_locale`, `guest_appcontent`, `guest_ces_wide`, `guest_ces_wide_module`). Main includes the CES timeout fix `bbc937d0553` and merged AppContent regression revert #20058. Current conventions and merge-tree checks pass. The ctype implementation/test blobs are unchanged; older measurements and validation below retain their original revision scope. - Windows x64 WinLibs MinGW/GCC 15.2 Release, full runtime configuration: built affected libc, libkernel, libSceLibcInternal and focused guest test targets. `ctest -R '^guest_(ctype_case|libc_internal_ctype|locale)$' --output-on-failure` passed **3/3** on the final implementation from D drive. - Tests cover all 256 byte values, custom signed/high-byte mappings, classic mappings, embedded NULs, subranges, empty ranges, readonly/unmapped memory, completed prefix effects, low-byte reads at a guarded boundary and aliased table-pointer reloads. - A standalone executable built from main's unchanged Ctype.cpp reproduced the bug: `expected=z actual=a`, exit 1; corrected table behavior passes the focused suite. - Public-header audit: **413 libraries / 34518 declarations**, unique/reachable headers passed. Repository nid_patcher produced a patched copy whose PE export table contains all four exact NIDs. - Final `check_conventions.py --base origin/main` and `git diff --check` passed. Overlap limitations are disclosed above. - No Linux, console or commercial-title execution; no GPU change or performance claim. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
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!19547
No description provided.