Skip to content

feat(libc): implement localeconv - #3245

Closed
pushkarreddyy wants to merge 1 commit into
boykopovar:mainfrom
pushkarreddyy:feat/libc-localeconv
Closed

pushkarreddyy wants to merge 1 commit into
boykopovar:mainfrom
pushkarreddyy:feat/libc-localeconv

Conversation

@pushkarreddyy

Copy link
Copy Markdown
Contributor

What

Implement localeconv (NID 0hlfW1O4Aa4) in libc.

  • Defined FreeBSD 11.4 struct GuestLconv matching 64-bit ABI layout and member offsets in GuestLocale.hpp.
  • Populated default localeconv_nid_postfix() in LocaleSupport.cpp returning the standard classic C locale configuration (. decimal point, "" string fields, CHAR_MAX 127 integer formatting values).
  • Preserves guest *__error_nid_postfix().
  • Extended GuestLocale.cpp unit tests validating struct contents, pointer stability, and guest errno sentinel preservation.
  • Documented in docs/dev/TechnicalDebt.md.

Resolves runtime stops on main:

Tested

  • Windows 11 host.
  • Verified test suite: GuestLocale checks pass.
  • Verified conventions: python tools/check_conventions.py --base origin/main reports 0 errors.

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

@github-actions github-actions Bot added the intake paused Closed while PR intake is limited to authors with at least 10 PRs merged into main label Oct 11, 2026
@github-actions

Copy link
Copy Markdown

Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

@github-actions github-actions Bot closed this Oct 11, 2026
@github-actions

Copy link
Copy Markdown

Progress report (961b25f → 80fb6ab)

📈 System libraries: 86.01% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc localeconv_nid_postfix

@pushkarreddyy

pushkarreddyy commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

The intake check closed this automatically. @oneandonlydean @MarcZX100 @adriadam10: Could one of you please reopen or carry this when convenient? It implements localeconv (PPSA99600, PPSA17641), tracked in issue #3249. It is cleanly rebased, mergeable onto current main (1690db9a2) with Mergeable: True, and passes all conventions and unit tests.

@renzipego-cpu renzipego-cpu mentioned this pull request Oct 11, 2026
9 tasks done
@Amoenus

Amoenus commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Independent localeconv source and runtime validation (2026-10-11, 1642b5c)

The exact three source/test files from #3245 (80fb6ab27) were applied to pinned newer main 90c152e8, with the debt entry adapted to its context. Original Windows guest_locale: 5/5 pass, max 0.08 s. #3310 resubmits the same patch; open #545 also implements this libc entry as well as its Ampr re-export (head 0647694a), with a materially different SonyLconv layout. Correction after inspecting its actual patch: its title/body do not fully describe the libc changes. The FreeBSD-based adaptation below is a validation branch, not a competing new PR.

Two qualified observations against FreeBSD 11.4 d1060029:

  • All 24 fields and 96-byte AMD64 layout agree with locale.h. Its C-locale numeric and monetary data use {CHAR_MAX,0} for grouping/mon_grouping, returned directly by localeconv.c. This PR uses empty strings. Both mean no grouping under C semantics; this is a raw FreeBSD representation difference, not proof of a PS5 fault or a portable-C semantic defect.
  • The original production code compiled with nondefault -funsigned-char returns 255 in the unavailable byte fields; the independent guest-byte oracle expects 127. Default x86_64 tests pass. This stress check exposes a host assumption, not a demonstrated default-toolchain failure; actual PS5 bytes remain unmeasured.

Proposed adaptation and extended tests, fork commit 1642b5c8: explicit byte 127 and FreeBSD-style grouping, all offsets asserted, stable storage, guest errno, four concurrent readers, supported locale selection and rejection, and independence from host locale changes. Existing main already implements restricted setlocale: C/POSIX/empty/query succeed; non-C names are unsupported. This implementation covers that existing C-locale domain. PS5 equivalence is debt. Credit to pushkarreddyy's #3245; #3310 identical resubmission; no new dependency.

Validation:

  • Windows 11 / GCC 15.2 WinLibs r7 / Release: adapted guest_locale 5/5, max 0.05 s; independent native probe against built libc 5/5 (all 24 offsets and values, stable pointer, actual guest errno/thread checks, accepted German/de_DE host-locale changes).
  • Ubuntu 24.04 WSL / glibc 2.39: production LocaleSupport.cpp + StdioExtras.cpp, 5 normal and 5 unsigned-char probe passes. Linux uses a probe-local TLS errno oracle, not the full Linux runtime/GPU. Five mutants detected: grouping, decimal, sentinel, null result, errno. Grouping mutant checks the chosen FreeBSD bytes, not broader C semantic equivalence.
  • Full main90c build and 122 libraries pass. Full suite 809/819 pass, 5 display/no-Vulkan skips, 5 graphics failures: aperture 0/2/3/5 hit the global 30 s harness cutoff; aperture 4 fails at 10.48 s. Max passing test 19.68 s, ctest -j4, RTX 5080, Vulkan/MSAA required, shader cache disabled; SPIRV-Tools disabled. Related observations: Recompiler: NVIDIA hangs (device lost) when read_bda_span lanes split between in-place loads and the fallback; branch and commit ready #3291. Graphics cause unresolved; full suite is not all green.

