feat(libSceLibcInternal): construct the messages<char> and messages<wchar_t> facets #21904

Merged
LeandroLP23 merged 1 commit from upstream-pr/21904 into main 2026-11-16 22:07:45 +00:00
LeandroLP23 commented 2026-11-16 20:48:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-11-16T20:48:57Z.


What

Implements the seven std::messages constructors that still threw: messages<char> C1(const char*, size_t), C1(const _Locinfo&, size_t), C2(const _Locinfo&, size_t) and C2(size_t), and messages<wchar_t> C1(const char*, size_t), C1(const _Locinfo&, size_t) and C2(size_t).

Each one writes the vtable pointer and the reference count into the 0x10-byte facet and nothing else. Both messages::_Init members are already a single ret from firmware 13.42 (the empty facet members debt entry), and Microsoft STL's xlocmes messages has no other members.

  • messages<char> gets the exported libc vtable _ZTVSt8messagesIcE (at slot 2), whose do_open, do_get and do_close are already wired.
  • No messages<wchar_t> vtable exists in the tree. The wide facet gets a vtable in libSceLibcInternal with the D1, D0, _Incref and _Decref slots and a do_open, do_get and do_close that behave as the exported messages<wchar_t> members do: -1, a copy of the default, nothing.
  • The constructors that take a locale name build and destroy a _Locinfo from it, so they accept the names _Locinfo(const char*) accepts.

The other messages constructors (C1(size_t), C2(const char*, size_t) and wide C1(size_t), C2(const char*, size_t), C2(const _Locinfo&, size_t)) are NID-only declarations, which #17300 names, so this PR leaves them alone. The debt fragment removes the seven stub entries and adds one that states what is not measured.

tools/progress.py --module libSceLibcInternal: 522 done / 609 to do on main 9b60c84343, 529 / 602 on this branch.

Tested

Windows 11, MinGW-w64 GCC 15.2, Release, BUILD_TESTING=ON, on main 9b60c84343.

  • guest_libc_internal_messages (extended) passes. For every constructor it checks that the vptr is the exported messages<char> vtable or the wide one, that the 64-bit reference count lands at offset 8 (with 0x100000007 to catch a truncated count), and that the bytes after the 0x10-byte facet stay as they were. It then calls the existing open, get and close exports on the constructed facets: open returns -1 in both widths, and get through the wide vtable copies a 20-unit wide default onto the heap. A wide facet allocated with operator new is retained, released and deleted through its own vtable, and the test's allocation counter comes back to where it started.
  • guest_libc_internal_facet_queries, guest_libc_internal_facet_put, guest_locale and public_headers still pass.
  • Negative controls: with the reference count's high half dropped, the test fails at "messages(refs) installs the exported vtable and the reference count only"; with the wide do_get copying narrow units, it fails at "get through the wide vtable copies the wide default". Both reverted.
  • python tools/check_conventions.py --base origin/main passes. tools/debt_fold.py --check passes once docs-nkwebkit-drop-readded-count-lines.md, which fails on main as well, is set aside.
  • tools/pr_overlap.py --names for the seven constructors: no open PR. --branch: no PR with the same exports. It reports neighbouring-line conflicts with #19767 and #21894 in InventoryExports6 and could not merge 13 conflicting PRs; I read the diffs of all of them, and none touches these constructors or a messages<wchar_t> vtable (#17300 only names the other, NID-only messages constructors).

Not tested: a console or a title.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5344856743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21904). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-11-16T20:48:57Z. --- ### What Implements the seven `std::messages` constructors that still threw: `messages<char>` `C1(const char*, size_t)`, `C1(const _Locinfo&, size_t)`, `C2(const _Locinfo&, size_t)` and `C2(size_t)`, and `messages<wchar_t>` `C1(const char*, size_t)`, `C1(const _Locinfo&, size_t)` and `C2(size_t)`. Each one writes the vtable pointer and the reference count into the 0x10-byte facet and nothing else. Both `messages::_Init` members are already a single `ret` from firmware 13.42 (the empty facet members debt entry), and Microsoft STL's `xlocmes` `messages` has no other members. - `messages<char>` gets the exported libc vtable `_ZTVSt8messagesIcE` (at slot 2), whose `do_open`, `do_get` and `do_close` are already wired. - No `messages<wchar_t>` vtable exists in the tree. The wide facet gets a vtable in libSceLibcInternal with the D1, D0, `_Incref` and `_Decref` slots and a `do_open`, `do_get` and `do_close` that behave as the exported `messages<wchar_t>` members do: `-1`, a copy of the default, nothing. - The constructors that take a locale name build and destroy a `_Locinfo` from it, so they accept the names `_Locinfo(const char*)` accepts. The other messages constructors (`C1(size_t)`, `C2(const char*, size_t)` and wide `C1(size_t)`, `C2(const char*, size_t)`, `C2(const _Locinfo&, size_t)`) are NID-only declarations, which #17300 names, so this PR leaves them alone. The debt fragment removes the seven stub entries and adds one that states what is not measured. `tools/progress.py --module libSceLibcInternal`: 522 done / 609 to do on `main` 9b60c84343f, 529 / 602 on this branch. ### 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 11, MinGW-w64 GCC 15.2, Release, `BUILD_TESTING=ON`, on `main` 9b60c84343f. - `guest_libc_internal_messages` (extended) passes. For every constructor it checks that the vptr is the exported `messages<char>` vtable or the wide one, that the 64-bit reference count lands at offset 8 (with `0x100000007` to catch a truncated count), and that the bytes after the 0x10-byte facet stay as they were. It then calls the existing `open`, `get` and `close` exports on the constructed facets: `open` returns -1 in both widths, and `get` through the wide vtable copies a 20-unit wide default onto the heap. A wide facet allocated with `operator new` is retained, released and deleted through its own vtable, and the test's allocation counter comes back to where it started. - `guest_libc_internal_facet_queries`, `guest_libc_internal_facet_put`, `guest_locale` and `public_headers` still pass. - Negative controls: with the reference count's high half dropped, the test fails at "messages<char>(refs) installs the exported vtable and the reference count only"; with the wide `do_get` copying narrow units, it fails at "get through the wide vtable copies the wide default". Both reverted. - `python tools/check_conventions.py --base origin/main` passes. `tools/debt_fold.py --check` passes once `docs-nkwebkit-drop-readded-count-lines.md`, which fails on `main` as well, is set aside. - `tools/pr_overlap.py --names` for the seven constructors: no open PR. `--branch`: no PR with the same exports. It reports neighbouring-line conflicts with #19767 and #21894 in `InventoryExports6` and could not merge 13 conflicting PRs; I read the diffs of all of them, and none touches these constructors or a `messages<wchar_t>` vtable (#17300 only names the other, NID-only messages constructors). Not tested: a console or a title. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
PrivacyOnion commented 2026-11-16 20:55:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T20:55:40Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_internal_messages_tests built cleanly.
  • CTest (guest_libc_internal_messages):
    1/1 Test #4109: guest_libc_internal_messages .....   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/InventoryExports6.cpp, core/libs/prx/libSceLibcInternal/include/Api.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp, core/libs/prx/libc/include/Api.hpp, core/libs/prx/libSceLibcInternal/Messages.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified messages and messages<wchar_t> constructor entry points against AGENTS.md rules and export inventory removals in InventoryExports6.cpp
    • Checked pointer validity handling in Construct, ConstructNamed, and ConstructFrom (ensuring nullptr self throws std::invalid_argument instead of segfaulting)
    • Verified wchar_t facet deletion, retain, and release lifetime management via std::atomic_ref with exact reference counter semantics
    • Checked LP64 vs LLP64 portability and 64-bit reference splitting across facet->references and facet->reserved fields
    • Verified debt fragment docs/dev/debt/changes/feat-libcinternal-messages-ctors.md matches the 7 replaced constructors and accurately describes implementation limits
    • Verified unit test coverage in GuestLibcInternalMessages.cpp exercising both character types, custom reference counts, open, get, and lifecycle hooks

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5927490502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21904#pullrequestreview-5927490502). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-16T20:55:40Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `1a2653604a`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libc_internal_messages_tests` built cleanly. - **CTest** (`guest_libc_internal_messages`): ``` 1/1 Test #4109: guest_libc_internal_messages ..... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/InventoryExports6.cpp`, `core/libs/prx/libSceLibcInternal/include/Api.hpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp`, `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libSceLibcInternal/Messages.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified messages<char> and messages<wchar_t> constructor entry points against AGENTS.md rules and export inventory removals in InventoryExports6.cpp - Checked pointer validity handling in Construct, ConstructNamed, and ConstructFrom (ensuring nullptr self throws std::invalid_argument instead of segfaulting) - Verified wchar_t facet deletion, retain, and release lifetime management via std::atomic_ref with exact reference counter semantics - Checked LP64 vs LLP64 portability and 64-bit reference splitting across facet->references and facet->reserved fields - Verified debt fragment docs/dev/debt/changes/feat-libcinternal-messages-ctors.md matches the 7 replaced constructors and accurately describes implementation limits - Verified unit test coverage in GuestLibcInternalMessages.cpp exercising both character types, custom reference counts, open, get, and lifecycle hooks 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!21904
No description provided.