feat(libc): mspace memalign, malloc stats, thread-unsafe flag and nested mspaces #49

Merged
oneandonlydean merged 1 commit from upstream-pr/49 into main 2026-09-28 05:58:28 +00:00
oneandonlydean commented 2026-09-28 01:24:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-28T01:24:43Z.


What

Four mspace gaps hit by a retail title:

  • sceLibcMspaceMemalign wasn't exported.
  • sceLibcMspaceMallocStats and sceLibcMspaceMallocStatsFast weren't exported.
  • sceLibcMspaceCreate rejected flag 1 (SCE_LIBC_MSPACE_THREAD_UNSAFE).
  • sceLibcMspaceCreate rejected an mspace created inside a block allocated from another mspace. The title's GPU heaps are carved out of its global heap this way. The failed create left a null handle, and the title's allocator later asserted Out of graphics memory.

How

  • Memalign uses the existing aligned allocation.
  • Stats fill SceLibcMallocManagedSize (size checked against 0x28) from new inUse/peakInUse counters on the arena. The system size is the arena's extent.
  • The thread-unsafe flag is accepted: the implementation always locks, so skipping locks is only an optimisation it doesn't need. Other flags are still rejected.
  • An overlapping create is allowed only when the new range lies entirely inside a live block of the other mspace. Every other overlap is still rejected.

Testing

mspace test extended for memalign (alignment and invalid alignment), stats (current, peak, short struct), a nested create inside an allocation, a create over unallocated arena space (rejected), the thread-unsafe flag and an unknown flag (rejected).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4658146859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/49). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-28T01:24:43Z. --- ### What Four mspace gaps hit by a retail title: - `sceLibcMspaceMemalign` wasn't exported. - `sceLibcMspaceMallocStats` and `sceLibcMspaceMallocStatsFast` weren't exported. - `sceLibcMspaceCreate` rejected flag `1` (`SCE_LIBC_MSPACE_THREAD_UNSAFE`). - `sceLibcMspaceCreate` rejected an mspace created inside a block allocated from another mspace. The title's GPU heaps are carved out of its global heap this way. The failed create left a null handle, and the title's allocator later asserted `Out of graphics memory`. ### How - Memalign uses the existing aligned allocation. - Stats fill `SceLibcMallocManagedSize` (size checked against 0x28) from new `inUse`/`peakInUse` counters on the arena. The system size is the arena's extent. - The thread-unsafe flag is accepted: the implementation always locks, so skipping locks is only an optimisation it doesn't need. Other flags are still rejected. - An overlapping create is allowed only when the new range lies entirely inside a live block of the other mspace. Every other overlap is still rejected. ### Testing `mspace` test extended for memalign (alignment and invalid alignment), stats (current, peak, short struct), a nested create inside an allocation, a create over unallocated arena space (rejected), the thread-unsafe flag and an unknown flag (rejected).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!49
No description provided.