Skip to content

feat(libSceLibcInternal): implement the messages facet members - #21170

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Herolias:feat/messages-facet
Nov 16, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Herolias:feat/messages-facet

Conversation

@Herolias

Copy link
Copy Markdown
Contributor

What

libSceLibcInternal's messages<char> and messages<wchar_t> get, open, close and do_get threw through NotImplemented_nid_no_patch, and libc's exported messages<char> vtable (_ZTVSt8messagesIcE, NID FnEnECMJGag, #10158) was nine zeroed slots, so a virtual call through a facet that uses it jumped to address 0. This change follows the Microsoft STL xlocmes for these.

  • get, open and close (NIDs XxsPrrWJ52I, U2t+WvMQj8A, EeBQ7253LkE; wide Ea+awuQ5Bm8, TPq0HfoACeI, GGoH7e6SZSY) call the facet's do_get, do_open and do_close through its vtable and return what they return. The new GuestLocale::MessagesVtable places them at 0x20, 0x28 and 0x30 past the vtable pointer, after the two destructors and _Incref/_Decref that every facet vtable here starts with; static_asserts pin the offsets. get returns a string by value, so it takes the result pointer first and the facet second, as the collate transform slot already does in GuestLocale.hpp.
  • do_get (NIDs vbgCuYKySLI, UM6rGQxnEMg) ignores the catalog, set and message and returns a copy of the default string. The copy follows basic_string's copy constructor (_Construct_lv_contents) on the 0x28-byte guest string:
    • a default of up to 15 characters (7 16-bit characters for wchar_t) copies the whole 16-byte buffer and records capacity 15 (7);
    • a longer one gets capacity size | 15 (size | 7) and capacity + 1 elements from the shared guest string allocator, with the terminator copied;
    • the default is read through its heap pointer when its capacity is 16 (8) or more, as _Myptr does, so a short string held on the heap is copied inline.
  • libc's messages<char> vtable now holds, in slots 2 to 8, the DestroyCollate, DeleteCollate, RetainFacet and ReleaseFacet functions the collate<char> vtable uses (c66f61f), then do_open returning -1, do_get making the copy above and do_close doing nothing. Offset-to-top and typeinfo stay zero, as for collate.
  • libSceLibcInternal reaches libc's copy through two bridges, LibcCopyString_nid_no_patch and LibcCopyWideString_nid_no_patch, next to the existing LibcAssignWideCString_nid_no_patch.
  • do_open returning -1 and do_close doing nothing agree with the firmware 13.42 reading behind 40c1005, which answers the existing do_open and do_close exports (NIDs HeBwePMtuFs, rRmMX83UL1E, zSehLdHI0FA, AjkxQBlsOOY). Those four are unchanged.

What still throws, and why:

  • A null facet, a facet without a vtable, or an empty slot in get, open or close throws std::invalid_argument without calling anything. The console would fault reading through the null pointer.
  • In do_get: a null result or default, a default whose capacity says heap but whose pointer is null, and a size above max_size() throw std::invalid_argument. max_size() is assumed to be SIZE_MAX - 1 (SIZE_MAX / 2 - 1 for wchar_t), as in the existing basic_string debt entry; the console's value was not read. A copy too large to allocate throws std::bad_alloc from the allocator.
  • messages<char>::_Getcat (NID 96Ev+CE1luE) and the messages constructors still throw; no available source settles their console layout. So nothing in this tree builds a messages facet yet; the wrappers run only on facets the title builds, with its own vtable or libc's.
  • No messages<wchar_t> vtable is exported, so the wide wrappers run only on a facet whose vtable the title supplies.

Debt: docs/dev/debt/changes/feat-messages-facet.md removes the eight "declaration is for import resolution only" entries, adds one Functional entry to libSceLibcInternal.md and changes the messages<char> vtable entry in libc.md. Each entry is under the 1000-character limit.

Overlap:

Not in this PR:

Tested

Fedora 44 x86-64, GCC 16.2.1, GNU ld 2.46.1, CMake 4.3.0, Ninja 1.13.2, Release with -DBUILD_TESTING=ON, on main at ff36fea. I ran no title, homebrew or console, because I have none. Nothing was built or run on Windows or macOS.

  • cmake --build build built the whole tree.
  • The selection from tools/select_tests.py (BUILD.md, "Selective test builds") was 5594 tests, because libc and libSceLibcInternal are linked into almost every test. 5591 passed and 3 failed: agc_driver_image_table_packed_guards, audio_out2_port_layouts and guest_http. All three fail the same way on main at 2454441, the previous base of this branch: I checked out main in the same tree, rebuilt their executables and ran each alone. The same three failed with this branch on that base. guest_http and audio_out2_port_layouts abort, and agc_driver_image_table_packed_guards logs "invalid format" image-table write-backs. 59 tests skipped themselves: 57 AGC and VideoOut tests, guest_environment_binding_unload and guest_net_raw_protocol. In an earlier run of the selection, two rebases back, guest_kernel_stack_protect also aborted once under -j 16. It passed when run alone and in the final run.
  • guest_libc_internal_messages (new):
    • each of the six get, open and close exports calls only its own slot of a recording vtable, passes the result, facet, catalog, set, message, default, name and locale through unchanged, and returns the slot's result;
    • a null facet, a facet without a vtable and an empty slot throw without calling any slot;
    • do_get for char and wchar_t:
      • short, full-inline and empty defaults copy the 16-byte buffer, tail bytes included, with capacity 15 or 7;
      • a short default held on the heap is copied inline from its heap buffer;
      • a default one past the inline capacity gets capacity size | 15 or size | 7;
      • an embedded NUL is copied with the size kept;
      • a large default (5000 characters, 3000 for wchar_t) gets aligned storage from the large-allocation path;
      • two different catalog, set and message triples give the same copy;
      • a null default, a null result and heap capacity with null storage throw;
    • the char wrappers on a facet whose vtable is libc's exported _ZTVSt8messagesIcE: open returns -1, get copies the default, close returns;
    • every allocation made by the test is freed.
  • guest_locale (extended): libc's messages<char> vtable has zero offset-to-top and typeinfo and non-null slots 2 to 8. It checks destroy, retain and release, open returning -1, close, a short and a long get (capacity length | 15, new storage, same bytes), a null default throwing, and the deleting destructor on a facet from operator new.
  • Negative controls: I made eight one-line changes to the code, rebuilt and ran the two tests, then restored the code. Each change made at least one test fail:
    • copying only size + 1 elements into the inline buffer;
    • not rounding the heap capacity;
    • an inline threshold one lower;
    • choosing the source buffer by size instead of capacity;
    • do_open returning 0;
    • an empty do_close slot;
    • get swapping set and message;
    • the wide do_get using the narrow layout.
  • tools/check_conventions.py --base origin/main reports "All conventions checks passed." With --title and --body set to this title and body, it also passes.
  • tools/debt_fold.py --check passes.
  • tools/pr_overlap.py --branch feat/messages-facet: see Overlap above.

Sources

Microsoft STL links are to 219514876ea86491de191ceaa88632616bbc0f19, the first public release, the pin the std::_MP_* entry in libSceLibcInternal.md already uses.

Behaviour Source
open, get and close call do_open, do_get and do_close and return their result stl/inc/xlocmes lines 38-49
do_open returns -1, do_get returns the default, do_close does nothing stl/inc/xlocmes lines 84-94; do_open and do_close also agree with the firmware 13.42 reading in 40c1005
The vtable order: destructors, then do_open, do_get, do_close, in declaration order stl/inc/xlocmes lines 79-94; the facet's _Incref/_Decref virtuals in stl/inc/xlocale lines 136-146; the first four slots as in the existing GuestLocale::FacetVtable and the collate<char> vtable (c66f61f)
Copy: a size below _BUF_SIZE copies _BUF_SIZE elements and sets capacity _BUF_SIZE - 1; otherwise capacity min(size | _ALLOC_MASK, max_size()), capacity + 1 elements allocated and size + 1 copied stl/inc/xstring lines 2461-2479
_BUF_SIZE 16 / 8 and _ALLOC_MASK 15 / 7 for 1- and 2-byte elements stl/inc/xstring lines 2040-2046
The source is the heap pointer when capacity is at least _BUF_SIZE stl/inc/xstring lines 2047-2066 (_Myptr, _Large_string_engaged)
The 0x28-byte guest string and its allocator GuestLocale::String in core/libs/prx/libc/include/GuestLocale.hpp; GuestStringStorage::Allocate in core/libs/prx/libc/GuestStringStorage.hpp
The vtable is 72 bytes (st_size) in the libc.prx bundled with PPSA26344 #10158

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

messages<char> and messages<wchar_t> open, get and close call the
facet's do_open, do_get and do_close through its vtable, and do_get
returns a copy of the default string, as the Microsoft STL xlocmes does.
The copy follows basic_string's _Construct_lv_contents on the guest
string. libc's exported messages<char> vtable now holds the destructors,
_Incref/_Decref and do_open (-1), do_get and do_close, as for collate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libc_internal_messages_tests, guest_locale_tests built cleanly.
  • CTest (guest_locale, guest_libc_internal_messages):
    1/2 Test #1324: guest_locale .....................   Passed    0.03 sec
    2/2 Test #4002: guest_libc_internal_messages .....   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceLibcInternal/Export.cpp, core/libs/prx/libSceLibcInternal/include/Api.hpp, core/libs/prx/libSceLibcInternal/include/PendingExports.hpp, core/libs/prx/libc/include/GuestLocale.hpp, core/libs/prx/libc/src/LocaleSupport.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified MessagesVtable layout and static_asserts in core/libs/prx/libc/include/GuestLocale.hpp (open at 0x20, get at 0x28, close at 0x30, sizeof == 0x38) and _ZTVSt8messagesIcE_nid_postfix population in core/libs/prx/libc/src/LocaleSupport.cpp.
    • Checked MessagesSlot null facet, null vtable, and null slot validation in core/libs/prx/libSceLibcInternal/Export.cpp for char and wchar_t messages::get, open, and close exports.
    • Verified CopyStringUnits in core/libs/prx/libc/src/LocaleSupport.cpp for null pointer checks, maxSize bounds, inline vs heap storage selection, SSO 16-byte buffer copy, and heap allocation with (capacity + 1) * unit and (size + 1) * unit copy.
    • Checked ABI signatures, return types, and parameter ordering across PendingExports.hpp, Api.hpp, Export.cpp, and GuestLocale.hpp, as well as LP64/LLP64 type safety.
    • Confirmed AGENTS.md compliance, technical debt fragment documentation in docs/dev/debt/changes/feat-messages-facet.md, and CTest/convention gate results.

Looks Good To Me

@github-actions

Copy link
Copy Markdown

Progress report (ff36fea → 0bd0598)

📈 System libraries: 41.45% (+0.03%, +11 implemented functions)

✅ 11 implemented
Library Name
libSceLibcInternal _ZNKSt8messagesIcE3getEiiiRKSs_nid_postfix
libSceLibcInternal _ZNKSt8messagesIcE4openERKSsRKSt6locale_nid_postfix
libSceLibcInternal sceLibcInternalPending4_005_nid_no_patch
libSceLibcInternal sceLibcInternalPending4_006_nid_no_patch
libSceLibcInternal sceLibcInternalPending4_009_nid_no_patch
libSceLibcInternal sceLibcInternalPending4_010_nid_no_patch
libSceLibcInternal sceLibcInternalPending4_011_nid_no_patch
libSceLibcInternal sceLibcInternalPending4_012_nid_no_patch
libc MessagesClose
libc MessagesGet
libc MessagesOpen
⚪ 2 behaviourally empty (constant return or throw)
Library Name
libc MessagesClose
libc MessagesOpen

Changed libraries (implemented exports)

Library Before After Change
libc 1786/1793 (99.61%) 1789/1796 (99.61%) +0.0007%
libSceLibcInternal 500/1131 (44.21%) 508/1131 (44.92%) +0.71%

@oneandonlydean
oneandonlydean merged commit ac29a0c into boykopovar:main Nov 16, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants