Skip to content

fix(libs): share Sony CRT handler and lconv state between libc and libSceAmpr - #7081

Closed
Pouare514 wants to merge 4 commits into
boykopovar:mainfrom
Pouare514:feat/sonycrt-shared-handler-lconv
Closed

Pouare514 wants to merge 4 commits into
boykopovar:mainfrom
Pouare514:feat/sonycrt-shared-handler-lconv

Conversation

@Pouare514

Copy link
Copy Markdown
Contributor

What

  • Share Sony CRT constraint-handler state and lconv storage between libc and libSceAmpr through a single definition in libc (core/libs/prx/libc/include/SonyCrt.hpp + src/SonyCrt.cpp). Each module previously owned its own handler/mutex/lconv static (internal linkage per TU), so a handler set via one module never fired in the other.
  • Add SonyLconvVariant { Ampr48, Compact0 }: SonyLocaleconv() keeps the verified Ampr layout (decimal_point@0x48); Compact0 (decimal_point@0x00, no prefix) covers catalog titles reusing the Dinkumware layout with a different offset (e.g. PPSA99902, per review on feat(libs): implement C runtime re-exports for libSceAmpr #545). Layouts pinned with static_assert(offsetof(...)).
  • libSceAmpr re-exports the shared state (0hlfW1O4Aa4 localeconv, 6f5f-qx4ucA wcscpy_s, ENLfKJEZTjE/ODGONXcSmz4 handlers) and links libc. wcscpy_s stays 16-bit (guest wchar); the default handler still aborts. Both assumptions debt-noted in TechnicalDebt.md.

Tested

  • New guest_crt test: lconv offset asserts (0x48 incl. sceAmprLocaleconv == localeconv, 0x00 compact), cross-TU handler visibility both directions, default-abort via child process. Passes; verified it fails without the fix (slot disconnected → abort 0xc0000409) and passes with it.
  • Neighbors guest_fiopen, guest_locale, guest_ampr_markers, guest_wide_strings, file_position: 5/5 pass (WinLibs GCC 15.2.0, Release).
  • python tools/check_conventions.py --base origin/main --head HEAD clean, git diff --check clean.
  • Note: the full libs target has a pre-existing, unrelated failure (libSceVideoOut.prx NID patch: duplicate patched export name: LibwuIonIBw), reproduced on pristine origin/main.

Checklist

  • Based on current main; no other open PR implements the same change
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • No new unimplemented paths or silent stubs
  • No notes, investigation files or images added to the repository
  • New third-party code: none
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: catalog localeconv reuse (SymphonyStation5/Cloud Play same NID, PPSA99902 compact variant), feat(libc): implement qsort_s #6707 qsort_s rebase
  • GPUs tested: n/a for this libc accounting change
  • AI-assisted: yes; I am responsible for this change

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 3965 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 5021 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6084 core/libs/prx/libc/CMakeLists.txt
PR 6819 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7645 core/libs/prx/libc/CMakeLists.txt
PR 7715 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7851 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8150 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8417 docs/dev/debt/libc.md
PR 8965 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9466 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 9526 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestCrt.cpp
core/libs/tests/GuestFiopen.cpp
docs/dev/debt/libc.md
PR 9584 core/libs/prx/libc/CMakeLists.txt
PR 9677 docs/dev/debt/libc.md
PR 9773 core/libs/prx/libc/CMakeLists.txt
PR 9775 core/libs/prx/libc/CMakeLists.txt
PR 10007 docs/dev/debt/libc.md
PR 10113 docs/dev/debt/libc.md
PR 10226 docs/dev/debt/libc.md
PR 10274 docs/dev/debt/libc.md
PR 10321 docs/dev/debt/libc.md
PR 10397 docs/dev/debt/libc.md
PR 10506 docs/dev/debt/libc.md
PR 10510 docs/dev/debt/libc.md
PR 10512 docs/dev/debt/libc.md
PR 10569 docs/dev/debt/libc.md
PR 10780 docs/dev/debt/libc.md
PR 10987 docs/dev/debt/libc.md
PR 11109 docs/dev/debt/libc.md
PR 11172 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 11262 docs/dev/debt/libc.md
PR 11266 docs/dev/debt/libc.md
PR 11625 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 11634 docs/dev/debt/libc.md
PR 11661 docs/dev/debt/libc.md
PR 11664 docs/dev/debt/libc.md
PR 11689 docs/dev/debt/libc.md
PR 11698 docs/dev/debt/libc.md
PR 11726 docs/dev/debt/libc.md
PR 11831 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 11848 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 11870 docs/dev/debt/libc.md
PR 12053 docs/dev/debt/libc.md
PR 12057 docs/dev/debt/libc.md
PR 12184 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12518 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 12574 core/libs/prx/libc/include/SonyCrt.hpp
core/libs/tests/GuestCrt.cpp
docs/dev/debt/libc.md
PR 12592 core/libs/prx/libc/include/SonyCrt.hpp
docs/dev/debt/libc.md
PR 12593 docs/dev/debt/libc.md
PR 12594 docs/dev/debt/libc.md
PR 12598 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12605 docs/dev/debt/libc.md
PR 12627 docs/dev/debt/libc.md
PR 12682 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12688 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12700 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12704 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 12717 core/libs/prx/libc/CMakeLists.txt
PR 12849 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 12920 docs/dev/debt/libc.md
PR 12947 docs/dev/debt/libc.md
PR 12965 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 13311 core/libs/prx/libc/CMakeLists.txt
PR 13312 core/libs/prx/libc/CMakeLists.txt
PR 13313 core/libs/prx/libc/CMakeLists.txt
PR 13314 core/libs/prx/libc/CMakeLists.txt
PR 13316 core/libs/prx/libc/CMakeLists.txt
PR 13317 core/libs/prx/libc/CMakeLists.txt
PR 13318 core/libs/prx/libc/CMakeLists.txt
PR 13319 core/libs/prx/libc/CMakeLists.txt
PR 13320 core/libs/prx/libc/CMakeLists.txt
PR 13381 core/libs/prx/libc/CMakeLists.txt
PR 13390 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 13449 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 13730 core/libs/prx/libSceAmpr/Export.cpp
PR 13794 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 13809 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 13828 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 14022 core/libs/prx/libc/src/LocaleSupport.cpp
PR 14212 docs/dev/debt/libc.md
PR 14298 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 14559 core/libs/prx/libc/src/FileAndHeap.cpp
PR 14560 core/libs/prx/libc/src/FileAndHeap.cpp
PR 14588 docs/dev/debt/libc.md
PR 14595 docs/dev/debt/libc.md
PR 14610 docs/dev/debt/libc.md
PR 14915 docs/dev/debt/libc.md
PR 15095 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15206 docs/dev/debt/libc.md
PR 15336 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15484 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15490 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15535 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15561 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15712 core/libs/prx/libc/src/LocaleSupport.cpp
PR 15715 core/libs/prx/libc/src/LocaleSupport.cpp
PR 15791 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15796 docs/dev/debt/libc.md
PR 15800 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15801 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15802 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15803 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15804 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15807 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15809 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 15834 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15879 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15923 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/LocaleSupport.cpp
PR 15938 core/libs/prx/libSceAmpr/Export.cpp
PR 15973 docs/dev/debt/libc.md
PR 16004 docs/dev/debt/libc.md
PR 16017 docs/dev/debt/libc.md
PR 16107 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16170 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 16178 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 16210 docs/dev/debt/libc.md
PR 16214 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 16216 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 16305 core/libs/prx/libc/src/LocaleSupport.cpp
PR 16341 core/libs/prx/libSceAmpr/Export.cpp
PR 16412 core/libs/prx/libc/CMakeLists.txt
PR 16416 core/libs/prx/libc/CMakeLists.txt
PR 16418 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
PR 16428 core/libs/prx/libc/CMakeLists.txt
PR 16435 core/libs/prx/libc/CMakeLists.txt
PR 16438 core/libs/prx/libc/CMakeLists.txt
PR 16457 core/libs/prx/libc/CMakeLists.txt
PR 16516 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 16548 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 16550 docs/dev/debt/libc.md
PR 16560 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 16580 docs/dev/debt/libc.md
PR 16613 docs/dev/debt/libc.md
PR 16623 core/libs/prx/libSceAmpr/Export.cpp
PR 16630 core/libs/prx/libSceAmpr/Export.cpp
PR 16635 core/libs/prx/libSceAmpr/Export.cpp
PR 16638 core/libs/prx/libSceAmpr/Export.cpp
PR 16740 docs/dev/debt/libc.md
PR 16747 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16757 docs/dev/debt/libc.md
PR 16791 core/libs/prx/libc/CMakeLists.txt
PR 16847 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16861 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 16862 docs/dev/debt/libc.md
PR 16866 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16912 docs/dev/debt/libc.md
PR 16919 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md

@Pouare514

Copy link
Copy Markdown
Contributor Author

Rebased onto 677354d (was e51d4e1) and reconciled with main without deleting main content. New HEAD fe01208, MERGEABLE, conventions pass.

Per file:

  • SonyCrt.hpp: kept main full content (*ti3 family, strtok/ctime/asctime/mbstowcs/fpclassify/sinh/fltrounds, fixed Dinkumware localeconv table); removed namespace{} and externalized only stateful pieces (mutex/slot/default+ignore+set+invoke handlers, SonyLocaleconv) with pure helpers staying inline. Added SonyLconvVariant/SonyLconvFor/SonyLocaleconvEx decls.
  • SonyCrt.cpp: kept; lconv section rewritten for main fixed table (shared Ampr storage with main init values + Compact storage, decimal_point .), no host sync.
  • SceTypes.hpp: kept main SonyLconv untouched; added SonyLconvCompact + 0x00 assert.
  • GuestCrt.cpp: merged (main fpclassify/fltrounds/sinh/divti/umodti/asctime/ctime/strtok/mbstowcs/random + branch offsets/cross-TU/abort-child). Tests live at core/libs/tests/GuestCrt.cpp (test: organize library tests and label CTest suites #6044 open, no move).
  • Ampr Export/CMakeLists, libc test stanza: main already had all 4 exports + links, kept as-is (incl. _Thrd_id etc.).
  • libc/CMakeLists: adds SonyCrt.cpp. FileAndHeap fopen_s: handler invoke + main nullptr hardening (Annex K). GuestFiopen: installs ignore handler before violation checks (default aborts by design).
  • Debt: TechnicalDebt.md untouched (now index); updated the two debt/libc.md lines to shared-state wording + compact note.

Verified: Release/Ninja build OK; guest_crt/fiopen/locale/ampr_markers/wide_strings + qsort/wide_conversion/math/mktime/strftime/time_conversion/allocating_strings all pass; git diff --check clean; check_conventions --base origin/main clean. Fail-without/pass-with holds: disconnecting Ampr slot fails guest_crt (abort), restoring passes.

Overlap audit: true coordination needed with #6133 (adds SonyModti3 inside same namespace{} - must rebase onto this) and #6707 (touches SonyCrt.hpp handler typedef/namespace + qsort_s per-TU handler docs, will need shared update). #7068 (fopen_s host errno) still open, reconciled here as handler+errno; everything else rebase-only disjoint.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 17, 2026
@Pouare514

Copy link
Copy Markdown
Contributor Author

CI note: everything runnable passes (conventions, register-context x4, relinker on Linux/Windows/macOS, write-watch x2). The full Linux + Windows builds need collaborator dispatch (automatic full builds only run on main) - requesting dispatch when review allows.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 17, 2026
@blawesom

Copy link
Copy Markdown
Contributor

Rebase handoff — rebased onto current main (authorship unchanged). One conflict in FileAndHeap.cpp: your constraint-handler-invoking fopen_s failure path taken (main's bare GuestEinval return superseded by your handler call with GuestEnoent).

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the known main regression (agc_driver_tessellation segfault — Mesa, #5444), not this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7081
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is ca9407394.

@blawesom

Copy link
Copy Markdown
Contributor

Pre-review verification found a link failure — the handoff branch builds, but patched_libraries fails on it: libSceAmpr.prx references SonyIgnoreHandlerS (mangled _Z18SonyIgnoreHandlerSPKcPvi, defined in libc's SonyCrt.cpp) but cannot resolve it — the handler is defined in libc's build (core/libs/prx/libc/CMakeLists.txt compiles SonyCrt.cpp) and SceAmpr/Export.cpp calls it at line 1044, but nothing exports it across the prx boundary. Everything else passes (full suite green apart from the known main regression agc_driver_tessellation, Mesa #5444); the handoff branch is still pushed for the rebase value, with this caveat: the shared CRT handler needs an export (or an inlined copy) in libSceAmpr before it links. Details in the rebase comment above.

@Pouare514

Copy link
Copy Markdown
Contributor Author

Handoff picked up, thanks @blawesom - branch reset to ca94073 (authorship intact) plus one fix commit on top, and thanks for the Linux verification.

fopen_s errno verdict, checked hunk by hunk: the constraint-handler invocations are kept as intended (null result/filename/mode invoke the handler and return EINVAL 22, per Annex K which returns the passed error - matches GuestFiopen/GuestCrt). One correction to the handoff: the open-failure path returns the guest-translated errno, not a hardcoded ENOENT - that is main's newer behavior (GuestErrnoFromHost in fopen_nid_postfix, debt note included) and GuestFopenErrors requires it for the ELOOP/ENAMETOOLONG/EISDIR cases, where a hardcoded 2 would fail. I also removed the now-unused GuestEnoent constexpr the merge left behind.

Link failure fixed via extern C _nid_no_patch, the same mechanism as AddPathProvider_nid_no_patch: the four Sony CRT entry points Ampr calls (SonyLocaleconv, SonySetConstraintHandlerS, SonyIgnoreHandlerS, and SonyInvokeConstraintHandler via the inlined SonyWcscpyS) are now published under literal _nid_no_patch names, so the NID patcher leaves them verbatim and the patched libSceAmpr.prx resolves them from libc.prx. Root cause was that plain C++ names get NID-hashed in libc's exports while Ampr still imported the mangled names. Handler slot and lconv storage stay single-definition in libc SonyCrt.cpp - no inlined copy, shared state intact.

Verified (Release, Ninja, BUILD_TESTING=ON, Windows): full patched-libs deploy green - patched_libraries passes (previously libSceAmpr.prx failed with error 127); unit gate green: guest_crt, guest_fiopen, guest_locale, guest_ampr_markers, guest_wide_strings, plus guest_safe_errors, guest_wide_conversion, guest_amm_placement, guest_ampr_threads, guest_ampr_cpp_error, guest_rune_locale, guest_collate, guest_errors, guest_posix_scalar_io. git diff --check and tools/check_conventions.py --base origin/main --head HEAD clean.

@Pouare514
Pouare514 force-pushed the feat/sonycrt-shared-handler-lconv branch from 5acfae9 to 347c538 Compare October 18, 2026 00:51
@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 18, 2026
@adriadam10 adriadam10 self-assigned this Oct 19, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, the shared handler/lconv state across the libc/libSceAmpr boundary is a real gap and the _nid_no_patch exports are the right mechanism. Before this can merge:

  • Conflicts with main (SonyCrt.hpp, FileAndHeap.cpp, docs/dev/debt/libc.md). main changed SonyConstraintHandler to APS5_VABI, moved the slot/mutex/default handler out of the anonymous namespace, and qsort_s (#6707) and strerror_s now call SonyInvokeConstraintHandler / compare against SonyDefaultConstraintHandler. The out-of-line definitions in SonyCrt.cpp (lines 7-44) need the APS5_VABI signature, and strerror_s must keep seeing the same default-handler pointer. Please rebase and re-run guest_crt, guest_qsort, guest_fiopen.
  • Drop SonyLconvVariant::Compact0 / SonyLconvCompact (SceTypes.hpp:36, SonyCrt.cpp:76-106, GuestCrt.cpp:94-105). No export uses it; only the test does, and the debt note itself says the layout is unverified. An unreferenced, unverified layout is dead code. Re-add it in the PR that wires a title-backed export to it, with the evidence.
  • GuestCrt.cpp:275: the abort check re-launches argv[0] through std::system with a hand-quoted path; that is shell-dependent on Windows. Prefer CreateProcess/fork-free alternatives already used by other guest tests, or assert the default handler pointer instead of spawning.

The CI on this head only covers Conventions/relinker; the full Linux + Windows Build will run in the merge queue after the rebase.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi Pouare514,

Thank you for your patience with this one, and thanks to BunnyFl for the firmware 13.42 data on our fopen_s question.

That data settles the question, and main has since caught up on that part. On current main, fopen_s already calls the constraint handler for a null result, filename or mode with the module's own messages ("fopen_s: bad FILE ** argument", "fopen_s: bad argument"), a NULL pointer and 22. The default handler in SonyCrt.hpp now writes the message to stderr and returns instead of aborting.

So the rebase (the branch conflicts with main in SonyCrt.hpp, FileAndHeap.cpp and tests/GuestCrt.cpp) mostly means keeping main's side for those two behaviours:

  • In core/libs/prx/libc/src/SonyCrt.cpp, the moved SonyDefaultConstraintHandler (lines 17-22 at e6f5d4c71b) calls std::abort(). Taking main's body (write the message, return) keeps the current behaviour.
  • In FileAndHeap.cpp, main's fopen_s calls (the module's messages, NULL as the pointer) can replace this branch's SonyInvokeConstraintHandler("fopen_s", result, GuestEinval) at lines 466 and 471.

The core of the PR is still needed: on main, libSceAmpr includes SonyCrt.hpp and gets its own copy of the handler slot, mutex and lconv state, so a handler set through one module still does not reach the other. Moving that state behind the _nid_no_patch exports, as you did, is what fixes it.

@sherySJ

sherySJ commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@Pouare514 are you still working on this? Main has moved under it since 24 October: SonyCrt.hpp (default handler, inline helpers from the Annex K work), FileAndHeap.cpp, GuestCrt.cpp, GuestFiopen.cpp and docs/dev/debt/libc.md conflict, and oneandonlydean's 4 November note lists what the rebase should keep from main (the default handler writes the message and returns, main's fopen_s calls).

If you are not, I would like to carry it as a separate PR with your four commits kept and your authorship intact, rebased onto current main and reduced to what main still lacks: one definition of the handler slot, mutex and lconv state in libc behind the _nid_no_patch exports, with libSceAmpr using it. No fopen_s change, main's default-handler body kept, and I would show guest_crt, guest_ampr_markers, guest_fiopen and guest_locale together with guest_crt failing on main. I would not close this PR. If you push your own rebase first I will drop mine, and I am happy to run the tests on Linux against your new head if that helps.

Unless I hear from you in 48 hours I will start on it.

@adriadam10

Copy link
Copy Markdown
Collaborator

Closing as stale: this conflicts with main (SonyCrt.hpp, FileAndHeap.cpp, GuestCrt.cpp, GuestFiopen.cpp, docs/dev/debt/libc.md) and there has been no activity from the author since 2026-10-18, after the rebase request of 2026-11-04.

The rebase is not mechanical any more. main's default constraint handler now writes the message and returns, while the out-of-line SonyDefaultConstraintHandler in SonyCrt.cpp here aborts, and fopen_s already invokes the handler on main. The shared definition has to be redone on top of that, keeping the guest_crt cross-module checks.

The gap is real (a handler set in libc is not seen by libSceAmpr, and lconv is stored once per module). @sherySJ offered to carry it with the original commits and authorship kept; feel free to do that, or reopen this rebased onto current main.

@sherySJ

sherySJ commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Carried as #16933, rebased onto current main with @Pouare514's commit and authorship kept. It follows adriadam10's note above: the default handler keeps main's write-and-return body, fopen_s is left as main has it, and the guest_crt cross-module checks are rewritten on current GuestCrt.cpp. Pouare514, if you would rather reopen this one instead, say so and I will close mine.

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

Labels

build docs libc needs rebase Conflicts with main, rebase needed prx unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants