Skip to content

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

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

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 7648 docs/dev/debt/libc.md
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 9761 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 9773 core/libs/prx/libc/CMakeLists.txt
PR 9775 core/libs/prx/libc/CMakeLists.txt
PR 9798 core/libs/prx/libc/CMakeLists.txt
PR 9863 docs/dev/debt/libc.md
PR 9873 docs/dev/debt/libc.md
PR 9929 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 9964 docs/dev/debt/libc.md
PR 10002 docs/dev/debt/libc.md
PR 10007 docs/dev/debt/libc.md
PR 10113 docs/dev/debt/libc.md
PR 10158 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 10165 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 10200 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 10226 docs/dev/debt/libc.md
PR 10234 docs/dev/debt/libc.md
PR 10245 docs/dev/debt/libc.md
PR 10250 docs/dev/debt/libc.md
PR 10253 docs/dev/debt/libc.md
PR 10265 docs/dev/debt/libc.md
PR 10274 docs/dev/debt/libc.md
PR 10315 docs/dev/debt/libc.md
PR 10321 docs/dev/debt/libc.md
PR 10325 docs/dev/debt/libc.md
PR 10328 docs/dev/debt/libc.md
PR 10345 docs/dev/debt/libc.md
PR 10349 docs/dev/debt/libc.md
PR 10397 docs/dev/debt/libc.md
PR 10405 core/libs/prx/libc/src/FileAndHeap.cpp
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 10565 docs/dev/debt/libc.md
PR 10569 docs/dev/debt/libc.md
PR 10749 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 11260 docs/dev/debt/libc.md
PR 11262 docs/dev/debt/libc.md
PR 11266 docs/dev/debt/libc.md
PR 11621 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 11624 core/libs/prx/libc/CMakeLists.txt
PR 11625 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 11628 core/libs/prx/libc/CMakeLists.txt
PR 11632 docs/dev/debt/libc.md
PR 11634 docs/dev/debt/libc.md
PR 11661 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 11664 docs/dev/debt/libc.md
PR 11689 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 11698 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 11793 core/libs/prx/libc/src/LocaleSupport.cpp
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 11895 docs/dev/debt/libc.md
PR 11907 docs/dev/debt/libc.md
PR 11947 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 12053 docs/dev/debt/libc.md
PR 12057 docs/dev/debt/libc.md
PR 12071 core/libs/prx/libc/CMakeLists.txt
PR 12122 docs/dev/debt/libc.md
PR 12146 core/libs/prx/libc/CMakeLists.txt
PR 12149 docs/dev/debt/libc.md
PR 12184 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12271 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12292 docs/dev/debt/libc.md
PR 12397 docs/dev/debt/libc.md
PR 12510 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 12511 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 12518 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 12530 docs/dev/debt/libc.md
PR 12532 docs/dev/debt/libc.md
PR 12560 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12592 core/libs/prx/libc/include/SonyCrt.hpp
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 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 12777 core/libs/prx/libc/CMakeLists.txt
PR 12841 docs/dev/debt/libc.md
PR 12849 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 12882 core/libs/prx/libc/CMakeLists.txt
PR 12883 core/libs/prx/libc/CMakeLists.txt
PR 12884 core/libs/prx/libc/CMakeLists.txt
PR 12885 core/libs/prx/libc/CMakeLists.txt
PR 12886 core/libs/prx/libc/CMakeLists.txt
PR 12887 core/libs/prx/libc/CMakeLists.txt
PR 12888 core/libs/prx/libc/CMakeLists.txt
PR 12889 core/libs/prx/libc/CMakeLists.txt
PR 12890 core/libs/prx/libc/CMakeLists.txt
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 13119 docs/dev/debt/libc.md
PR 13186 docs/dev/debt/libc.md
PR 13303 core/libs/prx/libc/CMakeLists.txt
PR 13304 core/libs/prx/libc/CMakeLists.txt
PR 13305 core/libs/prx/libc/CMakeLists.txt
PR 13306 core/libs/prx/libc/CMakeLists.txt
PR 13307 core/libs/prx/libc/CMakeLists.txt
PR 13308 core/libs/prx/libc/CMakeLists.txt
PR 13310 core/libs/prx/libc/CMakeLists.txt
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 13378 core/libs/prx/libc/CMakeLists.txt
PR 13379 core/libs/prx/libc/CMakeLists.txt
PR 13380 core/libs/prx/libc/CMakeLists.txt
PR 13381 core/libs/prx/libc/CMakeLists.txt
PR 13382 core/libs/prx/libc/CMakeLists.txt
PR 13383 core/libs/prx/libc/CMakeLists.txt
PR 13385 core/libs/prx/libc/CMakeLists.txt
PR 13386 core/libs/prx/libc/CMakeLists.txt
PR 13387 core/libs/prx/libc/CMakeLists.txt
PR 13389 core/libs/prx/libc/CMakeLists.txt
PR 13390 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 13391 core/libs/prx/libc/CMakeLists.txt
PR 13392 core/libs/prx/libc/CMakeLists.txt
PR 13393 core/libs/prx/libc/CMakeLists.txt
PR 13394 core/libs/prx/libc/CMakeLists.txt
PR 13395 core/libs/prx/libc/CMakeLists.txt
PR 13449 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 13730 core/libs/prx/libSceAmpr/Export.cpp
PR 13784 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 13793 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
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 14020 docs/dev/debt/libc.md
PR 14022 core/libs/prx/libc/src/LocaleSupport.cpp
PR 14085 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libc.md
PR 14235 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 14298 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 14326 docs/dev/debt/libc.md
PR 14373 core/libs/prx/libc/src/LocaleSupport.cpp
PR 14559 core/libs/prx/libc/src/FileAndHeap.cpp
PR 14560 core/libs/prx/libc/src/FileAndHeap.cpp
PR 14585 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 14588 docs/dev/debt/libc.md
PR 14595 docs/dev/debt/libc.md
PR 14610 docs/dev/debt/libc.md
PR 14619 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 14620 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 14623 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 14799 core/libs/prx/libc/CMakeLists.txt
PR 14828 docs/dev/debt/libc.md
PR 14864 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 14878 docs/dev/debt/libc.md
PR 14915 docs/dev/debt/libc.md
PR 14955 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15004 docs/dev/debt/libc.md
PR 15095 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15098 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 15099 core/libs/prx/libc/CMakeLists.txt
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.

This branch has not been deployed

No deployments
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.

6 participants