Repository navigation
fix(libc): keep a moved mspace block's usable bytes in realloc - #4880
Conversation
|
Windows cross-test of 00c35c1 on the older experimental 007 integration, author-preserving port 93d6507 (parent 2086c53). 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 2086c53, 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 2086c53. 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). |
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 libc: a guest free during exit waits 60 s for a lease and aborts after the AGC driver shut down (ProsperoEden quitting) #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)