Skip to content

fix(libc): keep a moved mspace block's usable bytes in realloc - #4880

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
David-cmrg:fix/libc-mspace-realloc-usable
Oct 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
David-cmrg:fix/libc-mspace-realloc-usable

Conversation

@David-cmrg

Copy link
Copy Markdown
Contributor

What

Fixes #4879.

sceLibcMspaceRealloc and sceLibcMspaceReallocalign copied the size a block was last requested with when they had to move it, not its usable size.

A caller may use every byte sceLibcMspaceMallocUsableSize reports, 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_realloc does (chunksize(oldp) - overhead_for(oldp)). The chunk no longer records the requested size, which nothing else read.

mspace gains CheckMovedBlockKeepsUsableBytes: a 1-byte block whose usable bytes are all written keeps them when sceLibcMspaceRealloc or sceLibcMspaceReallocalign moves it.

Tested

Fedora 44, GCC 16.2.1, Release, main 0c3dc9ca2.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA99008 ProsperoEden (PPSA99008) #4852
  • AI-assisted: yes (Claude Opus 5.5)

@oneandonlydean oneandonlydean self-assigned this Oct 13, 2026
@oneandonlydean
oneandonlydean merged commit 495bf91 into boykopovar:main Oct 13, 2026
13 checks passed
@Scramblrrrr

Copy link
Copy Markdown
Contributor

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc: mspace realloc keeps only the requested bytes of a moved block (ProsperoEden launcher crash since #4407)

3 participants