fix(libc): match shipped CRT ABI and constraint behavior #8711
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8711"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ivica00 on 2026-10-20T21:50:14Z.
What
Match the shipped CRT contracts for
_Thrd_id,strtok_s,asctime_sandctime_s, including the AMPR wrappers that share the bounded-string helpers. This corrects ABI and constraint behavior rather than adding title-specific fallbacks._Thrd_idreturns the fullscePthreadSelfhandle. Register a self callback alongside the existing create/join callbacks to preserve libc/kernel dependency direction; missing registration throws. The shipped export (NIDnp6xXcXEnXE, ELF VA0x4c70) calls PLT0xcab10, whose relocation namesscePthreadSelf(aI+OeCz8xrQ), and returns RAX unchanged.strtok_s(NID-vXEQdRADLI, VA0x71590) has four arguments: source, remaining-size pointer, delimiters, context pointer. Preserve its bounded scan, remaining-count/context updates, delimiter writes and error precedence, including the distinctbad argument,missing tokenandmissing delimitercallbacks.asctime_s(qPe7-h5Jnuc, VA0x71b30) andctime_s(2UFh+YKfuzk, VA0x71be0) reject zero or >=2^61 destination sizes without writing, and clear a valid destination on subsequent argument failure. Match observed field ranges and callback diagnostics, withEINVAL, null callback pointer argument and guest calling convention. Boundary years format as four digits.Evidence: REA
[email protected]with Ghidra 12.1.4 and JDK 21, using small PE wrappers containing unchanged code slices from the title's unwrapped libc. ELF symbols, relocations and raw instructions establish the ABI; inferred PE calling conventions do not. Unwrapped libc SHA-256:0e0a628ad9a635ab7b13a3516cf13be092e34cafb84929a7a66740347273da3e. Code-slice SHA-256: thread55b1bc8f5b303027829a07250e2fd18a97c65591fa4bfc771887084e0317f1fa, date/tokenizer page18b3cb29afc2971d652e1c7bde6c3bbf09fdb906c4eae73a19e701196da91957.The earlier local shared-handler-state refactor is excluded because #7081 addresses it. This PR preserves current main's handler storage and does not duplicate #7841's bounds-function additions or #7952's wcscpy_s work. Remaining locale/timezone, cross-SDK and console-verification limits are recorded in libc technical debt. No proprietary binaries or generated investigation files are committed.
Overlap review: #8636 implements
_Thrd_detachand explicitly leaves_Thrd_idas a throwing stub; our binary evidence resolves the width question it records. Its callback registration additions occupy adjacent lines, so this PR is a draft with #8636 listed for merge-order coordination, not a duplicate implementation. The intended order is #8636 first, then rebase these self-callback additions; no detach code is copied here. Maintainer/author agreement on that order is still pending.Manually reviewed every incomparable shared-file diff from the overlap tool: #1835/#5021/#7201 change timed waits or numeric conversion, #6879 changes wcstof, #6044 moves tests, #7081 changes shared handler/locale state, and #7648 changes errno/thread launch plumbing. Remaining shared debt-file edits in #6226, #6469, #6819, #7473, #7715, #8150 and #8520 concern unrelated entries. #7081 will need mechanical reconciliation if it lands later, but its shared-state implementation is excluded here. No other inspected PR implements the tokenizer/date contracts or
_Thrd_idfix proposed here.Tested
Windows 10 (10.0.19045), AMD Ryzen 5 7600, MinGW GCC 15.2.0, Release full-library configuration with dependencies built from source. Built the relevant library and test targets;
guest_crt,guest_ampr_threads,guest_libc_threads,guest_strings,guest_time_conversion,guest_strftimeandguest_wide_conversionpassed (7/7).The tokenizer also passed 128,253 original-versus-implementation calls across 50,000 deterministic randomized sequences. A local harness mapped only the shipped ELF's isolated tokenizer/helpers, intercepted its constraint callback, and compared return offsets, remaining counts, context offsets, complete buffers and callback count/message/pointer/error against this branch's built libc. No game initialization was invoked. The harness and proprietary input remain outside the repository.
Focused tests exercise both libc and AMPR wrappers, every date-field boundary, invalid destination sizes and write behavior, tokenizer constraints/continuations/high-byte delimiters, and stable distinct full-pointer thread identities on the main thread plus four simultaneous guest threads.
check_conventions.py --base upstream/mainpasses. The required--base origin/mainwas attempted but encounters WinError 206 because the fork's old main produces a large unrelated upstream export delta; the actual upstream PR base passes. No checker source was altered.The game, Linux runtime and retail console were not run. The isolated tokenizer comparison is direct binary execution; thread/date findings are disassembly plus host regression tests. No speed or FPS claim is made.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T21:50:55Z.
Progress report (
bcdb033→0705e28)📈 System libraries: 64.51% (+0.01%, +1 implemented functions)
✅ 1 implemented
_Thrd_id_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T22:00:27Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libc/src/Threads.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/Strings.cppcore/libs/prx/libc/src/Threads.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/tests/GuestAmprThreads.cppcore/libs/tests/GuestCrt.cppcore/libs/prx/libc/src/Threads.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/Strings.cppdocs/dev/debt/libc.mdcore/libs/prx/libSceAmpr/Export.cppcore/libs/prx/libc/include/SonyCrt.hppcore/libs/tests/GuestCrt.cppdocs/dev/debt/libc.mdcore/libs/prx/libkernel/Pthread/Posix/Thread.cppcore/libs/prx/libc/src/Strings.cppcore/libs/prx/libc/src/Threads.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libSceAmpr/Export.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libkernel/Pthread/Posix/Thread.cppcore/libs/prx/libc/include/SonyCrt.hppdocs/dev/debt/libc.mdcore/libs/prx/libc/src/Strings.cppcore/libs/prx/libkernel/Pthread/Posix/Thread.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/Threads.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/Strings.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/include/General.hppcore/libs/prx/libc/src/Strings.cppcore/libs/tests/GuestAmprThreads.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/include/General.hppcore/libs/prx/libc/src/Threads.cppcore/libs/prx/libkernel/Pthread/Posix/Thread.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/src/Strings.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/include/General.hppdocs/dev/debt/libc.mdcore/libs/prx/libSceAmpr/Export.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/include/General.hppcore/libs/prx/libc/src/Threads.cppcore/libs/prx/libkernel/Pthread/Posix/Thread.cppcore/libs/prx/libkernel/Pthread/Posix/Thread.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdPull request closed