fix(libkernel): report the largest free direct memory block from sceKernelAvailableDirectMemorySize #3292
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3292"
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 reyani-dev on 2026-10-11T05:42:52Z.
What
Carries the first of @xXPBSXx's two fixes from #3143, which was shared as a branch while intake was paused. The commit is theirs, unchanged (
aace6a3f), and merges cleanly onto currentmain. I left out the second fix (sceKernelMprotecton host thread-stack memory) because it overlaps #2982.sceKernelAvailableDirectMemorySizeallocated one page, freed it, and reported the free run that starts at that first fitting page. So it returned the first gap in the search range, not the largest free block. In Resident Evil 4 (PPSA07411) on Windows, it reported about 1.9 MiB and the title's 96 MiB allocation then failed (#3143). The function now scans the range for the largest free page run, starting at the requested alignment, and reports that block. When nothing fits, it still returnsSCE_KERNEL_ERROR_EAGAINwith both outputs zeroed, the same code the old path got from the allocator. The scan walks the same per-page bitmap thatAllocalready scans linearly.guest_memorygainsCheckAvailableDirectMemoryIsLargestFreeBlock. It leaves a 4 MiB hole between two 2 MiB blocks and checks:EAGAINwith zeroed outputs when nothing is free;EINVALfor a null output.Closes the first item of #3143.
Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, full build with
BUILD_TESTING=ON, the commit merged ontomain961b25fe:guest_memorypasses 3/3 (--repeat until-fail:3).DirectMemory/Export.cppreverted tomain, it fails at the first largest-block check (GuestMemory.cpp:1640).ctest -E "^agc_|video_out": 411/412. The one failure isguest_filesystem's symlink-creation check, because this account can't create symbolic links (#3169). It fails the same way onmain.check_conventions.py --base upstream/mainpasses, andpr_overlap.pyreports no overlap.The RE4 result is xXPBSXx's runtime finding in #3143; I don't have the title.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:25:49Z.
Additional platform validation of standalone PR head
aace6a3f38f91ea9e6c9239efdf54e1ae9a2a4bd(2026-10-11):Linux: passed — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release,
BUILD_TESTING=ON.1 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.
Checks:
guest_memory.Command after building:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_memory$".No title/gameplay validation. These results cover the standalone head, not a merge with current main.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:26:58Z.
Checked the diff against current
main, built it and ranguest_memory(passes; it fails with the three non-test files reverted).sceKernelAvailableDirectMemorySizenow reports the largest aligned free run clipped to the search window, which matches shadPS4'sDirectQueryAvailable; theEAGAINpath with zeroed outputs is unchanged from before. Merging.Not covered here: the RE4 behaviour on Windows (from #3143). Small nit for later: a doubled blank line before
CheckAvailableDirectMemoryIsLargestFreeBlockinGuestMemory.cpp.