libc: reallocf is absent, first stop of PSXS5 and SwanStationPS5 on main; fix branch ready #3501

Closed
opened 2026-10-11 11:57:17 +00:00 by screamm · 2 comments
screamm commented 2026-10-11 11:57:17 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T11:57:17Z.


libc (libSceLibcInternal) does not export reallocf (NID YMZO9ChZb0E). On current main 0f863c10 PSXS5 (PPSA97510) and SwanStationPS5 (PPSA98510) stop on it as their first stop (fresh Windows relink, --windows --registry unused-filter=0):

FAIL: unresolved ELF import YMZO9ChZb0E from libSceLibcInternal.prx

Fix branch ready: screamm:feat/libc-reallocf (92865bd6, one commit on main 0f863c10). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. The closed #1767 was the earlier attempt, closed for lack of a title; this is a rewrite on current main.

  • reallocf (in FileAndHeap.cpp, next to realloc) calls the same heap path as realloc; when the application's allocator returns null, or the default heap rejects the size as too large (the mapping posix_memalign already uses), it frees the original block through the guest's own allocator, sets errno 12 and returns null, as FreeBSD 11 lib/libc/stdlib/reallocf.c does; size 0 and a null pointer are left to realloc's existing behaviour; the other heap failures (exhausted arena, unknown or pinned pointer, finalized heap) keep throwing exactly as realloc does. TechnicalDebt records the FreeBSD provenance.
  • application_heap_default and application_heap_replacement gain null-pointer-as-malloc, grow and shrink keeping data, size 0 freeing once, and the failure path (oversized request on the default heap; the fail flag on the fake guest allocator) returning null with errno 12 and freeing exactly once; removing the free makes both fail.

Tested on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, full build including libs: the five heap tests 3/3; ctest -j8 -E "^agc_driver_|^video_out_flip" 532/534, the failures being windows_exceptions (#3411) and one agc_driver heap-corruption exit that also occurs on unchanged main here under load and passed 3/3 alone with this change; with main's FileAndHeap.cpp four of the five tests fail; tools/check_conventions.py --base main and git diff --check pass. Not run on Linux, no title run.

Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5800829243 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3501). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T11:57:17Z. --- libc (libSceLibcInternal) does not export `reallocf` (NID `YMZO9ChZb0E`). On current `main` `0f863c10` PSXS5 (PPSA97510) and SwanStationPS5 (PPSA98510) stop on it as their first stop (fresh Windows relink, `--windows --registry unused-filter=0`): ``` FAIL: unresolved ELF import YMZO9ChZb0E from libSceLibcInternal.prx ``` **Fix branch ready:** [`screamm:feat/libc-reallocf`](https://github.com/screamm/AnyPS5/tree/feat/libc-reallocf) (`92865bd6`, one commit on `main` `0f863c10`). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. The closed #1767 was the earlier attempt, closed for lack of a title; this is a rewrite on current `main`. - `reallocf` (in `FileAndHeap.cpp`, next to `realloc`) calls the same heap path as `realloc`; when the application's allocator returns null, or the default heap rejects the size as too large (the mapping `posix_memalign` already uses), it frees the original block through the guest's own allocator, sets errno 12 and returns null, as FreeBSD 11 `lib/libc/stdlib/reallocf.c` does; size 0 and a null pointer are left to `realloc`'s existing behaviour; the other heap failures (exhausted arena, unknown or pinned pointer, finalized heap) keep throwing exactly as `realloc` does. TechnicalDebt records the FreeBSD provenance. - `application_heap_default` and `application_heap_replacement` gain null-pointer-as-malloc, grow and shrink keeping data, size 0 freeing once, and the failure path (oversized request on the default heap; the fail flag on the fake guest allocator) returning null with errno 12 and freeing exactly once; removing the free makes both fail. **Tested** on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, full build including `libs`: the five heap tests 3/3; `ctest -j8 -E "^agc_driver_|^video_out_flip"` 532/534, the failures being `windows_exceptions` (#3411) and one `agc_driver` heap-corruption exit that also occurs on unchanged `main` here under load and passed 3/3 alone with this change; with `main`'s `FileAndHeap.cpp` four of the five tests fail; `tools/check_conventions.py --base main` and `git diff --check` pass. Not run on Linux, no title run. Written with Claude Code assistance (implementation by a subagent, reviewed and validated in this session).
pushkarreddyy commented 2026-10-11 12:23:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-11T12:23:19Z.


Thank you @screamm for the clear diagnosis and test vectors for reallocf on PSXS5 (PPSA97510) and SwanStationPS5 (PPSA98510).

I have carried this off current main into #3522 (feat(libc): implement reallocf):

  • Implements reallocf_nid_postfix (NID YMZO9ChZb0E) in core/libs/prx/libc/src/FileAndHeap.cpp following FreeBSD 11 lib/libc/stdlib/reallocf.c.
  • Reallocates through the application heap; on failure (or oversized request) frees the block through ApplicationHeapFree_nid_no_patch, sets errno = 12 (ENOMEM), and returns nullptr.
  • Unit tests in ApplicationHeap.cpp for null pointer, grow, shrink, size 0, and failure on both default and replacement allocators.
  • Co-authorship preserved.

PR #3522 is open and passed PR intake! Calling on @adriadam10 and @oneandonlydean for review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108979134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3501#issuecomment-6108979134). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-11T12:23:19Z. --- Thank you @screamm for the clear diagnosis and test vectors for `reallocf` on *PSXS5* (`PPSA97510`) and *SwanStationPS5* (`PPSA98510`). I have carried this off current `main` into **#3522** (`feat(libc): implement reallocf`): - Implements `reallocf_nid_postfix` (NID `YMZO9ChZb0E`) in `core/libs/prx/libc/src/FileAndHeap.cpp` following FreeBSD 11 `lib/libc/stdlib/reallocf.c`. - Reallocates through the application heap; on failure (or oversized request) frees the block through `ApplicationHeapFree_nid_no_patch`, sets `errno = 12` (`ENOMEM`), and returns `nullptr`. - Unit tests in `ApplicationHeap.cpp` for null pointer, grow, shrink, size 0, and failure on both default and replacement allocators. - Co-authorship preserved. PR #3522 is open and passed PR intake! Calling on @adriadam10 and @oneandonlydean for review.
blawesom commented 2026-10-11 13:08:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T13:08:34Z.


Independent verification on Linux (the gap noted in the report): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • Rebased 92865bd65 onto current main: applies cleanly, no conflicts.
  • tools/check_conventions.py --base origin/main and git diff --check pass.
  • The libc allocation tests pass, including the new reallocf cases.
  • Full suite: 832/832 passed (all tests including the Vulkan suites on AMD RX 9070 XT / RADV).

The rebased branch is available at blawesom:verify/3501 for anyone carrying — the commit is otherwise unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109353698 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3501#issuecomment-6109353698). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T13:08:34Z. --- Independent verification on **Linux** (the gap noted in the report): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - Rebased `92865bd65` onto current `main`: applies cleanly, no conflicts. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. - The libc allocation tests pass, including the new reallocf cases. - Full suite: **832/832 passed** (all tests including the Vulkan suites on AMD RX 9070 XT / RADV). The rebased branch is available at [`blawesom:verify/3501`](https://github.com/blawesom/AnyPS5/tree/verify/3501) for anyone carrying — the commit is otherwise unchanged.
Sign in to join this conversation.
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#3501
No description provided.