fix(libc): share the guest SDK application allocator #6610
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6610"
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 JJenkx on 2026-10-15T22:53:11Z.
What
Use the loaded guest SDK allocator for HLE application allocations on Linux. The SDK CRT owns initialization and finalization, preventing HLE from resetting a heap that already has live allocations. The debugger showed the SDK CRT calling the application initializer, an SDK allocation, HLE lazy initialization calling that same initializer again, then SDK free rejecting the earlier allocation. Require all ten allocator entry points to belong to the same native module and retain its loader reference until process exit. Pure HLE and non-Linux paths keep their existing behavior.
Tested
Additional Linux title check, 2026-10-18 UTC: Snoopy & The Great Mystery Club (PPSA28795, v01.000.002) on main
1e2d9b369bversus that main plus exact PR headbbc16577c9(local integration1f6b6bb85e). All 1,628 package files were checked against the listing before the comparison. Main stops in the guest SDK allocator during startup (int $0x45, application return offset0x1674e4b). With this PR, it loads the assets and reaches GPU initialization, then aborts after 4.04 seconds on the separate unsupported multisampled DCC register-clear code0x20. All 10application_heap_*tests pass on the integration, with no skips (0.05 s), and conventions pass. This confirms removal of this startup blocker only: no playable frame, gameplay, audio correctness or performance gain is claimed. Logs and debugger details remain local; no game files are attached.Arch Linux x86-64, GCC 16.2.1. Full libraries and relinker build with bundled dependencies and build-only validator lifetime repair #6476. Eleven allocator tests pass, including a native SDK fixture initialized before HLE use; removing the adoption block makes that unchanged regression fail. The incomplete-provider rejection test also passes. Silksong PPSA12544 version 01.000.010: current main
5d9dcc42dplus build-only #6476 exits 139 before a window in 2.02 s; the same base plus this change reaches the rendered title menu and closes normally (exit 0, 123.81 s). A first candidate launch lacked the writable devlog/app directory and was excluded; the compared staged run includes the same required directories as baseline. A second native run reached the screen-size calibration screen with injected controller input, stayed active for 182.74 s, and closed normally (exit 0). Both runs restored the temporary udmabuf limit. A third completed run passed both calibration screens and the intro cinematic, reached the opening tutorial with HUD and Bind prompt, and responded to Circle/Bind by restoring health (one to four filled masks). Right input was also issued. Ordinary close returned 0 after 363.98 s. This verifies initial tutorial interaction only; later areas, audio quality, and sustained performance remain unverified. No speed claim.God of War: Sons of Sparta PPSA28997 version 01.008.001 also reaches the rendered title and responds to controller input through the New Game/save-slot menus on Linux (main
5d9dcc42dplus this fix, build repair #6476 and tracing #6341; validation head d9aaee44a199). Navigation completed with ordinary close, exit 0 after 183.66 s. A targeted negative control using the same converted game/modules and graphics libraries, removing only the four-line SDK-adoption block from HLE libc, exits 139 before a window in 2.02 s in both runs. This is not a separate complete main-only build. Restoring the candidate reaches the rendered title again and closes normally, exit 0 after 63.81 s; eleven allocator tests pass after restoration. A further run on that same validation head passed the opening dialogue, reached the active Cyclops fight with player/boss HUDs, and responded to left-stick movement. It wrote a 2,036-byte player-save file and closed normally after 253.63 s (exit 0). A late capture went black after player health fell; the death/reload flow was not checked. Boss completion, save reloading, audio quality and controlled performance remain unverified. Details: https://github.com/boykopovar/AnyPS5/discussions/1742#discussioncomment-18961457Additional scope check: isolated integration
7cb3bd78d924= main896e1b2b72f3plus this commit builds the full runtime and passes all 11 selected allocator checks (no skips) on the same Linux/Ryzen host. Absolum PPSA28311 v01.002.000 still aborts during video-logo cleanup, just as on main, at a direct-memory release whose supplied range is not physically allocated. The separate memory trace shows a virtual address supplied where the allocation has a different physical offset. This PR does not resolve that title's cleanup failure; no kernel validation change or successful gameplay is claimed. The converted executable/modules and assets are unchanged between these native runs.Independent title validation: fma-rc reports that Cult of the Lamb PPSA06464 hits the same allocator double initialization on main
bf2053816plus #6149. Adding this PR avoids the replacement allocator’s abort at about 1.5 s and keeps the process running through their 120 s test limit. The contributor later corrected the visual result: frame captures show the studio logo followed by a loading screen with its spinner; the log becomes silent after about 20 s. The remaining loading stall is tracked in #5621. They also report ten selected application-heap tests passing on Linux. This is contributor-reported evidence, not a local title run.Current-main rebase validation (2026-10-17): rebased as one commit
5e649e6d2aon main66702f1cff; preserved both additive libc technical-debt entries. The source patch is unchanged by the rebase. Fresh Release build of libc and the three allocator test executables with bundled dependencies succeeds; all 11 allocator tests pass (0.05 s, no skips), including SDK adoption and partial-provider rejection. Conventions and whitespace checks pass. Native title runs above were on their stated earlier bases; no native title rerun or performance gain is claimed for this rebase.SDK/scripting compatibility refresh (2026-10-18 UTC): rebased as one commit on main
a8581d3331. Reproduced the reported interaction with #6842: merging its headb4e129ff800826015a5b0df120225382bb99c0fdinto the rebased, unchanged SDK test aborts at line 231. The SDK regression now callsApplicationHeapAlign/ApplicationHeapFreedirectly instead of asserting that the separate scripting hooks use the application heap. It still verifies alignment/size, SDK ownership, one initialization, live allocation preservation and retained module lifetime. Existing scripting-hook tests remain unchanged by this PR. This PR alone builds and passes all 11 allocator checks; the clean temporary merge with #6842 builds and passes all 12, each repeated three times (36 executions, no failures/skips). Restored the standalone branch, rebuilt and reran its 11 checks successfully. Conventions and whitespace checks pass. Linux x86-64 Release, bundled dependencies; this is allocator integration testing, with no new native title or performance claim. The branches merge cleanly and neither requires the other.The subsequent Snoopy bring-up report records the rendered title/menu result when this PR is combined with a separately published DCC register-clear fix, #6543 and #7250. New Game reaches a rendered loading screen and then fails on a later resident multisampled metadata write; gameplay remains unconfirmed. Those combined results are not attributed to this allocator change alone.
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-15T23:30:05Z.
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.
docs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/ApplicationProcessParameters.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/ApplicationHeap.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/src/ApplicationProcessParameters.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/ApplicationProcessParameters.cppcore/libs/tests/ApplicationHeap.cppcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/src/ApplicationHeap.cppcore/libs/prx/libc/src/ApplicationProcessParameters.cppcore/libs/tests/ApplicationHeap.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-15T23:36:02Z.
Manually reviewed the shared files that the overlap bot could not compare, using the archived patches and rechecking all 27 current PR head hashes against GitHub.
NOT APPLE. They do not implement SDK allocator adoption. This PR keeps the new allocator discovery Linux-only and leaves the existing process-parameter getter unchanged.tests/ApplicationHeap.cpptotests/memory/ApplicationHeap.cppand changing test registration helpers. If that lands first, this PR will need its test paths/registration adapted during rebase; it does not require those moves to implement allocator ownership.Depends on: noneremains accurate. No claim that these other branches are mergeable: the bot specifically reports that their own base conflicts prevented automatic comparison. This PR itself remains mergeable against current main.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-17T10:15:42Z.
Cult of the Lamb (PPSA06464, Unity) hits the same double initialization, tracked in #5621. On
mainbf2053816with #6149 (needed to get past an earlier fault inUnifyPS5Plugin.prx) the game's replacement allocator builds a 256 MiB heap at 0x200000000 from the bundledlibc.prx_malloc_init, then a second one at 0x216a00000 fromApplicationHeap's lazy init, and at 1.5 sIl2cppUserAssemblies.prxfrees a block from the first heap and the replacementfreeaborts. With this PR added only the first heap is created, there is no abort, and the game keeps running until my 120 s limit. It then shows the studio logo and stays on the loading screen with its spinner (log silent after about 20 s), which I am following up in #5621. (Edited: I first wrote that no frame was presented and pointed at the draw path; frame captures show otherwise.)The
application_heaptests (10, including the two new SDK ones) pass onmainplus this PR on Arch Linux with an RTX 5080, RADV and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-18T00:09:48Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainate3838332ee31af787ad311b7eadbe53d8d012e95. GPU tests ran on lavapipe (llvmpipe, LLVM 22.1.8).#6610 and #6842 together break #6610's test
application_heap_guest_sdk. Each PR alone passes it (#6842 does not have the test),mainhas no such test. Merged together, in this order (#6610 then #6842), it aborts (2 of 2):Line 231 of
core/libs/tests/ApplicationHeap.cppon #6610's head isrequire(scriptingGetMem_nid_postfix(64, 48) == storage.data()). The test expects the scripting hooks to take their blocks from the SDK's own allocator (storage.data()), which #6610 adopts. #6842 moves the hooks to libc's own heap on purpose (ApplicationHeap.cpp:209and:218on its head callGuestHeap::GuestHeapAlign_nid_postfixandGuestHeapFree_nid_postfix), soscriptingGetMemno longer returns the SDK block. The two PRs pick opposite owners for these hooks, so whichever lands second has to change the other's expectation.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-18T00:19:54Z.
Reproduced on main
a8581d3331: #6610 plus #6842 headb4e129ff800826015a5b0df120225382bb99c0fdaborts at the reported line 231. Fixed the SDK test to exerciseApplicationHeapAlign/ApplicationHeapFreedirectly. Its purpose is to verify adoption of the SDK application heap; it no longer makes a separate assertion about which allocator the scripting hooks select. The existing scripting tests are unchanged by this PR.The refreshed branch contains one commit on current main. Standalone: all 11 allocator checks pass. Temporary clean merge with #6842: all 12 allocator checks pass, each repeated three times (36 executions, no failures/skips). Both Release builds pass with bundled dependencies. Restored and rebuilt the standalone branch and reran its 11 checks; conventions/whitespace checks also pass. No native title rerun or speed claim. Updated Tested with the exact integration head and scope.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-18T07:09:09Z.
Additional title evidence: Blue Prince (
PPSA25009, v02.001.000), Linux, Ryzen 7950X / RX 6650 XT, RADV 26.2.4.On main
1b0c7cfa02bec9eef9f55ec31c4cdd5ca087675e, startup exits with SIGSEGV after approximately 2.14 seconds. Read-only debugger breakpoints show the application allocator initializer called first by the loaded guest libc CRT and then again through HLEApplicationHeapInitialize/scriptingGetMem. The second initialization replaces the heap state; reallocation of an earlier block subsequently reaches the guest allocator fatal trap.Applying this PR’s exact head
bbc16577c9a5d7963afcc2f8b18f36e9169a2325onto that main (local integration0ca04e01f8b10fac88115aa0779497372b292fb1) passes the original crash and renders the Blue Prince main menu with readable text. Full libraries build and all 11 allocator checks pass; conventions check passes.This establishes startup and opening-cinematic progress, not verified gameplay or an FPS improvement. The window’s roughly 60 FPS counter is not a matched gameplay benchmark. An initial local observation script incorrectly retained an ABSOLUM window-title filter; its no-window result is invalid and has been corrected.
A subsequent 113-second native smoke run and a separate 92-second direct-capture run both closed through the window manager normally (exit 0, no surviving game PID, temporary kernel limit restored). In the latter, paired direct X11/XComposite captures agree on the main menu. Follow-up input diagnostics show
scePadReadreturns the injected Cross bit (0x4000) to the guest with handle 1 and return count 1. An early press occurred during the splash sequence; a press after the menu was visible entered the loading screen. No libScePad source change was needed.A further native New Game run on the same integration verified the menu at 50 seconds, sent Cross at 61.19 seconds, and rendered the opening credits and cinematic with readable story text by 180 seconds. It closed normally at 187.21 seconds (exit 0, game PID gone, kernel limit restored). This run used no debugger or profiling instrumentation. At that point interactive gameplay and audio were unverified; this was not a performance comparison.
A longer follow-up on the same integration reached the first-person entrance hall with the 50-step HUD by 325 seconds. A recorded 1.5-second analog-stick pulse at 359.67 seconds changed the view from the hall toward the nearby wall in the 385-second capture, confirming camera control in the interactive scene. Forward movement was part of the same pulse and was not isolated; room progression, save reload and audio remain unverified. The run closed normally at 398.67 seconds (exit 0, game PID gone, kernel limit restored), without a debugger or profiling instrumentation. No matched FPS improvement is claimed.
A further 457.65-second run on the same pinned integration isolated movement: a 4-second forward-only left-stick input at 324.48 seconds (right stick neutral) moved from the entrance to the central flower table in the 335-second capture. Subsequent left-stick strafing and forward input reached the far wall/door area. This confirms translation as well as the previously verified camera control. Door interaction and room progression remain unverified. The game closed normally (exit 0, PID gone, temporary kernel limit restored). Relaunching the existing entrance-hall save files still offered New Game rather than Continue, so these files are not a verified resumable checkpoint.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T07:40:04Z.
Checked the diff: the SDK allocator adoption is limited to Linux and to a complete, single-module set of the ten exports (partial or mixed providers throw), and
application_heap_guest_sdk/_partialfail without the adoption block. The debt entry is in place, and the earlier interaction with #6842 is fixed. Title evidence from the PR and third-party runs covers the startup allocator abort; merging through the queue.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-19T07:56:41Z.
@JJenkx this looks like a Linux regression from this merge across many homebrew catalog titles.
Linux (Ubuntu 24.04 container, GCC 13, Release), headless with SDL's offscreen driver, so the titles normally stop at
DisplayWindow: Vulkan support is either not configured in SDL or not available .... Catalog sweep ofmain05b5d192f(before this merge) againste0a6f31d5(after it): 41 of the 61 titles that reached that check now die earlier or differently, with[libc] abort() called from ..., SIGSEGV, SIGILL, or Mesa's../radv-src/src/util/xmlconfig.c: 389: out of memory.(ccleste, RommPS, Mortalfin, Dusklight, Mario 64, Ship of Harkinian, Link's Awakening).Same machine, same build directory, 30 s per title,
e0a6f31d5with and withoutgit revert -m 1 096279ed2(nothing else changed, rebuilt each time):e0a6f31d5abort(), thenxmlconfig.c: 389: out of memory.DisplayWindowcheckxmlconfig.c: 389: out of memory.DisplayWindowcheckxmlconfig.c: 389: out of memory.DisplayWindowcheckabort()DisplayWindowcheckabort()DisplayWindowcheck[HUI] gl 4.6 ... renderer="PS5 AGC"DisplayWindowcheckDisplayWindowcheckDisplayWindowcheckThe
out of memorycomes from Mesa's own allocation while it reads its driconf, so host allocations seem to fail once the guest SDK allocator is adopted. These titles bundle their own runtime, so perhaps the ten#guestexports are found in a module whose allocator is never initialized on this path: the adoption block returns before the replacement table's initializer runs. Is the initializer expected to have run already by the timeApplicationHeapInitialize_nid_no_patchadopts the exports?Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-19T09:02:02Z.
Follow-up with a likely cause and a guard to try. All of these titles bundle the SDK
libc.prxinsce_module, so its relinked guest module (app0/sce_module/libc.prx.guest.prx) exports all ten allocator NIDs as#guest. The adoption block runs beforeApplicationHeapInitialize_nid_no_patchlooks at the title's own replacement table, so these titles get the guest allocator even if they never replaced it. Before this merge, an all-null table at+0x20gave them the default heap throughApplicationHeapRegister_nid_no_patch.I tried adopting only when the title's table has a non-null entry:
On
maine12c91357, Linux, with only that change (local, not pushed):DisplayWindowcheck again, as they do with the merge reverted.application_heap_*tests pass 5 of 5 (--repeat until-fail:5), includingapplication_heap_guest_sdkandapplication_heap_guest_sdk_partial.I can't run Snoopy or Blue Prince. Do they have a non-null replacement table, so they keep the adoption with this guard? Also, 20 other catalog titles bundle
libc.prxand were not affected by the merge, and I haven't worked out why. So the empty table may not be the whole story.Imported from boykopovar/AnyPS5. Originally posted by root-over on 2026-10-19T10:56:46Z.
Data point with a real display and GPU, past the
DisplayWindowcheck: Linux (Ubuntu, kernel 7.0, Wayland), AMD Ryzen 5 5625U iGPU (Vega, RADV RENOIR, Mesa 26.0.8), GCC 15.2.0, Release,main8816fd772. Catalog releases checked against their sha256,eboot.binandsce_module/libc.prxunwrapped withtools/unwrap_self.py, 30-45 s per title.mainmain+git revert -m 1 096279ed2main+ @babyhuey's guardHello World: unique ownership failed(new (std::nothrow)returned null), no windowI_AllocLow: cannot allocate 256000 bytes, exits[libc] abort()at 3 s--linux-fixed-base 0x400000)[libc] abort()at 3 s--trap-sdk-syscall-stubs)std::bad_allocat 3 s"Past start-up" means they get through allocation and stop later on this GPU's missing features (no
VK_KHR_fragment_shader_barycentricfor ccleste and VLC, no mesh shaders for PS5SX2), unrelated to this change.With the guard, the
application_heap/libctests pass (16/16 after a full rebuild).DriftCheck's
libc.prxis built by ps5-native-app-boilerplate'slibc_builder.cpp: it exports the allocator NIDs from an observed API surface and only importsmalloc,freeandposix_memalign, which it hands to_sceKernelRtldSetApplicationHeapAPIin its initializer, so it has no allocator of its own to adopt. Other catalog titles generated from the same boilerplate likely behave the same way.