fix(libc): skip holes inside an allocation when unmapping a range #3440
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3440"
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 alfalfa-star on 2026-10-11T10:34:51Z.
What
A fixed direct mapping whose range starts in a hole inside an earlier allocation aborts with:
The call path is
sceKernelBatchMap2→DoMapDirect→ReplaceFixedOverlap→UnmapRegistered→GuestAllocationsUnmap→replaceRange.Title: RIDE 4 (PPSA01599, Unreal Engine 4) on main
8ec0e131, a few seconds in, before any window. Under gdb (ReplaceFixedOverlapbreakpoint plusAPS5_TRACE_MEMORY=1):0x2008e40000+0x2000000, which is part of a larger direct mapping.0x10) at0x2009d20000+0x1790000. That range starts inside the unmapped part and ends in the still-mapped rest.On FreeBSD both the munmap and the fixed map over a partly unmapped range are legal.
Cause:
GuestAllocationsUnmapdecides which range contains the cursor from the allocation's original extent (allocationAddress + allocationBytes), and runs each piece to that extent's end.replaceRangethen meets the hole and throws.Holes between allocations were already skipped (
962fc34e); holes inside one were not.Fix
Two lines: test containment against the registered range itself (
address + bytes), and end each piece at that range's end. A cursor in a hole then moves on to the next registered range, exactly as between allocations.lastis still computed from what remains of the allocation, so the Windowsmunmap_releaseof the whole allocation happens on the same final piece as before.Tested
Linux (Arch), GCC, Release, on main
99c1c263.guest_memorycaseCheckFixedMappingOverHoleInsideAllocation:sceKernelMunmap;ctest: 825/825 (4 video-out flip tests skipped as usual).tools/check_conventions.pypasses.Note: TibixDev's stacked series (#1324 and the PRs built on it) edits the
lastcheck a few lines below. It doesn't touch these lines, but it may need a trivial rebase.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 adriadam10 on 2026-10-11T10:46:01Z.
Checked build and ctest on the PR merged onto main:
guest_memorypasses with the change and the newCheckFixedMappingOverHoleInsideAllocationfails without it. The fix is correct: containment and piece end now use the registered range, so a cursor in a hole inside an allocation moves on like one between allocations, andlastis unchanged. Merging.