fix(libc): align guest heap allocations to 32 bytes #1621
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1621"
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 TheAggie on 2026-10-08T15:05:35Z.
What
Clang's PS4/PS5 target sets the default new alignment and the suitable alignment to 32 bytes:
PSOSTargetInfoinclang/lib/Basic/Targets/OSTargets.hhasNewAlign = 256andSuitableAlign = 256(bits). So__STDCPP_DEFAULT_NEW_ALIGNMENT__andalignof(max_align_t)are 32 on the console, and PS5 code may store to a freshmallocor plainoperator newresult with 32-byte-aligned AVX instructions.The guest heap aligned blocks to 16 bytes. Worse, the arena's size classes are multiples of 32 bytes on page-aligned spans, so after the 16-byte header every small block landed exactly 16 bytes past a 32-byte boundary. ccleste (PPSA59322, darkxex/PS5_Celeste) faults on its first such store:
operator new(40)returns0x200104f90frommalloc, and the next instruction isvmovaps %ymm0,(%rax).GuestHeap: the minimum alignment is 32 bytes. The padding is now sized from the 16-byte alignment the raw blocks guarantee (RawAlignment), so a 32-byte-aligned pointer always fits its block.guest_memorytest (CheckHeapAlignment):Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti.
CTestTestfile.cmakecommands because antivirus blocksctest.exeon this machine. That run was on a local branch that also carries my other pending changes; everyguest_*test also passes on this branch alone.Not tested on Linux.
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