fix(libc): align mspace allocations to 32 bytes #3639
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3639"
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 reyani-dev on 2026-10-11T14:34:13Z.
What
sceLibcMspaceMallocand the rest of the mspace allocator aligned blocks to 16 bytes. Clang's PS4/PS5 targets set the default new alignment and the suitable alignment to 32 bytes (PSOSTargetInfo:NewAlign = 256,SuitableAlign = 256). So PS5 code may store to a fresh block with 32-byte-aligned AVX instructions. The guest heap has guaranteed 32 bytes since #1621; this does the same for mspaces.Allocatenow aligns every block to at least 32 bytes, which covers malloc, calloc, realloc moves, and memalign/posix_memalign/reallocalign with smaller alignments. Block sizes still round to 16 bytes.Title: ProsperoLichess (PPSA99009) on
maina11c8f7ffaults right after loading its puzzle pack, in its own log (download0/prosperolichess/app.log):At guest
0xd1d0cthe title initialises a function-local staticnew T(40 bytes) withvmovaps %ymm0,(%rax). Itsoperator newcallssceLibcMspaceMallocon a 128 MiBmmapheap made withsceLibcMspaceCreate, and the block came back at...5f0, 16 bytes past a 32-byte boundary (the #GP is reported as a read of -1). With this change that fault is gone, and the title runs on to its next stop:Tested
Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, on
maina11c8f7f:CheckAlignmentinmspace(arena base 16 bytes past a 32-byte boundary; malloc 1 to 64 bytes, calloc, realloc growth, memalign 16, reallocalign 8, posix_memalign 8). It fails with the source change reverted and passes with it. The existing mspace checks still pass.ctest -E "^agc_|video_out": 450 of 453 pass. The 3 failures also fail onmainon Windows:windows_exceptions(#3411),guest_kernel_sys(symlink without Developer Mode, #3510) andguest_filesystem(directory time, #3518).tools/check_conventions.pyandtools/pr_overlap.py: clean.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
Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T15:57:53Z.
A second title has the same fault. ProsperoRadio (PPSA99001) on
maina11c8f7f, indownload0/prosperoradio.log:At guest
0xd02dit callsoperator new(0x100)and clears the block withvmovaps %ymm0,(%rax);raxis 16 bytes past a 32-byte boundary. With this branch, the fault is gone and the title runs to its next stop:Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:44:15Z.
Checked the alignment change in
Allocate(all entry points go through it) and the newCheckAlignmenttest: it fails withMspace.cppreverted and passes with the change;mspaceand the rest of the libs ctest scope pass on Linux. Merging.