feat(libSceJemspace): implement arena allocation and statistics #9855
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9855"
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 kyon-eth on 2026-10-22T19:03:04Z.
What
Draft follow-up to #9452. Current main integrated:
c2c852d0ec3.Implement all 13 discovered libSceJemspace exports: arena lifecycle, allocation/reallocation, usable size, statistics snapshots, purge and callback reports. Preserve allocation ownership, per-arena limits, failure outputs and the observed size/alignment rules.
Build pinned public jemalloc 5.2.0 directly with CMake from its Git submodule. Configure headers with compiler feature/type probes and generate private-symbol mappings with the compiler toolchain's nm. Replace its page layer with guest kernel mappings and implement the module's extent accounting. Keep allocator internals hidden from NID exports and package its license. No Autoconf, Bash, external Make build, CI tool installation or conventions-checker exception is required.
Contracts were inspected at
0x51cb0–0x526ceand the page layer at0x3a470–0x3a75b. The firmware version is unverified. Both newly resolved names reproduce their NIDs:sceJemspacePurge=s686MsLMwns,sceJemspacePrintStats=4aop4GKLZaA.The inspected allocator identifies thirteen further commits unavailable upstream. Matching the exercised contracts does not establish equivalence for that entire delta. Reports intentionally describe the public backend. Remaining uncertainties are recorded in
docs/dev/debt/libSceJemspace.md.Tested
Current-main validation (2026-10-30): merged main
c2c852d0ec3, retaining main's release-packaging changes. Both registered macOS x86-64 allocator/statistics tests pass (2/2). Conventions, whitespace and privacy checks pass. No allocator behavior was changed by this integration, and no new Linux/Windows execution or game result is claimed.C-standard follow-up:
libSceJemspacenow requires C11, matching the allocator and symbol-probe targets. Reproduced the reportedATOMIC_VAR_INITfailure inGuestPages.con macOS/Clang with-DCMAKE_C_STANDARD=23. With the target property added and that global setting retained, the generated compile command uses-std=gnu11and both registered Jemspace tests pass. The ordinary x86_64/Rosetta configuration also builds and passes both tests. These runs use the boundary composition documented below.The independent Windows 11 / WinLibs GCC 15.2 report verified the preceding head with a global C11 workaround: both registered tests passed against the real Windows libc/libkernel, including combined unmap, guard preservation and range reuse. This target-local fix removes the need for that global workaround; Windows execution of this new commit still needs CI confirmation.
Review follow-up: probe the
strerror_rreturn type under_GNU_SOURCEwith compiler warnings treated as errors, matching jemalloc's upstream detection. DefineJEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCEonly when that probe succeeds. macOS retains its POSIX/int path; glibc/GNU compilation still needs the maintainer's Linux CI run.The registered allocator test now links libkernel explicitly and exercises the mapping assumption used when extents coalesce: create two adjacent guest mappings plus a guard, unmap the combined range, query both original addresses to ensure neither remains mapped, preserve the guard, then reuse the combined range with zeroed contents and clean up. This models a merged extent at the kernel boundary; it does not claim to force jemalloc's internal coalescing scheduler or prove Windows execution locally. Both tests pass again on macOS ARM64 and x86_64 with the documented boundary adapter. Full Linux/Windows jobs were skipped on the preceding head and require a maintainer-triggered run for this update.
ctest --test-dir <build> --output-on-failure:guest_jemspace_allocatorandguest_jemspace_statsboth pass per architecture. This rerun uses realApplicationHeap.cppinitialization and allocation dispatch with the in-tree test's replacement metadata; guest kernel mappings and unused default-heap boundaries remain substituted. It is not a complete libc/kernel integration build.c430b3a05dguest-heap test setup is retained. CI build/release workflows and conventions tooling have no changes relative to main; the earlier tool-install steps and checker exception are removed.Overlap scan against current
main: #9452 is the declaration dependency. #9347 independently adds Vorbis/OGG submodule entries and packaging tests at shared insertion points; preserve both sets on merge. The scanner could not compare shared files in #674, #1835, #5021, #5797, #6044, #6879, #8619 and #8739 because those branches conflict withmain. The shared changes concern build documentation, input/AOT/wasm tooling, test paths and decoder licensing; they are not additional Jemspace implementations. Shared build/package edits require merge coordination if those branches land first.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 jotitadev on 2026-10-23T02:18:02Z.
Review: COMMENTED
macOS run with the real
libc.prx/libkernel.prxinstead of boundary fixtures. The allocator builds, butguest_jemspace_allocatoraborts as registered.Machine: Apple M2 Max, macOS 27.2, Apple clang 21, x86-64 build under Rosetta 2, Release,
BUILD_TESTING=ON, Python 3.9.6. Autoconf 2.73 (Homebrew) and/usr/bin/make(GNU Make 3.81).Base/method:
maindoesn't link on macOS, so the tree is #8658 (feat/macos-port) @c5fa39620a. This PR's diff at25e1e3bb9c(git diff merge-base..head -- . ':!docs') is applied on top..gitmodulesandtest_package_release.pyhad add/add conflicts with #8658's ogg/vorbis entries, and I kept both sides.3rdparty/jemallocis atb0b3e49a54. Fullcmake --build -j4.--with-jemalloc-prefix=anyps5_jemspace_ ... --disable-zone-allocator --with-lg-page=14and buildslibjemalloc.a.libSceJemspace.prxis x86-64 Mach-O.nm -gUlists exactly the 13sceJemspace*exports and nothing else.guest_jemspace_stats: passes.guest_jemspace_allocator: fails 3/3, the same way each time:The first
sceJemspaceCreate("invalid", 0, 1)returns as expected. The abort comes at the next create, wheresceJemspaceCreategets itsSpacefrommalloc_nid_postfix(Export.cpp:179). With the reallibc.prx, that goes throughApplicationHeapInitialize_nid_no_patch. It needs the process parameters, plus a libc parameter block with an allocator replacement table at+0x38/+0x30. The test executable has neither, andallocationOrNullonly catchesbad_alloc, so theruntime_errorescapes through theAPS5_VABIexport and terminates the process.As a check, I added
ProcessParametersFixture::Installwith a valid header (size 0x40, magic0x4942524f). The abort then moves toapplication heap: null metadata, the missing libc/replacement block. So the test needs a parameter fixture that registers a host-backed allocator, orSpaceneeds to come from somewhere other than the guest heap. I assume the run in the description passed because its OS-backed libc boundary fixture replaced this path.The failing path is
ApplicationProcessParameters/ApplicationHeap, which is shared with Linux (#elif defined(__linux__) || defined(__APPLE__)). So I expect a full Linux build to fail the same way, but I have only run it on macOS.Also, for BUILD.md: on macOS the build now needs Autoconf, which a stock Xcode install doesn't have (
brew install autoconfhere). The Make from Xcode's command-line tools is enough.Python 3.9.6 (Xcode's):
tools/tests/test_package_release.py40 passed (5 platform skips),tools/tests/test_check_conventions_comments.py72 passed.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T03:47:26Z.
Review: CHANGES_REQUESTED
I reviewed the registered CTest wiring and the independent macOS run against the actual
libc.prx/libkernel.prx.guest_jemspace_allocatoraborts on its secondsceJemspaceCreate:Export.cppobtains the arenaSpacewithmalloc_nid_postfix, which entersApplicationHeapInitializeand throws because the test executable has no process-parameter/libc replacement metadata. The current tests catch onlystd::bad_alloc, so this runtime error escapes and aborts the test. The out-of-tree OS-backed boundary fixture in the PR description does not exercise this registered executable path.Please make the in-tree registered allocator test runnable with the real linked libc path, for example by installing a valid process-parameter and allocator-replacement fixture or by allocating
Spacethrough a path that does not require an uninitialized guest application heap. Then rerunguest_jemspace_allocatorandguest_jemspace_statson a supported platform and report the exact commands/results. The current base-branch conventions check also fails on the new build-tool lookups; the PR documents that the checker exception itself needs base-branch integration, so that gate needs an explicit maintainership path before merge.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T08:03:30Z.
Review: COMMENTED
Follow-up to my earlier macOS report: on head
c430b3a05dtheguest_jemspace_allocatorabort is gone.Apple M2 Max, macOS 27.2, Apple clang 21.0.0 (Xcode 27), x86_64 under Rosetta, Release, system Python 3.9.6. Base is #8658 @
37a9a6b4be(main plus the macOS port) with this PR merged and the3rdparty/jemallocsubmodule checked out.guest_jemspace_statsandguest_jemspace_allocatorpass 3/3.c430b3a05dreverted,guest_jemspace_allocatorstill aborts withapplication heap: invalid or missing process parameters, so the new heap setup is what fixes it.tools/tests/test_check_conventions_comments.pyandtools/tests/test_package_release.pypass on Python 3.9.6 (5 skips in the latter).Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T22:21:06Z.
Review: CHANGES_REQUESTED
The previous blockers around the registered allocator test setup, Jemspace public declarations, and C11 compiler selection appear addressed in the current tree. The author reports both registered tests passing on macOS x86-64 and on a Windows head before the last current-main integration; the latter included the real linked libc/libkernel test path. I did not run these tests locally. Current hosted checks include successful eligibility and relinker jobs; full Linux/Windows product jobs are skipped.
The exact head
64d8650470407360c39c3b342f3ad1ddb5eac1d2is cleanly mergeable but is based on main9ae2f7d22a, 1,304 commits behind the current tip. Please update it to currentmainas required by the branch rule and rerunguest_jemspace_allocatorandguest_jemspace_statson that head, preferably on both Linux and Windows because the page adapter and toolchain detection are platform-sensitive. The existing detailed macOS and Windows evidence supports the design, but it does not cover the resulting current-main tree.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T06:48:37Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this review; the points below are optional.
What I ran
Reviewed head
4cb2235bc0d70b9fd6ca23ad5357f579371fa4bausing the prepared diff and the pinnedrepo_read.pyreader. No build or tests were run in this review.Results
Findings
Blocking
None identified in the code read.
Non-blocking
None.
Not verified
The review was incomplete: I did not read every changed file listed in the manifest or run checks. Files read:
description.md,commits.md,manifest.json,diff.patch; repository files.gitmodules,core/libs/prx/libSceJemspace/Export.cpp,core/libs/prx/libSceJemspace/Jemalloc.cmake,core/libs/prx/libSceJemspace/JemallocConfig.cmake, andcore/libs/prx/libSceJemspace/include/Api.hpp. The changed submodule pointer3rdparty/jemallocwas excluded from full text because it is not plain text. Other changed files were not read. Linux/Windows builds and execution, console behavior, and full integration were not verified here.To get this to a good state
Nothing is required. Optional: complete review of the unread changed files and run the relevant CI checks before making a formal merge decision.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:25:18Z.
Review: COMMENTED
Built the branch allocator against its pinned jemalloc source in a focused Linux CMake build. Both registered CTests passed, covering allocator operations and statistics.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.