fix(libc): keep a moved mspace block's usable bytes in realloc #4880
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4880"
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 David-cmrg on 2026-10-13T01:42:38Z.
What
Fixes #4879.
sceLibcMspaceReallocandsceLibcMspaceReallocaligncopied the size a block was last requested with when they had to move it, not its usable size.A caller may use every byte
sceLibcMspaceMallocUsableSizereports, and ProsperoEden's cache of freed blocks does: it bins blocks by usable size and hands one out for any request up to its bin (headless/heap_arenas.inc). A block first allocated for 8 bytes can therefore carry 32 bytes, and moving it kept only 8. Since #4407 a request of 1 to 16 bytes has 32 usable bytes, which made this common enough to crash ProsperoEden's launcher.A moved block now keeps its old usable bytes, bounded by the new size, as dlmalloc's
mspace_reallocdoes (chunksize(oldp) - overhead_for(oldp)). The chunk no longer records the requested size, which nothing else read.mspacegainsCheckMovedBlockKeepsUsableBytes: a 1-byte block whose usable bytes are all written keeps them whensceLibcMspaceReallocorsceLibcMspaceReallocalignmoves it.Tested
Fedora 44, GCC 16.2.1, Release,
main0c3dc9ca2.mspace: with the test change alone it fails 3 of 3; with this change it passes 3 of 3.guest_reallocalign,guest_new_handler_default_heapand the sevenapplication_heap_*tests pass.--to-intel --trap-sdk-syscall-stubs, withdatain the run folder):launcher closed: no game (quit)), 2 of 2. The title then stops at exit on #4846.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 Scramblrrrr on 2026-10-13T02:39:23Z.
Windows cross-test of
00c35c159on the older experimental 007 integration, author-preserving port 93d6507e5edbb9470bcd4f37e87743b4a6d2e618 (parent 2086c5328). mspace, guest_reallocalign and all seven application_heap_* checks pass: 9/9, restored build 0.18 s. This older integration does not register guest_new_handler_default_heap, so that test is not included.Production-only negative: retained CheckMovedBlockKeepsUsableBytes, restored only Mspace.cpp from parent 2086c5328, rebuilt. mspace fails at the usable-byte check; the eight controls pass. Restored production, rebuilt and reran all nine successfully. Production code applied cleanly; test conflict resolved keeping the new fixture without importing unrelated newer allocator-alignment fixtures.
Separate 007 game comparison is now running with only libc changed, patched SHA256 DE052483D75B672DEFCF472C9CFDE0EBEC85723E318C4D3FFB81396489FD6C00; graphics remains FCB1B8FB... at 2086c5328. No claim yet that the title uses the affected allocator case, or that this fixes its renderer crash. No title code or captures uploaded. AI-assisted (Codex).