fix(libc): return an aligned empty block from reallocalign to 0 bytes #11850
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11850"
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 ionut27001 on 2026-10-27T09:51:08Z.
What
With the default heap,
reallocalign(ptr, 0, alignment)threwstd::invalid_argumentwhen the block did not already have that alignment. Only the already-aligned case was handled.The evidence is the console log attached to the merged #11259 (gist,
preallign.console.log), taken in a payload process on a PS5 (firmware 13.60) withreallocalignfromlibSceLibcInternal.sprx. A block from that heap that was 64-aligned but not 256-aligned, given size 0 and alignment 256, came back as a different pointer, 256-aligned, withmalloc_usable_size0 anderrnostill 1234:This change returns a new empty block with the requested alignment in that case, as the console did. The old block stays allocated: the log does not show whether the console frees it, and leaving it is safe where freeing it would not be if the console keeps it. Alignment 0 or one that is not a power of two still throws in this path;
reallocaligninFileAndHeap.cpprounds the default heap's alignment up to a power of two of at least 32 before it gets here. The debt entry is cut to the open gap: the old block is left allocated because the console's handling of it is not known.Overlaps: no open PR mentions
reallocalign. #11468 changes other lines ofGuestHeapRealign_nid_postfixinGuestHeap.cpp;git merge-treeshows no conflict with this head.Tested
Windows 11, WinLibs GCC 15.2.0, Release, on
main801d5b9bc1:guest_reallocalignpasses twice. It now takes a block fromreallocalign(NULL, 24, 64)that is not 256-aligned and checks thatreallocalign(block, 0, 256)returns a different, 256-aligned block with 0 usable bytes anderrnounchanged.GuestHeap.cppfrommain, the test aborts (0xc0000409), because that call throws.Not tested on Linux, nor with a title.
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)