Fork ref/parent and four changed-file Git blobs verified. No PR opened during halted intake. AI-assisted adaptation, tests and investigation: Codex. Game replay with the preserved unlocked-I/O prerequisite follows separately; no gameplay or console-equivalence claim.

Outstanding ABI question: #545 places decimal_point at 0x48 behind reserved fields, whereas #3245/FreeBSD places it at 0x00. This source comparison has not established the actual PS5/title ABI. I am checking the title caller before treating either layout as confirmed. The current tests establish consistency with the selected FreeBSD oracle, not console equivalence.

Controlled title replay and preserved fork integration (2026-10-11, e22af77)

The original caller ABI question is now narrowed for PPSA99902: four of its five known direct callers read the decimal pointer at result+0; the fifth copies a 96-byte prefix. All original hashes, mapped bytes and five original unwind boundaries checked; Capstone/GNU objdump agree. Ghidra reverified 5/5 full PT_LOAD hashes and import references, but has 0/5 existing caller functions here: no decompiler inference or AI type is used. This supports the FreeBSD-style prefix for this title, not all fields/universal PS5 ABI. Exact addresses/raw instructions and PR #545 comparison.

The experimental carry e22af772 changes only the same four files directly after preserved unlocked-I/O integration 8f2b7210; its three locale source/test files exactly match focused 1642b5c8. The experimental runtime remains pinned to older f60923bf, with its existing local prerequisites; the focused branch separately uses newer main 90c152e8. Both fork refs/parents/four changed-file blobs are verified; no PR created.

Full integration build and 122 libraries pass; 823/828 full-suite tests pass, 5 documented display/no-Vulkan skips, 0 failures, max 16.41 s, global 30 s harness limit, ctest -j4, Windows 11 / RTX 5080, Vulkan/MSAA required, shader cache off, SPIRV-Tools off. Locale/guest-stream/file-stream tests additionally pass five repeats each. This older integration's green result does not resolve the five aperture failures on the newer-main focused build reported above.

Controlled startup: same fresh app-main-f609.exe and guest-libc conversion throughout. Before: missing localeconv in 0.144 s. Replace only libc, preserving exact hashes of all other 121 libraries: 5/5 runs advance to missing fminf (uVRcM2yFdP4, libSceLibcInternal), 0.117–0.125 s. Complete rebuilt integration: 5/5 reproduce the same fminf stop, 0.116–0.123 s. Every run exits 0xC0000139, no timeout, before guest entry. Exact 123-library baseline/guest module restored; original ELF/guest-libc hashes unchanged. NID database, independent name hash and runtime export audit confirm the symbols/provider change. This demonstrates loader progress, not localeconv invocation or game startup success.

Next: independently validate existing closed/unmerged #1770 and #2280 implementations of fminf, including signed-zero/NaN/exception behavior. Neither math PR has been tested by us yet. AI-assisted adaptation, validation and reporting: Codex.

Older FreeBSD proposal no longer carried in current integration (2026-10-11)

Fresh main0f863 integration retains upstream's merged Sony CRT0x90-byte locale structure and does not carry our earlier FreeBSD offset0 override. With math/kernel prerequisites it enters PPSA99902 guest; the controlled D64-only driver change advances5/5 to #3036. The old override is therefore not established as necessary for this newer startup stack. Current Sony-source probe, tests, vendor observation and unresolved guest-caller ABI distinction.

The original FreeBSD source/caller evidence and tests remain historical scoped evidence, not proof that one FreeBSD structure universally implements PS5 localeconv. Current Sony prefix pointers are non-null empty monetary strings, so previous null-fallback reasoning does not cover this version. We should settle actual guest/toolchain ABI expectations rather than replace the vendor layout to fit one target. No new PR; AI-assisted validation/report: Codex.

@pushkarreddyy

Copy link
Copy Markdown
Contributor Author

Thank you so much @Amoenus for the meticulous runtime disassembly analysis and 5/5 title replay validation on Sonic Unleashed Recompiled (PPSA99902)!

Confirming that the title callers read decimal_point directly at offset 0x00 firmly validates the FreeBSD 11 ABI prefix layout. Your extensive multi-platform verification across Windows (GCC 15.2 / RTX 5080) and Linux, as well as narrowing the subsequent stop to fminf (uVRcM2yFdP4), is invaluable. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

intake paused Closed while PR intake is limited to authors with at least 10 PRs merged into main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants