feat(libSceLibcInternal): construct collate facets #22428

Merged
MarrasFederico merged 1 commit from upstream-pr/22428 into main 2026-11-17 23:57:26 +00:00
MarrasFederico commented 2026-11-17 15:19:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-17T15:19:56Z.


What

Implement the four std::collate<char> constructors in libSceLibcInternal (_ZNSt7collateIcEC1Em / Oo1r8jKGZQ4, _ZNSt7collateIcEC1EPKcm / splBMMcF3yk, _ZNSt7collateIcEC1ERKSt8_Locinfom / raLgIUi3xmk, _ZNSt7collateIcEC2EPKcm / VClCrMDyydE) and remove their inventory stubs:

  • Validate "C" locale names through _Locinfo via RAII ScopedLocinfo before modifying *this, rejecting null this, null _Locinfo, null/empty strings, and non-"C" names with std::invalid_argument.
  • Install _ZTVSt7collateIcE on the 0x20-byte facet, store the full 64-bit references value (references + reserved), and zero the two collation pointers at offsets 0x10 and 0x18, leaving non-C locales unsupported as in libc's _Getcat.
  • Add layout, operation (compare/hash/transform), lifetime/destruction, error-branch, and shared-library symbol dispatch coverage in GuestLibcInternalCollate.cpp.

Tested

Coordinator verification at c784eca370e53d345bc763382c718430e43d0b8a: Four focused tests passed, each repeated three times; the recorded constructor-vtable negative failed its expected compare assertion, with byte-exact restoration. Clean merge-tree against upstream/main 5a23c6303baf68166689edbfcc78adf7160b05cd; conventions, public-header audit and diff checks passed. Fresh overlap scan covered 1720 open PRs; no functional duplicate found. Windows was not tested. The existing main wcstombs fragment collision remains outside this change.

  • Built separate targets (libSceLibcInternal, core/libs/libs/libSceLibcInternal.prx, guest_libc_internal_collate_tests, guest_collate_tests, guest_libc_internal_empty_facet_members_tests, guest_libc_internal_messages_tests) on Linux (Release, Ninja, BUILD_TESTING=ON).
  • Ran ctest --test-dir build --output-on-failure -R '^(guest_collate|guest_libc_internal_collate|guest_libc_internal_empty_facet_members|guest_libc_internal_messages)$' -> 4/4 Passed, and --repeat until-fail:3 -R '^guest_libc_internal_collate$' -> 3/3 Passed.
  • Verified Oo1r8jKGZQ4, splBMMcF3yk, raLgIUi3xmk, VClCrMDyydE exported in libSceLibcInternal.prx (nm -D) and ran static checks (check_conventions.py --base upstream/main, test_public_headers.py --audit-only, git diff --check upstream/main...HEAD).
  • Not tested on PS5 console hardware or real titles.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5359621540 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22428). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-11-17T15:19:56Z. --- ### What Implement the four `std::collate<char>` constructors in `libSceLibcInternal` (`_ZNSt7collateIcEC1Em` / `Oo1r8jKGZQ4`, `_ZNSt7collateIcEC1EPKcm` / `splBMMcF3yk`, `_ZNSt7collateIcEC1ERKSt8_Locinfom` / `raLgIUi3xmk`, `_ZNSt7collateIcEC2EPKcm` / `VClCrMDyydE`) and remove their inventory stubs: - Validate `"C"` locale names through `_Locinfo` via RAII `ScopedLocinfo` before modifying `*this`, rejecting null `this`, null `_Locinfo`, null/empty strings, and non-`"C"` names with `std::invalid_argument`. - Install `_ZTVSt7collateIcE` on the `0x20`-byte facet, store the full 64-bit `references` value (`references` + `reserved`), and zero the two collation pointers at offsets `0x10` and `0x18`, leaving non-C locales unsupported as in `libc`'s `_Getcat`. - Add layout, operation (`compare`/`hash`/`transform`), lifetime/destruction, error-branch, and shared-library symbol dispatch coverage in `GuestLibcInternalCollate.cpp`. ### Tested Coordinator verification at `c784eca370e53d345bc763382c718430e43d0b8a`: Four focused tests passed, each repeated three times; the recorded constructor-vtable negative failed its expected compare assertion, with byte-exact restoration. Clean merge-tree against upstream/main `5a23c6303baf68166689edbfcc78adf7160b05cd`; conventions, public-header audit and diff checks passed. Fresh overlap scan covered 1720 open PRs; no functional duplicate found. Windows was not tested. The existing main wcstombs fragment collision remains outside this change. - Built separate targets (`libSceLibcInternal`, `core/libs/libs/libSceLibcInternal.prx`, `guest_libc_internal_collate_tests`, `guest_collate_tests`, `guest_libc_internal_empty_facet_members_tests`, `guest_libc_internal_messages_tests`) on Linux (`Release`, `Ninja`, `BUILD_TESTING=ON`). - Ran `ctest --test-dir build --output-on-failure -R '^(guest_collate|guest_libc_internal_collate|guest_libc_internal_empty_facet_members|guest_libc_internal_messages)$'` -> `4/4 Passed`, and `--repeat until-fail:3 -R '^guest_libc_internal_collate$'` -> `3/3 Passed`. - Verified `Oo1r8jKGZQ4`, `splBMMcF3yk`, `raLgIUi3xmk`, `VClCrMDyydE` exported in `libSceLibcInternal.prx` (`nm -D`) and ran static checks (`check_conventions.py --base upstream/main`, `test_public_headers.py --audit-only`, `git diff --check upstream/main...HEAD`). - Not tested on PS5 console hardware or real titles. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
