fix(libc): adopt the guest SDK allocator only when the title replaces the heap #7897
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7897"
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 babyhuey on 2026-10-19T12:49:57Z.
What
Since #6610,
ApplicationHeapInitialize_nid_no_patchadopts a loaded guest SDK's ten allocator exports on Linux before it looks at the title's replacement table. Many catalog titles bundle alibc.prxthat exports those NIDs but has no allocator of its own: per @root-over on #6610, the ps5-native-app-boilerplatelibc.prximports onlymalloc,freeandposix_memalignand hands them to_sceKernelRtldSetApplicationHeapAPI. For these titles, HLE allocations now go through exports that lead back into HLE, and they abort, segfault or fail to allocate at start-up.The guest exports are now adopted only when the title's replacement table has an allocator entry. With an empty table, the title keeps the default heap, as before #6610. A title that does replace the allocator keeps #6610's path, and non-Linux hosts are unchanged.
application_heap_guest_sdk_default: it loads the same guest SDK fixture, clears the replacement table, and checks that an allocation comes from the default heap without calling the fixture's exports. Withmain'sApplicationHeap.cppit segfaults (the fixture'smallocreads a null table entry).ApplicationGuestHeapApidebt entry states the new condition.Tested
On
4a5ce8a09(based onmainb106f6f8c):application_heap|allocatorpass 5/5 (--repeat until-fail:5), including the new one and #6842'sapplication_heap_scripting. No warnings in the touched files.application_heap|allocatorpass 5/5 (the guest SDK tests are Linux-only). No warnings in the touched files. Eternal Darkness (PPSA99314) runs as onmain(413 frames in 30 s). The guarded path is Linux-only, so nothing changes on Windows.DisplayWindowVulkan check. Onmainthese ten abort, segfault or hit an illegal instruction at start-up, or Mesa reportsxmlconfig.c: 389: out of memory.. With this change all ten reach theDisplayWindowcheck again: ccleste (PPSA59322), Mario 64 (PPSA99310), Eternal Darkness (PPSA99314), Dusklight (PPSA99305), ProsperoTV (PPSA99003), PSXS5 (PPSA97510), Régie5 (PPSA99520), Media Player Classic (PPSA99015), DriftCheck (PPSA98766) and DOOM (PPSA99666). In the full catalog sweep, 41 of the 61 titles that reached that check stopped earlier after #6610 (#6610 has the table).main02084228aand reach theDisplayWindowcheck with this change merged onto it. So does Sahin (PPSA99404), added later, onmaind50ec76da.check_conventions.pypasses.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-19T13:02:31Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libc.mdL7-8Some 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/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/ApplicationHeap.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/ApplicationHeap.cppcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by root-over on 2026-10-19T13:40:01Z.
Real-GPU run of this head (
4a5ce8a09), past theDisplayWindowcheck: Linux (Ubuntu, kernel 7.0, Wayland), Ryzen 5 5625U iGPU (Vega, RADV RENOIR, Mesa 26.0.8), GCC 15.2.0, Release. Catalog releases checked against their sha256, 30 s each.ctest -R "application_heap|^libc": 12 of 12 pass.main8816fd772both stopped at start-up (my table on #6610).needs a vertex shader before it, a separate limit of this GPU (nofragmentShaderBarycentric, #6528). That is the same point they reach with #6610 reverted.The behaviour matches #6610 reverted, or the guard I tried locally, on every title I have.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-20T02:26:38Z.
Two more Linux titles that this PR brings back, both new in the catalog and not in the description's list. Ubuntu 24.04 in WSL2, GCC 13.3, Release, lavapipe, headless with SDL's offscreen driver, 60 s each.
main500cc640bagainstmainplus head4a5ce8a094.mainapplication heap: incomplete or mixed guest allocator APIBoth run 60 s on Windows on
main, where the guarded path is not built.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T12:35:11Z.
One more title this brings back: Ruffle (PPSA68091, 1.2.0), which bundles
sce_module/libc.prxand has an empty replacement table. Linux, RTX 4070 Ti (NVIDIA 595.99.02), on the display:main15da28937eand1d41645527(2 runs each)xmlconfig.c: 389: out of memory.maine25c9758e0+4a5ce8a094(2 runs)maina9c93a05cc+4a5ce8a094+ #8429 (2 runs)A temporary print on
mainshowed the adopted API coming fromapp0/sce_module/libc.prx.guest.prx. The first HLE allocation is a 32-bytestrndupfrom RADV's config parser, and it got NULL from thatlibc.prx's allocator. Ruffle 1.2.0 last ran onmain98c251fc62(10-17), before #6610.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T15:06:41Z.
A performance data point for this PR: Super Meat Boy 3D (PPSA31162), which bundles
sce_module/libc.prx. Level 1-1, Linux, RTX 4070 Ti (NVIDIA 595.99.02), Release.main30fda0a03aagainst the samemainwith4a5ce8a094merged (clean). Each run starts from a fresh boot. A script waits for the game's ownLoad map completelines (menu, slot 1, world map, level 1), settles for 30 s in the level and counts presents for 60 s withAPS5_PROFILE_DRAW=1.main(2 runs)main+ this PR (2 runs)That's about 3×. Both builds run the same draws: about 150,000 occlusion dumps per 10 s, each draining the draw pipeline. So the per-draw cost on the committer is what changes. I haven't traced why each commit costs about 4.5 times as much while the bundled
libc.prx's allocator serves the HLE allocations. The title runs either way, so onmainthis shows up only as speed.maina9c93a05ccmeasures the same as30fda0a03a(18–20), so the gap isn't from a change inmainbetween those two commits.AI-assisted: yes (Claude Code)