fix(libc): give the scripting heap hooks blocks from libc's own heap #6842

Merged
milescoviello merged 1 commit from upstream-pr/6842 into main 2026-10-19 12:03:41 +00:00
milescoviello commented 2026-10-16 14:04:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T14:04:55Z.


What

Since #5092 (merged 10-15), Metal Gear Solid Master Collection (PPSA18194) dies 0 s in on main: EXIT-139 with no message, 5 of 5 runs on 82ddae75b (one of them with #6814 applied). Before #5092 its Unity launcher ran. In the 10-15 sweep (0029e62f9) it reached its LoadExec into mgs4/mgs4.elf at 30 s, a 30 s run on that build reaches the limit, and with #5092 reverted on 82ddae75b it reaches the limit 2 of 2.

What happens:

  1. The title ships its own libc.prx. At start, that libc initializes the title's malloc replacement, and Unity puts its heap in a 256 MiB direct mapping at 0x200000000.
  2. IL2CPP's GC looks up scriptingGetMem by name (the only hook name in Il2cppUserAssemblies.prx) and now finds #5092's hook. The hook allocates through ApplicationHeapAlign. That heap is not initialized in this process (_init_env belongs to the title's own libc), so the lazy initialization from #4774 reads the same replacement table from the process parameters and calls its initialize callback a second time.
  3. Unity starts a second heap. With APS5_TRACE_MEMORY=1, a new 256 MiB mapping at 0x215000000 appears right before the four scriptingGetMem(0x1000, 0x40000) calls. The run with #5092 reverted makes no such mapping.
  4. The next free of a block from the first heap fails dlmalloc's least_addr check (the core has mspace_free(0x215000010, 0x200001060)). The player then calls the title libc's abort (int 0x45), which ends the process with SIGSEGV.

How

The two hooks now allocate and free through libc's own guest heap (GuestHeapAlign / GuestHeapFree) instead of the title's registered allocator, so calling them never initializes that allocator. The alignment rules stay as #5092 made them. A size that overflows now returns null instead of throwing. The debt entry records why, and that which console library exports the hooks is still unknown.

Tested

Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti (NVIDIA 595.99).

  • New application_heap_scripting: with the process parameters installed and the heap not yet initialized, two scriptingGetMem(0x1000, 0x40000) blocks are 4 KiB-aligned, distinct and writable. Neither they nor their frees reach the registered allocator, and _init_env afterwards initializes it exactly once.
  • The replacement-mode assertions now check that the hooks do not reach the registered allocator: it sees no size and no free, and failing it does not affect them.
  • With main's ApplicationHeap.cpp, application_heap_scripting and application_heap_replacement fail. With the change, all 9 application_heap_* tests pass 3 of 3, and the 396 tests matching application_heap|guest_|libc|getifaddrs|heap pass.
  • MGS4 Master Collection, pad input. On 82ddae75b it is EXIT-139 at 0 s. With this PR, 3 of 3 30 s runs reach the limit with the same log as the 10-15 build (542–553 lines, the same textures and asset bundles), and a 120 s run stops where the 10-15 sweep did: at 30 s, on sceWebBrowserDialogOpenForPredeterminedContent not implemented (open #5904 and #6092).
  • Throwaway builds while narrowing it down:
scriptingGetMem variant MGS4
#5092 (title allocator), blocks zero-filled (they already were) EXIT-139 0 s
title allocator, 64 KiB padding after each block EXIT-139 0 s
title allocator, 64 KiB padding before each block EXIT-139 0 s
fresh anonymous mappings 30 s limit, 21 calls, no scriptingFreeMem

So the contents and bounds of the blocks don't matter; reaching the title's allocator does.

@mrfelek found the same crash in Hollow Knight: Silksong (PPSA12544), another IL2CPP title with its own libc.prx. On main af7db81e6 it segfaults about 30 s in. With #5092 reverted, or with this PR (35ea8317e), it runs at about 1,050–1,200 presents per 10 s. Their git bisect --first-parent also lands on #5092's merge.

@karimibrahim07 checked it on Windows (Windows 11, WinLibs GCC 15.2.0, Release). All 9 application_heap_* tests pass 3 of 3. With main's ApplicationHeap.cpp, application_heap_scripting and application_heap_replacement fail, the same two as on Linux.

@utajum confirmed it on God of War: Sons of Sparta (PPSA28997) on Linux with RADV (Ryzen Z2 Go, Mesa 26.2.0-devel), on main e09dbc2b4. That title ships its own libc.prx, so it is this PR's case, not #694's. On main it segfaults at start-up right after global-metadata.dat opens, in the same il2cpp_init → title free → title abort chain as MGS4. With this PR's ApplicationHeap.cpp it boots, loads a save and plays, in 10 runs of 75–180 s with no crash.

@imellag checked it on macOS (Apple M4 Pro, Rosetta 2, MoltenVK 1.4.2), with this head merged into #7332, which adds the macOS runtime. The 9 application_heap_* tests pass, and with the earlier ApplicationHeap.cpp the same two abort. God of War: Sons of Sparta segfaults about a second after global-metadata.dat opens without this PR, in the same chain, and with it the game reaches gameplay.

Not checked: a Unity title that runs on AnyPS5's libc, whose GC now gets its blocks from libc's heap instead of the title's allocator.

#6713 edits the same files for executables without process parameters; it does not touch these functions. @karimibrahim07 moved #6713's test block and debt line (668d51adb), so the two merge cleanly in either order.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA18194 (Metal Gear Solid Master Collection launcher)
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99, Ubuntu 24.04
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4889514847 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T14:04:55Z. --- ### What Since #5092 (merged 10-15), Metal Gear Solid Master Collection (PPSA18194) dies 0 s in on `main`: `EXIT-139` with no message, 5 of 5 runs on 82ddae75b (one of them with #6814 applied). Before #5092 its Unity launcher ran. In the 10-15 sweep (0029e62f9) it reached its `LoadExec` into `mgs4/mgs4.elf` at 30 s, a 30 s run on that build reaches the limit, and with #5092 reverted on 82ddae75b it reaches the limit 2 of 2. What happens: 1. The title ships its own `libc.prx`. At start, that libc initializes the title's malloc replacement, and Unity puts its heap in a 256 MiB direct mapping at `0x200000000`. 2. IL2CPP's GC looks up `scriptingGetMem` by name (the only hook name in `Il2cppUserAssemblies.prx`) and now finds #5092's hook. The hook allocates through `ApplicationHeapAlign`. That heap is not initialized in this process (`_init_env` belongs to the title's own libc), so the lazy initialization from #4774 reads the same replacement table from the process parameters and calls its initialize callback a second time. 3. Unity starts a second heap. With `APS5_TRACE_MEMORY=1`, a new 256 MiB mapping at `0x215000000` appears right before the four `scriptingGetMem(0x1000, 0x40000)` calls. The run with #5092 reverted makes no such mapping. 4. The next `free` of a block from the first heap fails dlmalloc's `least_addr` check (the core has `mspace_free(0x215000010, 0x200001060)`). The player then calls the title libc's `abort` (`int 0x45`), which ends the process with SIGSEGV. ### How The two hooks now allocate and free through libc's own guest heap (`GuestHeapAlign` / `GuestHeapFree`) instead of the title's registered allocator, so calling them never initializes that allocator. The alignment rules stay as #5092 made them. A size that overflows now returns null instead of throwing. The debt entry records why, and that which console library exports the hooks is still unknown. ### Tested Ubuntu 24.04, GCC 13.3, Release, RTX 4070 Ti (NVIDIA 595.99). - New `application_heap_scripting`: with the process parameters installed and the heap not yet initialized, two `scriptingGetMem(0x1000, 0x40000)` blocks are 4 KiB-aligned, distinct and writable. Neither they nor their frees reach the registered allocator, and `_init_env` afterwards initializes it exactly once. - The replacement-mode assertions now check that the hooks do not reach the registered allocator: it sees no size and no free, and failing it does not affect them. - With `main`'s `ApplicationHeap.cpp`, `application_heap_scripting` and `application_heap_replacement` fail. With the change, all 9 `application_heap_*` tests pass 3 of 3, and the 396 tests matching `application_heap|guest_|libc|getifaddrs|heap` pass. - MGS4 Master Collection, pad input. On 82ddae75b it is `EXIT-139` at 0 s. With this PR, 3 of 3 30 s runs reach the limit with the same log as the 10-15 build (542–553 lines, the same textures and asset bundles), and a 120 s run stops where the 10-15 sweep did: at 30 s, on `sceWebBrowserDialogOpenForPredeterminedContent not implemented` (open #5904 and #6092). - Throwaway builds while narrowing it down: | `scriptingGetMem` variant | MGS4 | |---|---| | #5092 (title allocator), blocks zero-filled (they already were) | `EXIT-139` 0 s | | title allocator, 64 KiB padding after each block | `EXIT-139` 0 s | | title allocator, 64 KiB padding before each block | `EXIT-139` 0 s | | fresh anonymous mappings | 30 s limit, 21 calls, no `scriptingFreeMem` | So the contents and bounds of the blocks don't matter; reaching the title's allocator does. @mrfelek [found the same crash in Hollow Knight: Silksong](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6226045804) (PPSA12544), another IL2CPP title with its own `libc.prx`. On `main` af7db81e6 it segfaults about 30 s in. With #5092 reverted, or with this PR (`35ea8317e`), it runs at about 1,050–1,200 presents per 10 s. Their `git bisect --first-parent` also lands on #5092's merge. @karimibrahim07 [checked it on Windows](https://github.com/boykopovar/AnyPS5/pull/6842#pullrequestreview-5555933162) (Windows 11, WinLibs GCC 15.2.0, Release). All 9 `application_heap_*` tests pass 3 of 3. With `main`'s `ApplicationHeap.cpp`, `application_heap_scripting` and `application_heap_replacement` fail, the same two as on Linux. @utajum [confirmed it on God of War: Sons of Sparta](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6234256861) (PPSA28997) on Linux with RADV (Ryzen Z2 Go, Mesa 26.2.0-devel), on `main` e09dbc2b4. That title ships its own `libc.prx`, so it is this PR's case, not #694's. On `main` it segfaults at start-up right after `global-metadata.dat` opens, in the same `il2cpp_init` → title `free` → title `abort` chain as MGS4. With this PR's `ApplicationHeap.cpp` it boots, loads a save and plays, in 10 runs of 75–180 s with no crash. @imellag [checked it on macOS](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6252133867) (Apple M4 Pro, Rosetta 2, MoltenVK 1.4.2), with this head merged into #7332, which adds the macOS runtime. The 9 `application_heap_*` tests pass, and with the earlier `ApplicationHeap.cpp` the same two abort. God of War: Sons of Sparta segfaults about a second after `global-metadata.dat` opens without this PR, in the same chain, and with it the game reaches gameplay. Not checked: a Unity title that runs on AnyPS5's libc, whose GC now gets its blocks from libc's heap instead of the title's allocator. #6713 edits the same files for executables without process parameters; it does not touch these functions. @karimibrahim07 moved #6713's test block and debt line (668d51adb), so the two merge cleanly in either order. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA18194 (Metal Gear Solid Master Collection launcher) - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99, Ubuntu 24.04 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-16 14:39:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T14:39:53Z.


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 3987 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 6044 core/libs/prx/libc/CMakeLists.txt
core/libs/tests/ApplicationHeap.cpp
PR 6079 core/libs/prx/libc/CMakeLists.txt
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 6975 docs/dev/debt/libc.md
PR 7039 docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7084 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/prx/libc/CMakeLists.txt
core/libs/tests/ApplicationHeap.cpp
PR 7386 docs/dev/debt/libc.md
PR 7417 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7525 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 7715 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6217903442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6217903442). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T14:39:53Z. --- <!-- pr-overlap --> 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 3987](https://www.github.com/boykopovar/AnyPS5/pull/3987) | `docs/dev/debt/libc.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libc/CMakeLists.txt`<br>`core/libs/tests/ApplicationHeap.cpp` | | [PR 6079](https://www.github.com/boykopovar/AnyPS5/pull/6079) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 6975](https://www.github.com/boykopovar/AnyPS5/pull/6975) | `docs/dev/debt/libc.md` | | [PR 7039](https://www.github.com/boykopovar/AnyPS5/pull/7039) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libc/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 7084](https://www.github.com/boykopovar/AnyPS5/pull/7084) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/CMakeLists.txt`<br>`core/libs/tests/ApplicationHeap.cpp` | | [PR 7386](https://www.github.com/boykopovar/AnyPS5/pull/7386) | `docs/dev/debt/libc.md` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `core/libs/prx/libc/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7525](https://www.github.com/boykopovar/AnyPS5/pull/7525) | `core/libs/prx/libc/CMakeLists.txt`<br>`docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `core/libs/prx/libc/CMakeLists.txt`<br>`docs/dev/debt/libc.md` |
milescoviello commented 2026-10-16 21:28:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T21:28:46Z.


An independent bisect agrees. I bisected main (first-parent, 115 merges between b4a4fcac0 and 1b1f8483c) for this title's start-up crash, classifying each run by whether the fault is in the title's sce_module/libc.prx.guest.prx. It lands on #5092 (7663bc63b) as the first bad merge; c10aa036d, the merge before it, runs.

On current main bc3c0fc13 with #6814 and #6237 merged (Linux, RTX 4070 Ti, pad input), the title still dies at 0 s with the fault in its own libc. With this PR added (35ea8317e, on the slightly newer main 0dc15620d with the same two PRs), 2 of 2 runs reach the 180 s limit, and the launcher's LoadExec into mgs4/mgs4.elf happens in both. #5904 is on main now, so this PR and #6237 are what stand between main and the game here.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225048445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6225048445). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T21:28:46Z. --- An independent bisect agrees. I bisected `main` (first-parent, 115 merges between b4a4fcac0 and 1b1f8483c) for this title's start-up crash, classifying each run by whether the fault is in the title's `sce_module/libc.prx.guest.prx`. It lands on #5092 (7663bc63b) as the first bad merge; c10aa036d, the merge before it, runs. On current `main` bc3c0fc13 with #6814 and #6237 merged (Linux, RTX 4070 Ti, pad input), the title still dies at 0 s with the fault in its own libc. With this PR added (35ea8317e, on the slightly newer `main` 0dc15620d with the same two PRs), 2 of 2 runs reach the 180 s limit, and the launcher's `LoadExec` into `mgs4/mgs4.elf` happens in both. #5904 is on `main` now, so this PR and #6237 are what stand between `main` and the game here. AI-assisted: yes
mrfelek commented 2026-10-16 22:40:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-16T22:40:32Z.


Hollow Knight: Silksong (PPSA12544), another IL2CPP title that ships its own libc.prx, has the same startup crash since #5092, and this PR fixes it.

Linux, Ryzen 9 5950X, RTX 3080 Ti, NVIDIA 615.71.09, GCC 15.3, Release:

Build Result
main af7db81e6 segfault about 30 s in, right after global-metadata.dat is opened, no frames
main af7db81e6 with aea1dd601 (#5092) reverted runs, ~1,050–1,200 presents / 10 s
main af7db81e6 + this PR (35ea8317e) runs, ~1,080–1,200 presents / 10 s

A git bisect --first-parent from 14036cb0e (Oct 13, good) to af7db81e6, keeping the Oct 13 relink fixed, also lands on the #5092 merge (7663bc63b).

AI-assisted: this comment was drafted with the help of Claude Code and checked against the logs by us.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226045804 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6226045804). Originally posted by [mrfelek](https://github.com/mrfelek) on 2026-10-16T22:40:32Z. --- Hollow Knight: Silksong (PPSA12544), another IL2CPP title that ships its own `libc.prx`, has the same startup crash since #5092, and this PR fixes it. Linux, Ryzen 9 5950X, RTX 3080 Ti, NVIDIA 615.71.09, GCC 15.3, Release: | Build | Result | |---|---| | `main` `af7db81e6` | segfault about 30 s in, right after `global-metadata.dat` is opened, no frames | | `main` `af7db81e6` with `aea1dd601` (#5092) reverted | runs, ~1,050–1,200 presents / 10 s | | `main` `af7db81e6` + this PR (`35ea8317e`) | runs, ~1,080–1,200 presents / 10 s | A `git bisect --first-parent` from `14036cb0e` (Oct 13, good) to `af7db81e6`, keeping the Oct 13 relink fixed, also lands on the #5092 merge (`7663bc63b`). AI-assisted: this comment was drafted with the help of Claude Code and checked against the logs by us.
milescoviello commented 2026-10-17 03:31:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T03:31:27Z.


Thanks @mrfelek. A second IL2CPP title, with an independent bisect that lands on #5092, makes this much clearer. I added it to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6229071165 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6229071165). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T03:31:27Z. --- Thanks @mrfelek. A second IL2CPP title, with an independent bisect that lands on #5092, makes this much clearer. I added it to the description. AI-assisted: yes (Claude Code)
karimibrahim07 commented 2026-10-17 03:52:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-17T03:52:25Z.

Review: COMMENTED


Windows check, since the description lists it as not checked. Head 35ea8317e merged onto main e3a8e4430 (clean merge). Windows 11 Pro (26300), Ryzen 5 3600, WinLibs GCC 15.2.0 r7, Ninja Release.

  • All 9 application_heap_* tests pass, --repeat until-fail:3, application_heap_scripting included.
  • Negative control: with main's ApplicationHeap.cpp and this PR's test, application_heap_scripting and application_heap_replacement fail (0xc0000409), the same two tests as on Linux.

Overlap with #6713 (mine): the bot found a textual conflict in ApplicationHeap.cpp (tests) and docs/dev/debt/libc.md, because both PRs added a block right after the lazy case and a line under the scriptingGetMem entry. I moved #6713's test block and debt line away from yours (668d51adb), so the two now merge cleanly in either order. With both merged onto main, all 10 application_heap_* tests pass 3 of 3. As you say, #6713 doesn't touch these two functions: it only changes ApplicationHeapInitialize for a null process-parameters pointer. With both applied, the hooks still never reach the registered allocator.

Code: routing the hooks to GuestHeap instead of ApplicationHeapAlign makes sense given the MGS4 and Silksong results: those titles' own libc owns the registered allocator, and the hooks were initializing it a second time. Catching std::length_error alongside bad_alloc matches the new SIZE_MAX check. I have no code requests.

Not checked here: a title. I don't have MGS4, Silksong or a Unity title that uses AnyPS5's own libc (the PPSA28997 case you mention). For that case the GC's blocks now come from libc's heap instead of the title's allocator, so a run of it would be the useful remaining evidence.

AI-assisted: yes. I ran the build, the tests and the negative control above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5555933162 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#pullrequestreview-5555933162). Originally posted by [karimibrahim07](https://github.com/karimibrahim07) on 2026-10-17T03:52:25Z. **Review:** COMMENTED --- Windows check, since the description lists it as not checked. Head `35ea8317e` merged onto `main` `e3a8e4430` (clean merge). Windows 11 Pro (26300), Ryzen 5 3600, WinLibs GCC 15.2.0 r7, Ninja Release. - All 9 `application_heap_*` tests pass, `--repeat until-fail:3`, `application_heap_scripting` included. - Negative control: with `main`'s `ApplicationHeap.cpp` and this PR's test, `application_heap_scripting` and `application_heap_replacement` fail (`0xc0000409`), the same two tests as on Linux. **Overlap with #6713 (mine):** the bot found a textual conflict in `ApplicationHeap.cpp` (tests) and `docs/dev/debt/libc.md`, because both PRs added a block right after the `lazy` case and a line under the `scriptingGetMem` entry. I moved #6713's test block and debt line away from yours (668d51adb), so the two now merge cleanly in either order. With both merged onto `main`, all 10 `application_heap_*` tests pass 3 of 3. As you say, #6713 doesn't touch these two functions: it only changes `ApplicationHeapInitialize` for a null process-parameters pointer. With both applied, the hooks still never reach the registered allocator. **Code:** routing the hooks to `GuestHeap` instead of `ApplicationHeapAlign` makes sense given the MGS4 and Silksong results: those titles' own libc owns the registered allocator, and the hooks were initializing it a second time. Catching `std::length_error` alongside `bad_alloc` matches the new `SIZE_MAX` check. I have no code requests. Not checked here: a title. I don't have MGS4, Silksong or a Unity title that uses AnyPS5's own libc (the PPSA28997 case you mention). For that case the GC's blocks now come from libc's heap instead of the title's allocator, so a run of it would be the useful remaining evidence. AI-assisted: yes. I ran the build, the tests and the negative control above.
milescoviello commented 2026-10-17 03:58:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T03:58:16Z.


Thanks @karimibrahim07 for the Windows run and the negative control, and for moving #6713's block so the two merge in either order. I added it to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6229350217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6229350217). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T03:58:16Z. --- Thanks @karimibrahim07 for the Windows run and the negative control, and for moving #6713's block so the two merge in either order. I added it to the description. AI-assisted: yes (Claude Code)
utajum commented 2026-10-17 13:08:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by utajum on 2026-10-17T13:08:47Z.


Confirmed on PPSA28997 (God of War: Sons of Sparta), Linux, RADV (Ryzen Z2 Go / REMBRANDT, Mesa 26.2.0-devel), main e09dbc2b4.

PPSA28997 ships its own sce_module/libc.prx, so it is the title-libc case, not the #694 one.

  • main: SIGSEGV at start-up, right after global-metadata.dat opens. Core: il2cpp_init -> title libc free (tIhsqj0qsFE) -> eboot allocator -> title libc abort (L1SBTkC+Cvw). Same chain as MGS4.
  • main + this PR's ApplicationHeap.cpp: boots, reaches the title screen, loads an existing save and plays. 10 runs of 75-180 s, no crash.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234256861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6234256861). Originally posted by [utajum](https://github.com/utajum) on 2026-10-17T13:08:47Z. --- Confirmed on PPSA28997 (God of War: Sons of Sparta), Linux, RADV (Ryzen Z2 Go / REMBRANDT, Mesa 26.2.0-devel), main e09dbc2b4. PPSA28997 ships its own `sce_module/libc.prx`, so it is the title-libc case, not the #694 one. - main: SIGSEGV at start-up, right after `global-metadata.dat` opens. Core: `il2cpp_init` -> title libc `free` (tIhsqj0qsFE) -> eboot allocator -> title libc `abort` (L1SBTkC+Cvw). Same chain as MGS4. - main + this PR's `ApplicationHeap.cpp`: boots, reaches the title screen, loads an existing save and plays. 10 runs of 75-180 s, no crash.
milescoviello commented 2026-10-17 13:32:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T13:32:01Z.


Thanks @utajum, that's a useful run. It's a third IL2CPP title with its own libc.prx, after MGS4 and Silksong, and it's also the first RADV result for this PR. I'd listed PPSA28997 as the #694 case under "Not checked", which was wrong. I've corrected that and added your run to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234476780 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6234476780). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T13:32:01Z. --- Thanks @utajum, that's a useful run. It's a third IL2CPP title with its own `libc.prx`, after MGS4 and Silksong, and it's also the first RADV result for this PR. I'd listed PPSA28997 as the #694 case under "Not checked", which was wrong. I've corrected that and added your run to the description. AI-assisted: yes (Claude Code)
imellag commented 2026-10-18 16:12:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-18T16:12:42Z.


Checked on macOS: Apple M4 Pro, macOS 27.0.1 (26A434), Rosetta 2, Apple clang 21.0.0, Vulkan SDK 1.4.363.0 (MoltenVK 1.4.2). main has no macOS runtime yet, so this is head b4e129ff8 merged into #7332 (690c044a6 merged into main a62c724c3), no conflicts, x86-64 build under Rosetta.

  • application_heap_*: 9/9, and again with --repeat until-fail:3. With the merge's ApplicationHeap.cpp swapped for the one before this PR, application_heap_replacement and application_heap_scripting abort, the same two as on Linux and Windows.
  • God of War: Sons of Sparta (PPSA28997, 01.008.001): without this PR the process ends with SIGSEGV about a second after global-metadata.dat opens, with nothing in the log. A temporary report in the write watch's fault handler (local only) shows the chain described above: the fault is the int $0x45 in the title libc's abort (L1SBTkC+Cvw), called from the eboot under the title libc's free (tIhsqj0qsFE), called from Il2cppUserAssemblies. With this PR the title starts, loads its FMOD banks and reaches gameplay. That run also needs a local workaround for a separate macOS module-loading stop, reported on #7332.

Not checked: other titles on macOS.

AI-assisted: yes (Claude Code). I ran all of the above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252133867 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6252133867). Originally posted by [imellag](https://github.com/imellag) on 2026-10-18T16:12:42Z. --- Checked on macOS: Apple M4 Pro, macOS 27.0.1 (26A434), Rosetta 2, Apple clang 21.0.0, Vulkan SDK 1.4.363.0 (MoltenVK 1.4.2). `main` has no macOS runtime yet, so this is head `b4e129ff8` merged into #7332 (`690c044a6` merged into `main` `a62c724c3`), no conflicts, x86-64 build under Rosetta. - `application_heap_*`: 9/9, and again with `--repeat until-fail:3`. With the merge's `ApplicationHeap.cpp` swapped for the one before this PR, `application_heap_replacement` and `application_heap_scripting` abort, the same two as on Linux and Windows. - God of War: Sons of Sparta (PPSA28997, 01.008.001): without this PR the process ends with SIGSEGV about a second after `global-metadata.dat` opens, with nothing in the log. A temporary report in the write watch's fault handler (local only) shows the chain described above: the fault is the `int $0x45` in the title libc's `abort` (`L1SBTkC+Cvw`), called from the eboot under the title libc's `free` (`tIhsqj0qsFE`), called from `Il2cppUserAssemblies`. With this PR the title starts, loads its FMOD banks and reaches gameplay. That run also needs a local workaround for a separate macOS module-loading stop, reported on #7332. Not checked: other titles on macOS. AI-assisted: yes (Claude Code). I ran all of the above on my machine.
milescoviello commented 2026-10-18 18:45:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T18:45:40Z.


Thanks @imellag for the macOS run and the Sons of Sparta check. I added it to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253709932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6253709932). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T18:45:40Z. --- Thanks @imellag for the macOS run and the Sons of Sparta check. I added it to the description. AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-19 12:04:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T12:04:28Z.


Checked the two hooks against GuestHeap (alignment and overflow paths: length_error is thrown at GuestHeap.cpp:75/266 and now returns null), the new application_heap_scripting test (registered in ctest and in the Windows PATH list; it pins no allocator init/free before _init_env, so it fails on main), and the updated libc debt entry. Windows, macOS and three titles confirmed by the reviewers above; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6266767637 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6266767637). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T12:04:28Z. --- Checked the two hooks against `GuestHeap` (alignment and overflow paths: `length_error` is thrown at GuestHeap.cpp:75/266 and now returns null), the new `application_heap_scripting` test (registered in ctest and in the Windows PATH list; it pins no allocator init/free before `_init_env`, so it fails on `main`), and the updated libc debt entry. Windows, macOS and three titles confirmed by the reviewers above; merged.
madkyp commented 2026-10-19 17:29:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by madkyp on 2026-10-19T17:29:56Z.


