feat(libSceLibcInternal): implement UTF codecvt metadata and unshift #19593

Merged
fogydes merged 1 commit from upstream-pr/19593 into main 2026-11-13 20:09:23 +00:00
fogydes commented 2026-11-13 15:30:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-11-13T15:30:52Z.


What

Implement five unversioned UTF codecvt metadata/unshift exports that previously threw. The char32 unshift writes next=first and returns ok without reading the facet/state. Char16 unshift writes next=first before reading the state's low 16 bits, returning error for values above 1. Metadata queries use the caller's mode at offset 0x18: char32 encoding is -1 for either header flag and 0 otherwise; char32 max length is 9 or 6; char16 max length is 9 for consume-header, 7 for generate-header, otherwise 6. Unrelated mode bits are ignored.

Clean-room source: readable libc.prx, SDK 10.00, char32 unshift 0xb31b0, encoding 0xb2e40, max length 0xb2e30; char16 unshift 0xb2cf0, max length 0xb27d0, cross-checked with SDK target/include/xlocale. Raw access widths are preserved: char32 mode one byte, char16 mode four bytes, state two bytes. No reference binaries/extracts are attached or linked; no console measurement is claimed.

Unusable output/state/mode memory and address overflow throw as documented host-safety behavior. A completed next-pointer write remains visible if the subsequent char16 state read fails. Full conversion/facet construction and later-firmware equivalence remain unverified.

Coverage measured with tools/progress.py: 424 -> 429 implemented / 706 -> 701 TODO / 1130 total. The five NIDs already existed as throwing exports; selected presence gap is unchanged (0 missing / 5 provided / 0 unknown).

Based on main snapshot 228330220ba. Required pr_overlap.py inspected 1514 open heads and exited 2 with six stale comparisons. All eight reported heads were manually checked: no competing behavior or dependency. #17300 renames four matching throwing stubs; the fifth also still throws. #13782/#19434 have independent umbrella-include insertion conflicts; preserve both headers. The checker used later main c612c4c9e890; copy/type providers are unchanged, while GuestHeap changed singleton lifetime (these wrappers do not allocate through it). Stale whole-branch merges are not claimed clean.

