feat(libc): provide the runtime scripting allocator hooks #5092
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5092"
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 MrMha on 2026-10-13T11:18:45Z.
What
Add the runtime allocator hooks requested in #694:
scriptingGetMem(alignment, size)calls the application allocator's aligned allocation, andscriptingFreeMem(pointer)frees through that same allocator. Alignments below 16 normalize to 16; larger non-powers of two return null. Null free is a no-op; allocation failure represented bystd::bad_allocreturns null; other allocator errors propagate.The signatures and source-based alignment contract remain documented in libc technical debt. NIDs:
scriptingGetMem→ayuoL6Vjz2k;scriptingFreeMem→yV45DG6ei28. This supplies the hooks, but does not claim complete resolution of the title's process-scope lookup path.Reapplied on main
2e5dd5aa144af1bf90a214a6341bf3e1b4e6d47a. Retained the newly mergedfdopendebt entry and added the scripting entry beside it; production and test changes apply cleanly.Tested
Fresh local checks on macOS 27.0.1 arm64, AppleClang 21, C++20,
-Wall -Wextra -Werror:ApplicationHeap.cppwith a controlled registered allocator. Native and ASan/UBSan executions pass eight normalization/alignment cases, writable storage, matching/null free, three invalid alignments without callback invocation, null/bad_alloc allocation failures, and propagation of callback/misalignment errors.core/libs/tests/ApplicationHeap.cpppasses-fsyntax-only.ApplicationHeap.cppbecause both scripting hooks are absent.Earlier Linux full linked regression evidence from @coltken95 at old head
a4e1104remains in the discussion; it was not rerun on this new head. Full runtime build/CTest, patched-libc process-scope lookup and title execution remain unverified on this head and need the maintainer-dispatched full build.Manual review of the bot-listed shared hunks found other libc debt entries, #4927's
getcwdassertion, #6217's default-heap statistics wiring and #6044's test relocation/labels. None adds these scripting hooks. If #6044 lands first, preserve the scripting assertions atcore/libs/tests/memory/ApplicationHeap.cpp. These are source comparisons, not combined runtime validation.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-13T11:36:08Z.
Progress report (
8dc92ae→aea1dd6)➖ System libraries: 88.7% (+0.0%, +2 implemented functions)
✅ 2 implemented
scriptingFreeMem_nid_postfixscriptingGetMem_nid_postfixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:07:58Z.
Ready to merge from my side, but the PR description fails the conventions check:
main; no other open PR implements the same functions (see outstanding work above)Please fill those template lines in (only you can answer AI-assisted); it merges once they pass.
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T18:52:12Z.
Tested on Linux x86-64 (Release build, CTest), with a4e110403 merged into main
9d0a41d5a:application_heap_replacement,application_heap_invalid_metadata,application_heap_defaultandapplication_heap_exit_orderall pass.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:07:22Z.
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.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/tests/ApplicationHeap.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by MrMha on 2026-10-15T13:26:19Z.
Rebased onto main
2e5dd5aa144af1bf90a214a6341bf3e1b4e6d47aasaea1dd601afd98233c22eb45131a80306b00976b. The documentation conflict is resolved by retaining both the mergedfdopennote and the scripting-hook note. The PR description/template now reflects this head and the current test limitations.Fresh macOS 27.0.1 arm64 / AppleClang 21 / C++20 checks: the actual production
ApplicationHeap.cpplinked to the controlled registered-allocator harness below passes natively and under ASan/UBSan. It checks eight normalization/alignment values, writable storage, matching/null free, three invalid alignments without calling the allocator, null andbad_allocfailures, and propagation of callback/misalignment errors. The updated repositoryApplicationHeap.cpptest also passes-fsyntax-only. With unchanged main's production file, the same harness fails to link because both hooks are absent. Trusted main conventions and whitespace checks pass.The aborting stand-ins below deliberately exclude default guest-heap/process-parameter execution: this is not a full libc or patched-export lookup test. The rebased head still needs the linked
application_heap_*runtime tests through the maintainer-dispatched full Build workflow before claiming full runtime validation. The older Linux linked-test result in this discussion is historical, not a fresh result on this head.Manually inspected the bot-listed shared hunks: the debt changes are other entries; #4927 changes
getcwdexpectations, #6217 wires default-heap statistics, and #6044 relocates/labels tests. None implements the scripting hooks. Preserve our assertions at the moved memory test path if #6044 lands first. No combined-runtime validation is claimed.Reproduce the focused custom-allocator check
Save the following as
allocator_harness.cppoutside the repository. From this checkout on macOS, build with AppleClang 21 (add the SDK libc++ include path if the local toolchain requires it):AI-assisted: yes (OpenAI Codex).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:30:20Z.
Checked on the current head: build + ctest of core/libs (105/105, incl. the eight
application_heap_*tests), and the new assertions fail to link without the change.scriptingGetMemmatches KytyPS5'sKernelApplicationHeapGetMem(alignment < 16 raised to 16, non-power-of-two returns null) and routes through the registered application allocator;scriptingFreeMemhandles null. The unverified signature of the free hook is recorded in the libc debt file. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T19:26:00Z.
Tested on Linux x86-64 (Release build, CTest), with
aea1dd601merged into main44df21632. This replaces my earlier result at a4e1104:application_heap_replacement,application_heap_invalid_metadata,application_heap_default,application_heap_exit_orderandapplication_heap_lazypass.libc/src/ApplicationHeap.cpp:application_heap_testsdoesn't link (undefined reference to 'scriptingGetMem_nid_postfix'and'scriptingFreeMem_nid_postfix'), since main doesn't provide the hooks.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T14:05:06Z.
Heads-up @MrMha: since this merged, Metal Gear Solid Master Collection (PPSA18194) aborts 0 s in on
main. The title ships its ownlibc.prx, which has already initialized its allocator. IL2CPP's firstscriptingGetMemcall then makes the application heap's lazy initialization run the title's allocator initializer a second time, and Unity's dlmalloc aborts on its nextfree. #6842 keeps the hooks but serves them from libc's own guest heap. The details and runs are there.AI-assisted: yes