feat(libc): export the C rune locale #1781

Merged
babyhuey merged 1 commit from upstream-pr/1781 into main 2026-10-10 06:18:43 +00:00
babyhuey commented 2026-10-08 19:04:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T19:04:45Z.


What

Exports the FreeBSD C rune locale from libc: _DefaultRuneLocale (lWGF8NHv880), _CurrentRuneLocale (chlN6g6UbGo) and __mb_sb_limit (fGYLBr2COwA). Titles built against FreeBSD <ctype.h>/<wctype.h> read _CurrentRuneLocale->__runetype[c] inline, bounded by __mb_sb_limit, and fall back to &_DefaultRuneLocale; they import these as libSceLibcInternal data.

  • _RuneLocale follows FreeBSD 11 include/runetype.h, checked with static_asserts: __runetype at 64, __maplower at 2112, __mapupper at 3136, ranges at 4160, 4224 bytes.
  • The C table is generated, not copied. It matches FreeBSD 11 lib/libc/locale/table.c for all 256 __runetype, __maplower and __mapupper entries (compared offline against a parse of that file): ASCII classes, the digit value in the low byte of digits and hex letters, no class above 0x7f, magic RuneMagi, encoding NONE, __invalid_rune 0xFFFD, empty _ext ranges.
  • _CurrentRuneLocale points at _DefaultRuneLocale, and __mb_sb_limit is 256, as in FreeBSD table.c and none.c for the C locale, the only locale setlocale accepts.

Found with tools/import_audit.py on the catalog homebrew titles: _DefaultRuneLocale is absent in 11 of 36 audited titles, _CurrentRuneLocale and __mb_sb_limit in 9.

Tested

Linux (Ubuntu 24.04, GCC 13, Release): new guest_rune_locale and existing guest_locale pass with --repeat until-fail:3. The test reads the export at raw FreeBSD offsets and checks every entry against the existing is*, tolower and toupper exports, the digit values, the header fields and __mb_sb_limit. It fails when the _CTYPE_N bit is dropped from digits. check_conventions.py passes. Windows: both files compile with MinGW-w64 GCC 13 (-Wall -Wextra -fsyntax-only); not run on Windows.

import_audit.py with the patched libraries, absent imports before → after: PPSA19111 66 → 63, PPSA59322 ccleste 50 → 47, PPSA68091 Ruffle 71 → 68, PPSA97510 74 → 71, PPSA98510 74 → 71, PPSA99002 74 → 71, PPSA99010 vkQuake 51 → 48, PPSA99764 80 → 77, PPSA99810 64 → 61. No title run.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791530755 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1781). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T19:04:45Z. --- ### What Exports the FreeBSD C rune locale from libc: `_DefaultRuneLocale` (`lWGF8NHv880`), `_CurrentRuneLocale` (`chlN6g6UbGo`) and `__mb_sb_limit` (`fGYLBr2COwA`). Titles built against FreeBSD `<ctype.h>`/`<wctype.h>` read `_CurrentRuneLocale->__runetype[c]` inline, bounded by `__mb_sb_limit`, and fall back to `&_DefaultRuneLocale`; they import these as `libSceLibcInternal` data. - `_RuneLocale` follows FreeBSD 11 `include/runetype.h`, checked with `static_assert`s: `__runetype` at 64, `__maplower` at 2112, `__mapupper` at 3136, ranges at 4160, 4224 bytes. - The C table is generated, not copied. It matches FreeBSD 11 `lib/libc/locale/table.c` for all 256 `__runetype`, `__maplower` and `__mapupper` entries (compared offline against a parse of that file): ASCII classes, the digit value in the low byte of digits and hex letters, no class above 0x7f, magic `RuneMagi`, encoding `NONE`, `__invalid_rune` 0xFFFD, empty `_ext` ranges. - `_CurrentRuneLocale` points at `_DefaultRuneLocale`, and `__mb_sb_limit` is 256, as in FreeBSD `table.c` and `none.c` for the C locale, the only locale `setlocale` accepts. Found with `tools/import_audit.py` on the catalog homebrew titles: `_DefaultRuneLocale` is absent in 11 of 36 audited titles, `_CurrentRuneLocale` and `__mb_sb_limit` in 9. ### Tested Linux (Ubuntu 24.04, GCC 13, Release): new `guest_rune_locale` and existing `guest_locale` pass with `--repeat until-fail:3`. The test reads the export at raw FreeBSD offsets and checks every entry against the existing `is*`, `tolower` and `toupper` exports, the digit values, the header fields and `__mb_sb_limit`. It fails when the `_CTYPE_N` bit is dropped from digits. `check_conventions.py` passes. Windows: both files compile with MinGW-w64 GCC 13 (`-Wall -Wextra -fsyntax-only`); not run on Windows. `import_audit.py` with the patched libraries, absent imports before → after: PPSA19111 66 → 63, PPSA59322 ccleste 50 → 47, PPSA68091 Ruffle 71 → 68, PPSA97510 74 → 71, PPSA98510 74 → 71, PPSA99002 74 → 71, PPSA99010 vkQuake 51 → 48, PPSA99764 80 → 77, PPSA99810 64 → 61. No title run. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
popcoder565 commented 2026-10-09 15:45:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:45:59Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 8aa4040b, merged onto main d70b8998 in one build with 38 other PRs that had no Windows run.

  • This PR's tests pass: guest_rune_locale. None of them reported skipping a case.
  • Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084264690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1781#issuecomment-6084264690). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:45:59Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `8aa4040b`, merged onto `main` d70b8998 in one build with 38 other PRs that had no Windows run. - This PR's tests pass: `guest_rune_locale`. None of them reported skipping a case. - Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-10 06:18:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:18:38Z.


Checked the NIDs against aerolib, the _CTYPE_* bits and digit/hex values against FreeBSD runetype.h, and the layout asserts. guest_rune_locale passes on Linux and fails to link without the change; popcoder565 also ran it on Windows. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094582290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1781#issuecomment-6094582290). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:18:38Z. --- Checked the NIDs against aerolib, the `_CTYPE_*` bits and digit/hex values against FreeBSD `runetype.h`, and the layout asserts. `guest_rune_locale` passes on Linux and fails to link without the change; popcoder565 also ran it on Windows. Merging.
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!1781
No description provided.