Also fixes Plants vs. Zombies™: Replanted (PPSA29802, #6404): on Linux 47a266c it aborted in the title's free() (chunk from the first application heap at 0x200000000 freed into the second at 0x215e00000). On main 7a015c094 it reaches the profile menu and runs 3 min without a fatal. Ryzen 7 9800X3D + RX 9070 XT (RADV, Mesa 26.2.4), CachyOS.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273192732 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6273192732). Originally posted by [madkyp](https://github.com/madkyp) on 2026-10-19T17:29:56Z. --- Also fixes Plants vs. Zombies™: Replanted (PPSA29802, #6404): on Linux 47a266c it aborted in the title's `free()` (chunk from the first application heap at 0x200000000 freed into the second at 0x215e00000). On main 7a015c094 it reaches the profile menu and runs 3 min without a fatal. Ryzen 7 9800X3D + RX 9070 XT (RADV, Mesa 26.2.4), CachyOS.
milescoviello commented 2026-10-19 17:40:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T17:40:25Z.


@madkyp thanks for the report. Good to know Plants vs. Zombies: Replanted (PPSA29802) had the same cross-heap free() abort (a chunk from the first application heap freed into the second) and now reaches the profile menu on main 7a015c094 and runs 3 minutes without a fatal. #6404 returns a 404 for me, so if it lives somewhere else (a discussion?), feel free to link this there.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273411692 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6842#issuecomment-6273411692). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-19T17:40:25Z. --- @madkyp thanks for the report. Good to know Plants vs. Zombies: Replanted (PPSA29802) had the same cross-heap `free()` abort (a chunk from the first application heap freed into the second) and now reaches the profile menu on `main` 7a015c094 and runs 3 minutes without a fatal. #6404 returns a 404 for me, so if it lives somewhere else (a discussion?), feel free to link this there. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6842
No description provided.