Commit Graph
20 Commits
Author SHA1 Message Date
babyhuey 4a5ce8a094 fix(libc): adopt the guest SDK allocator only when the title replaces the heap
A bundled libc.prx can export the ten allocator NIDs while forwarding
them to HLE, so adopting its exports for a title whose replacement
table is empty sends HLE allocations back into themselves. Keep the
default heap in that case, as before the guest SDK adoption.
2026-10-19 08:39:37 -04:00
Adrià 980da5090d Merge pull request #6842 from milescoviello/fix/scripting-heap-own-blocks
fix(libc): give the scripting heap hooks blocks from libc's own heap
2026-10-19 14:03:41 +02:00
Adrià 096279ed25 Merge pull request #6610 from JJenkx/fix/linux-sdk-heap-owner
fix(libc): share the guest SDK application allocator
2026-10-19 09:38:02 +02:00
JJenkx bbc16577c9 fix(libc): share the guest SDK application allocator 2026-10-17 20:19:08 -04:00
milescovielloandClaude Opus 5.5 b4e129ff80 fix(libc): give the scripting heap hooks blocks from libc's own heap
scriptingGetMem and scriptingFreeMem went through the title's registered
allocator. A title that ships its own libc.prx has already initialized that
allocator, and the application heap's lazy initialization then ran its
initializer a second time: Metal Gear Solid Master Collection (PPSA18194)
started a second Unity heap and aborted when it freed a block of the first.
The hooks now allocate and free through libc's guest heap, so they never
initialize the registered allocator; sizes that overflow return null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 20:43:32 +00:00
milescovielloandClaude Opus 5.5 dde480e6c8 feat(libc): answer malloc_stats_fast for the default heap
Ship of Harkinian (PPSA99320) logs its heap use with malloc_stats_fast
every 10 s and stopped on the first call, since only an application
allocator could answer it. The default heap now keeps its system and
in-use byte counts with their peaks and fills the same managed-size
block as sceLibcMspaceMallocStatsFast, whose layout moves to a shared
header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 20:43:32 +00:00
MrMha aea1dd601a feat(libc): provide the runtime scripting allocator hooks
Use the registered application allocator and the source-backed alignment/size signature. Add callback ownership and failure checks; record unmeasured console behavior.
2026-10-15 17:21:14 +04:00
hamb3r cee2006d18 feat(libc): lazily initialize application heap on first access 2026-10-14 23:14:30 +03:00
Feurisandmilescoviello d119945a45 fix(libc): allocate from realloc(NULL, 0) as malloc(0) does
realloc(NULL, 0) returned NULL without allocating anything, while malloc(0) returns a unique pointer. C11 7.22.3.5p3 says realloc with a null pointer behaves like malloc for the specified size, so code that grows an empty buffer from zero elements (p = realloc(p, n * size) with n == 0) and treats NULL as out of memory failed on its first call.

FreeBSD 11.4 never returns NULL from realloc for a zero size; je_realloc rounds the size up before choosing between resizing and allocating (contrib/jemalloc/src/jemalloc.c, je_realloc).

A null pointer with size 0 now reaches the allocator's realloc, which allocates as malloc(0) does. A non-null pointer with size 0 is still freed and NULL returned, as before.

Co-authored-by: milescoviello <kitslayer29@gmail.com>
2026-10-12 00:11:17 -03:00
Adrià FranchandClaude 859f2f3b92 feat(libc): implement malloc_usable_size
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-11 04:41:39 +02:00
Adrià 11cb1b75ab Merge pull request #2397 from NahuelGenchi/fix/libc-posix-memalign-huge
fix(libc): return ENOMEM from posix_memalign for sizes the default heap rejects
2026-10-10 11:15:44 +02:00
Nahuel Genchi 230625e080 fix(libc): return ENOMEM from posix_memalign for sizes the default heap rejects 2026-10-09 15:03:07 -03:00
Aryan Sharma 7b130700f6 feat(libc): implement malloc_stats_fast through the application allocator
A title that replaces the allocator through its libc parameters also
supplies malloc_stats_fast in that table, and PPSA28997 calls it. It is
now forwarded to the title's function. Without a replacement allocator
that provides it, the call throws.
2026-10-09 11:04:45 +05:30
Dean 9ab937b261 Merge pull request #973 from ebarr24/codex/libc-posix-memalign-errors
fix(libc): return posix_memalign allocation errors
2026-10-07 18:01:22 +13:00
Ethan Barr db49ba97b5 fix(libc): return posix_memalign allocation errors 2026-10-06 16:41:01 -07:00
Dextroid17 cc7bda30e7 fix(libc): register the application heap finalizer when libc loads
The finalizer was registered with std::atexit from the heap handshake, which
runs after libc's own __cxa_atexit runner and the title's exit callbacks
register theirs. std::atexit runs handlers in reverse registration order, so
the heap was torn down first: an exit user that allocated then threw
"application heap: allocator has been finalized" out of a destructor path,
which terminates the process.

Register the finalizer from a namespace-scope object instead, so it is
registered when libc is loaded and therefore runs last, and make finalize()
idempotent rather than throwing on a second pass.

application_heap_exit_order registers a guest exit callback that allocates
through the heap and aborts with "application heap: allocator has been
finalized" on the previous code.
2026-10-06 18:40:06 -04:00
asimplestray b42db4b6f3 feat(libc): implement RaiseEv, catchReturnFromMain and reallocalign 2026-09-30 23:55:00 +00:00
SamG-Coder 67fce999c5 fix(libc): support SDK startup without allocator replacements 2026-09-28 09:03:10 +10:00
PacukaandClaude Opus 5.5 998605fe4e fix(libc): swap calloc and realloc slots of the malloc replacement table
SceLibcMallocReplace lists calloc before realloc (malloc, free, calloc,
realloc, memalign, reallocalign, posix_memalign, ...), as the table in
retail titles shows. realloc therefore called the application's calloc
with the old pointer as the element count, and calloc called realloc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 11:15:16 +02:00
boykopovar 9f2b41b9a1 fix(libc): route guest allocations through application heap 2026-09-24 06:53:12 +03:00