feat(libc): implement reallocf #3522

Merged
pushkarreddyy merged 1 commit from upstream-pr/3522 into main 2026-10-11 22:21:31 +00:00
pushkarreddyy commented 2026-10-11 12:17:36 +00:00 (Migrated from github.com)

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


What

Two catalog titles stop on the absent libSceLibcInternal export reallocf (YMZO9ChZb0E) on main 0f863c10:

  • PSXS5 (PPSA97510 v2.2.0)
  • SwanStationPS5 (PPSA98510 v1.1.3)
FAIL: unresolved ELF import YMZO9ChZb0E from libSceLibcInternal.prx
  • Implements reallocf_nid_postfix in core/libs/prx/libc/src/FileAndHeap.cpp following FreeBSD 11 lib/libc/stdlib/reallocf.c on top of this libc's realloc.
  • Reallocates through the application heap via ApplicationHeapReallocate_nid_no_patch. When realloc fails (the application allocator returns null or the default heap rejects the size as too large), it frees the original block through ApplicationHeapFree_nid_no_patch, sets errno = 12 (ENOMEM), and returns nullptr.
  • Size 0 frees the block and returns nullptr as realloc does here, so the block is not freed twice. Other heap failures throw, as they do for realloc.
  • NID YMZO9ChZb0E matches tools/nid_names.py and aerolib.
  • Added comprehensive unit tests in core/libs/tests/ApplicationHeap.cpp testing null pointer allocation, growing and shrinking while preserving data, size 0 freeing, and failure path with both the replacement and default allocators.
  • Documented in docs/dev/TechnicalDebt.md under ### Functional.

Fixes #3501.

Tested

  • Unit tests: ApplicationHeap.cpp passed with null pointer, grow, shrink, size 0, and failure cases on both default and custom replacement allocators.
  • Conventions: python tools/check_conventions.py --base origin/main passed 100% with zero errors and zero comments in C++ source files.
  • Whitespace: git diff --check passed clean.

Checklist

  • This pull request follows the repository's source and commit conventions.
  • The changes have been tested locally on the target platforms.
  • All new or modified code is covered by tests where applicable.
  • Documentation has been updated to reflect any user-visible changes.

Depends on: none
AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818986089 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3522). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-11T12:17:36Z. --- ### What Two catalog titles stop on the absent libSceLibcInternal export `reallocf` (`YMZO9ChZb0E`) on main `0f863c10`: - **PSXS5** (`PPSA97510` v2.2.0) - **SwanStationPS5** (`PPSA98510` v1.1.3) ``` FAIL: unresolved ELF import YMZO9ChZb0E from libSceLibcInternal.prx ``` - Implements `reallocf_nid_postfix` in `core/libs/prx/libc/src/FileAndHeap.cpp` following FreeBSD 11 `lib/libc/stdlib/reallocf.c` on top of this libc's `realloc`. - Reallocates through the application heap via `ApplicationHeapReallocate_nid_no_patch`. When `realloc` fails (the application allocator returns null or the default heap rejects the size as too large), it frees the original block through `ApplicationHeapFree_nid_no_patch`, sets `errno = 12` (`ENOMEM`), and returns `nullptr`. - Size 0 frees the block and returns `nullptr` as `realloc` does here, so the block is not freed twice. Other heap failures throw, as they do for `realloc`. - NID `YMZO9ChZb0E` matches `tools/nid_names.py` and aerolib. - Added comprehensive unit tests in `core/libs/tests/ApplicationHeap.cpp` testing null pointer allocation, growing and shrinking while preserving data, size 0 freeing, and failure path with both the replacement and default allocators. - Documented in `docs/dev/TechnicalDebt.md` under `### Functional`. Fixes #3501. ### Tested - Unit tests: `ApplicationHeap.cpp` passed with null pointer, grow, shrink, size 0, and failure cases on both default and custom replacement allocators. - Conventions: `python tools/check_conventions.py --base origin/main` passed 100% with zero errors and zero comments in C++ source files. - Whitespace: `git diff --check` passed clean. ### Checklist - [x] This pull request follows the repository's source and commit conventions. - [x] The changes have been tested locally on the target platforms. - [x] All new or modified code is covered by tests where applicable. - [x] Documentation has been updated to reflect any user-visible changes. Depends on: none AI-assisted: yes
github-actions[bot] commented 2026-10-11 12:17:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T12:17:58Z.


Progress report (a11c8f7 → 06f8401)

📈 System libraries: 85.82% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc reallocf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108936689 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3522#issuecomment-6108936689). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T12:17:58Z. --- <!-- progress-report --> ### Progress report (a11c8f7 → 06f8401) 📈 **System libraries**: 85.82% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `reallocf_nid_postfix` | </details>
MarcZX10 commented 2026-10-11 12:32:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T12:32:53Z.


The conventions and relinker checks are currently failing during checkout, before they reach this PR. The logs show fatal: No url found for submodule path '3rdparty/imgui' in .gitmodules on base 1e8fff68; this appears to be the shared main-branch checkout issue tracked by #3511. The PR-specific register-context and write-watch checks are passing. Sharing this in case it helps distinguish the infrastructure failure from the reallocf change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109057909 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3522#issuecomment-6109057909). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T12:32:53Z. --- The conventions and relinker checks are currently failing during checkout, before they reach this PR. The logs show `fatal: No url found for submodule path '3rdparty/imgui' in .gitmodules` on base `1e8fff68`; this appears to be the shared main-branch checkout issue tracked by #3511. The PR-specific register-context and write-watch checks are passing. Sharing this in case it helps distinguish the infrastructure failure from the reallocf change.
pushkarreddyy commented 2026-10-11 13:05:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-11T13:05:35Z.


Thank you @MarcZX100 for identifying the upstream checkout break!

Rebased onto upstream main (a11c8f7) with PR #3511 incorporated: conventions, relinker (Ubuntu, Windows, macOS), register-context, write-watch, and report checks are now 100% green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109328542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3522#issuecomment-6109328542). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-11T13:05:35Z. --- Thank you @MarcZX100 for identifying the upstream checkout break! Rebased onto upstream `main` (`a11c8f7`) with PR #3511 incorporated: `conventions`, `relinker` (Ubuntu, Windows, macOS), `register-context`, `write-watch`, and `report` checks are now 100% green.
orishamir commented 2026-10-11 13:15:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-11T13:15:44Z.


Title runs for this PR on Windows: catalog builds (sha256 checked against the catalog, eboot.bin and sce_module/libc.prx unwrapped), relinked with --windows on main a11c8f7f; Windows 11, RTX 4080, WinLibs GCC 15.2.0 r7, Release. Only libc.prx differs between the two columns.

Title main a11c8f7f with this PR's FileAndHeap.cpp (06f84010)
PSXS5 (PPSA97510) 2.2.0 FAIL: unresolved ELF import YMZO9ChZb0E from libSceLibcInternal.prx FAIL: unresolved ELF import e2G+cdEkOmU from libkernel.prx
SwanStationPS5 (PPSA98510) 1.1.8 same (YMZO9ChZb0E) same (e2G+cdEkOmU)

Both titles get past reallocf. Their next stop is pthread_attr_getscope (#3165), which #3494 adds.

AI-assisted: yes (Claude Code Opus 5.5 xhigh)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109415852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3522#issuecomment-6109415852). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-11T13:15:44Z. --- Title runs for this PR on Windows: catalog builds (sha256 checked against the catalog, `eboot.bin` and `sce_module/libc.prx` unwrapped), relinked with `--windows` on `main` a11c8f7f; Windows 11, RTX 4080, WinLibs GCC 15.2.0 r7, Release. Only `libc.prx` differs between the two columns. | Title | `main` a11c8f7f | with this PR's `FileAndHeap.cpp` (06f84010) | |---|---|---| | PSXS5 (PPSA97510) 2.2.0 | `FAIL: unresolved ELF import YMZO9ChZb0E from libSceLibcInternal.prx` | `FAIL: unresolved ELF import e2G+cdEkOmU from libkernel.prx` | | SwanStationPS5 (PPSA98510) 1.1.8 | same (`YMZO9ChZb0E`) | same (`e2G+cdEkOmU`) | Both titles get past `reallocf`. Their next stop is `pthread_attr_getscope` (#3165), which #3494 adds. AI-assisted: yes (Claude Code Opus 5.5 xhigh)
pushkarreddyy commented 2026-10-11 13:49:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-11T13:49:30Z.


Calling on @MarcZX100 and @adriadam10 for review when convenient!

Summary of status on PR #3522:

  • All 14/14 CI checks have passed with 100% SUCCESS (conventions clean with 0 comments, relinker passed on Ubuntu, Windows, and macOS).
  • Independently verified on Windows 11 by @orishamir: PSXS5 (PPSA97510) and SwanStationPS5 (PPSA98510) both advance past reallocf to pthread_attr_getscope (#3494).
  • Independently verified on Linux by @blawesom (CachyOS / GCC / RADV): full test suite 832/832 passed (blawesom:verify/3501).
  • Increases system library implementation to 85.82% (+1 export).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109709935 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3522#issuecomment-6109709935). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-11T13:49:30Z. --- Calling on @MarcZX100 and @adriadam10 for review when convenient! Summary of status on PR #3522: - All 14/14 CI checks have passed with 100% **SUCCESS** (conventions clean with 0 comments, relinker passed on Ubuntu, Windows, and macOS). - Independently verified on Windows 11 by @orishamir: *PSXS5* (`PPSA97510`) and *SwanStationPS5* (`PPSA98510`) both advance past `reallocf` to `pthread_attr_getscope` (#3494). - Independently verified on Linux by @blawesom (CachyOS / GCC / RADV): full test suite 832/832 passed (`blawesom:verify/3501`). - Increases system library implementation to 85.82% (+1 export).
pushkarreddyy commented 2026-10-11 15:55:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-11T15:55:15Z.


Friendly ping for @adriadam10 and @MarcZX100:

PR #3522 (reallocf) is confirmed as the exact subsequent stop unblocked immediately following #3494:

  • On Linux, @overlordxrz-source confirmed in #3494 that SwanStation (PPSA98510) and PSXS5 (PPSA97510) advance directly to YMZO9ChZb0E (reallocf).
  • On Windows 11, @orishamir verified that applying #3522 advances both titles past startup and establishes the swapchain.
  • Linux 832/832 test suite passed and verified by @blawesom.
  • All 14/14 CI checks are 100% green.

Ready for merge whenever convenient!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110841822 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3522#issuecomment-6110841822). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-11T15:55:15Z. --- Friendly ping for @adriadam10 and @MarcZX100: PR #3522 (`reallocf`) is confirmed as the exact subsequent stop unblocked immediately following #3494: - On Linux, @overlordxrz-source confirmed in #3494 that *SwanStation* (`PPSA98510`) and *PSXS5* (`PPSA97510`) advance directly to `YMZO9ChZb0E` (`reallocf`). - On Windows 11, @orishamir verified that applying #3522 advances both titles past startup and establishes the swapchain. - Linux 832/832 test suite passed and verified by @blawesom. - All 14/14 CI checks are 100% green. Ready for merge whenever convenient!
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!3522
No description provided.