Tested

  • Windows x64 WinLibs MinGW/GCC 15.2 Release, full runtime configuration: affected libc/libkernel/libSceLibcInternal and guest targets built on D. ctest -R '^guest_(codecvt_utf_metadata|libc_internal_codecvt_char)$' --output-on-failure passed 2/2 on final head 47d5044a0eef.
  • Tests cover all mode-bit combinations and unrelated high bits; state 0/1/2/65535; ignored arguments; exact return signatures; aliasing/output-before-state behavior; readonly/unmapped buffers and page boundaries proving one/four/two-byte access widths.
  • Public headers: 413 libraries / 34522 exports, unique/reachable declarations passed. All five NIDs verified in a freshly patched PE copy: c6Lyc6xOp4o, DDnr3lDwW8I, E5NdzqEmWuY, RYTHR81Y-Mc, BvRS0cGTd6I.
  • Final conventions and git diff checks passed. Automated overlap limitations are disclosed above.
  • No Linux, console/commercial-title, GPU 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:5298241262 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19593). Originally posted by [fogydes](https://github.com/fogydes) on 2026-11-13T15:30:52Z. --- ### What Implement five unversioned UTF codecvt metadata/unshift exports that previously threw. The char32 unshift writes next=first and returns ok without reading the facet/state. Char16 unshift writes next=first before reading the state's low 16 bits, returning error for values above 1. Metadata queries use the caller's mode at offset 0x18: char32 encoding is -1 for either header flag and 0 otherwise; char32 max length is 9 or 6; char16 max length is 9 for consume-header, 7 for generate-header, otherwise 6. Unrelated mode bits are ignored. Clean-room source: readable `libc.prx`, SDK 10.00, char32 unshift `0xb31b0`, encoding `0xb2e40`, max length `0xb2e30`; char16 unshift `0xb2cf0`, max length `0xb27d0`, cross-checked with SDK `target/include/xlocale`. Raw access widths are preserved: char32 mode one byte, char16 mode four bytes, state two bytes. No reference binaries/extracts are attached or linked; no console measurement is claimed. Unusable output/state/mode memory and address overflow throw as documented host-safety behavior. A completed next-pointer write remains visible if the subsequent char16 state read fails. Full conversion/facet construction and later-firmware equivalence remain unverified. Coverage measured with tools/progress.py: **424 -> 429 implemented / 706 -> 701 TODO / 1130 total**. The five NIDs already existed as throwing exports; selected presence gap is unchanged (0 missing / 5 provided / 0 unknown). Based on main snapshot `228330220ba`. Required pr_overlap.py inspected 1514 open heads and exited 2 with six stale comparisons. All eight reported heads were manually checked: no competing behavior or dependency. #17300 renames four matching throwing stubs; the fifth also still throws. #13782/#19434 have independent umbrella-include insertion conflicts; preserve both headers. The checker used later main `c612c4c9e890`; copy/type providers are unchanged, while GuestHeap changed singleton lifetime (these wrappers do not allocate through it). Stale whole-branch merges are not claimed clean. ### 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 x64 WinLibs MinGW/GCC 15.2 Release, full runtime configuration: affected libc/libkernel/libSceLibcInternal and guest targets built on D. `ctest -R '^guest_(codecvt_utf_metadata|libc_internal_codecvt_char)$' --output-on-failure` passed **2/2** on final head `47d5044a0eef`. - Tests cover all mode-bit combinations and unrelated high bits; state 0/1/2/65535; ignored arguments; exact return signatures; aliasing/output-before-state behavior; readonly/unmapped buffers and page boundaries proving one/four/two-byte access widths. - Public headers: **413 libraries / 34522 exports**, unique/reachable declarations passed. All five NIDs verified in a freshly patched PE copy: c6Lyc6xOp4o, DDnr3lDwW8I, E5NdzqEmWuY, RYTHR81Y-Mc, BvRS0cGTd6I. - Final conventions and git diff checks passed. Automated overlap limitations are disclosed above. - No Linux, console/commercial-title, GPU 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
PrivacyOnion commented 2026-11-13 19:30:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T19:30:22Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_codecvt_utf_metadata_tests built cleanly.
  • CTest (guest_codecvt_utf_metadata):
    1/1 Test #3699: guest_codecvt_utf_metadata .......   Passed    0.34 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/Err.cpp, core/libs/prx/libSceLibcInternal/include/ErrExports.hpp, core/libs/prx/libSceLibcInternal/libSceLibcInternal.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • CodecvtUtfMetadata.cpp: Verified _ZNKSt7codecvtIDic9_MbstatetE10do_unshiftERS0_PcS3_RS3__nid_postfix and _ZNKSt7codecvtIDsc9_MbstatetE10do_unshiftERS0_PcS3_RS3__nid_postfix write first to *next using GuestCopyOut_nid_no_patch while preserving errno and returning codecvt_base::ok (0) or codecvt_base::error (2 for pending > 1).
    • CodecvtUtfMetadata.cpp: Verified ReadMode_nid_no_patch guards against pointer overflow (address > max - ModeOffset) before accessing offset 0x18, preserving errno and raising std::invalid_argument on unreadable memory.
    • CodecvtUtfMetadata.cpp: Verified memory access widths match SDK 10.00 libc.prx: 1 byte (uint8_t) for char32 encoding/max_length queries, 4 bytes (uint32_t) for char16 max_length, and 2 bytes (uint16_t) for char16 shift state.
    • CodecvtUtfMetadata.cpp: Verified metadata return mappings across all bit combinations of GenerateHeader (2) and ConsumeHeader (4): char32 encoding returns -1 with header flags and 0 without; char32 max length returns 9 with header flags and 6 without; char16 max length prioritizes ConsumeHeader (9) over GenerateHeader (7), defaulting to 6.
    • GuestCodecvtUtfMetadata.cpp: Verified tests cover all 8 mode bit masks, state values (0, 1, 2, 65535), state/next buffer aliasing, output writes before state failure, and page-boundary memory protection on both Linux and Windows.
    • CodecvtUtfMetadata.cpp, CodecvtUtfMetadata.hpp, GuestCodecvtUtfMetadata.cpp, and docs/dev/debt/libSceLibcInternal.md: Verified complete compliance with AGENTS.md rules, confirming zero comments in code, valid NID removals from Err.cpp, and proper gap documentation.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5896860944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19593#pullrequestreview-5896860944). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T19:30:22Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `47d5044a0e`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_codecvt_utf_metadata_tests` built cleanly. - **CTest** (`guest_codecvt_utf_metadata`): ``` 1/1 Test #3699: guest_codecvt_utf_metadata ....... Passed 0.34 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/Err.cpp`, `core/libs/prx/libSceLibcInternal/include/ErrExports.hpp`, `core/libs/prx/libSceLibcInternal/libSceLibcInternal.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - CodecvtUtfMetadata.cpp: Verified _ZNKSt7codecvtIDic9_MbstatetE10do_unshiftERS0_PcS3_RS3__nid_postfix and _ZNKSt7codecvtIDsc9_MbstatetE10do_unshiftERS0_PcS3_RS3__nid_postfix write first to *next using GuestCopyOut_nid_no_patch while preserving errno and returning codecvt_base::ok (0) or codecvt_base::error (2 for pending > 1). - CodecvtUtfMetadata.cpp: Verified ReadMode_nid_no_patch guards against pointer overflow (address > max - ModeOffset) before accessing offset 0x18, preserving errno and raising std::invalid_argument on unreadable memory. - CodecvtUtfMetadata.cpp: Verified memory access widths match SDK 10.00 libc.prx: 1 byte (uint8_t) for char32 encoding/max_length queries, 4 bytes (uint32_t) for char16 max_length, and 2 bytes (uint16_t) for char16 shift state. - CodecvtUtfMetadata.cpp: Verified metadata return mappings across all bit combinations of GenerateHeader (2) and ConsumeHeader (4): char32 encoding returns -1 with header flags and 0 without; char32 max length returns 9 with header flags and 6 without; char16 max length prioritizes ConsumeHeader (9) over GenerateHeader (7), defaulting to 6. - GuestCodecvtUtfMetadata.cpp: Verified tests cover all 8 mode bit masks, state values (0, 1, 2, 65535), state/next buffer aliasing, output writes before state failure, and page-boundary memory protection on both Linux and Windows. - CodecvtUtfMetadata.cpp, CodecvtUtfMetadata.hpp, GuestCodecvtUtfMetadata.cpp, and docs/dev/debt/libSceLibcInternal.md: Verified complete compliance with AGENTS.md rules, confirming zero comments in code, valid NID removals from Err.cpp, and proper gap documentation. 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!19593
No description provided.