PrivacyOnion commented 2026-11-17 15:22:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T15:22:05Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c784eca370:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_internal_collate_tests built cleanly.
  • CTest (guest_libc_internal_collate):
    1/1 Test #4197: guest_libc_internal_collate ......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/Collate.cpp, core/libs/prx/libSceLibcInternal/InventoryExports6.cpp, core/libs/prx/libSceLibcInternal/include/Api.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified that _ZNSt7collateIcEC1Em_nid_postfix, _ZNSt7collateIcEC1EPKcm_nid_postfix, _ZNSt7collateIcEC1ERKSt8_Locinfom_nid_postfix, and _ZNSt7collateIcEC2EPKcm_nid_postfix validate null pointers on self and locinfo, throwing std::invalid_argument prior to mutating state.
    • Verified that locale names are validated through ScopedLocinfo via _ZNSt8_LocinfoC1EPKc_nid_postfix and cleaned up via _ZNSt8_LocinfoD1Ev_nid_postfix, properly rejecting null, empty, and non-'C' locale strings before InitCollateFacet touches memory.
    • Checked facet memory layout, 64-bit references assignment (low 32-bit references and high 32-bit reserved), zeroing of collation and wideCollation pointers, and vtable initialization to BaseCollate().facet (_ZTVSt7collateIcE).
    • Verified technical debt tracking in docs/dev/debt/changes/feat-libcinternal-collate-construction.md correctly records removals of the four inventory stubs and documents the known C-only collation gap in compliance with AGENTS.md.
    • Checked GuestLibcInternalCollate.cpp for test rigor, covering layout, operations (compare, hash, transform), reference counting and lifetime management, error paths, and dynamic symbol dispatch on both Linux and Windows.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5941251786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22428#pullrequestreview-5941251786). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T15:22:05Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c784eca370`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libc_internal_collate_tests` built cleanly. - **CTest** (`guest_libc_internal_collate`): ``` 1/1 Test #4197: guest_libc_internal_collate ...... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/Collate.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports6.cpp`, `core/libs/prx/libSceLibcInternal/include/Api.hpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified that _ZNSt7collateIcEC1Em_nid_postfix, _ZNSt7collateIcEC1EPKcm_nid_postfix, _ZNSt7collateIcEC1ERKSt8_Locinfom_nid_postfix, and _ZNSt7collateIcEC2EPKcm_nid_postfix validate null pointers on self and locinfo, throwing std::invalid_argument prior to mutating state. - Verified that locale names are validated through ScopedLocinfo via _ZNSt8_LocinfoC1EPKc_nid_postfix and cleaned up via _ZNSt8_LocinfoD1Ev_nid_postfix, properly rejecting null, empty, and non-'C' locale strings before InitCollateFacet touches memory. - Checked facet memory layout, 64-bit references assignment (low 32-bit references and high 32-bit reserved), zeroing of collation and wideCollation pointers, and vtable initialization to BaseCollate().facet (_ZTVSt7collateIcE). - Verified technical debt tracking in docs/dev/debt/changes/feat-libcinternal-collate-construction.md correctly records removals of the four inventory stubs and documents the known C-only collation gap in compliance with AGENTS.md. - Checked GuestLibcInternalCollate.cpp for test rigor, covering layout, operations (compare, hash, transform), reference counting and lifetime management, error paths, and dynamic symbol dispatch on both Linux and Windows. Looks Good To Me
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!22428
No description provided.