feat(libc): implement __std_calloc_crt allocation wrapper #12184

Open
laloerraz wants to merge 4 commits from upstream-pr/12184 into main
laloerraz commented 2026-10-28 01:33:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by laloerraz on 2026-10-28T01:33:53Z.


What

Provide missing libc export __std_calloc_crt (NID 1a7K+jO+ST0) through the existing guest calloc implementation. The signature and forwarding contract follow Microsoft STL; the name/NID occur in the public PS5 ps5rs inventory. The source-derived alias is an inference rather than a PS5 measurement; record unverified native allocator routing and error behavior in libc debt. This does not claim that a title is unblocked.

Tested

Windows x86-64, WinLibs GCC 15.2.0 POSIX/DWARF, Release full CMake configuration. Built application_heap_tests and patched libc.prx. CTest -R ^application_heap_ --output-on-failure -j1 --timeout25: 9/9 passed, 0 failures, 0.32 seconds, including replacement, invalid_metadata, default, exit_order, scripting, lazy and three stats modes. Tests exercise zeroed storage, 64-bit multiplication overflow, zero dimensions, existing guest deallocation/reallocation and callback allocation failure. Public-header audit and conventions passed. Patched output exports the expected NID. No game, PS5 module or console run; actual native allocator-domain/error equivalence remains unverified.

Sources: github.com/microsoft/STL@b6f01e438b/stl/src/tzdb.cpp (L647-L649) and github.com/claimore22/ps5rs@5f252a658f/data/stubs/by_library/libc.txt

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Overlap review: the full tool examined 1,364 open PRs. No duplicate function/export was found. Thirty-seven stale PR comparisons required manual review; PR #11848 appends unrelated freezero tests at the same ApplicationHeap.cpp insertion point, so a textual merge resolution may be needed. There is no demonstrated functional dependency. Full log and manual diff review are retained locally; do not describe every stale PR as merge-clean.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5043742897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12184). Originally posted by [laloerraz](https://github.com/laloerraz) on 2026-10-28T01:33:53Z. --- ### What Provide missing libc export __std_calloc_crt (NID 1a7K+jO+ST0) through the existing guest calloc implementation. The signature and forwarding contract follow Microsoft STL; the name/NID occur in the public PS5 ps5rs inventory. The source-derived alias is an inference rather than a PS5 measurement; record unverified native allocator routing and error behavior in libc debt. This does not claim that a title is unblocked. ### Tested Windows x86-64, WinLibs GCC 15.2.0 POSIX/DWARF, Release full CMake configuration. Built application_heap_tests and patched libc.prx. CTest -R ^application_heap_ --output-on-failure -j1 --timeout25: 9/9 passed, 0 failures, 0.32 seconds, including replacement, invalid_metadata, default, exit_order, scripting, lazy and three stats modes. Tests exercise zeroed storage, 64-bit multiplication overflow, zero dimensions, existing guest deallocation/reallocation and callback allocation failure. Public-header audit and conventions passed. Patched output exports the expected NID. No game, PS5 module or console run; actual native allocator-domain/error equivalence remains unverified. Sources: https://github.com/microsoft/STL/blob/b6f01e438b68ee497f9c08313e49d12bb2f0d8e0/stl/src/tzdb.cpp#L647-L649 and https://github.com/claimore22/ps5rs/blob/5f252a658ff470bcb2b6cd15205fd8ca64ae4477/data/stubs/by_library/libc.txt <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes Overlap review: the full tool examined 1,364 open PRs. No duplicate function/export was found. Thirty-seven stale PR comparisons required manual review; PR #11848 appends unrelated freezero tests at the same ApplicationHeap.cpp insertion point, so a textual merge resolution may be needed. There is no demonstrated functional dependency. Full log and manual diff review are retained locally; do not describe every stale PR as merge-clean.
MarcZX10 commented 2026-10-28 03:23:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T03:23:58Z.

Review: CHANGES_REQUESTED


The code and focused test changes look sound in the scope I checked: the NID recomputes to 1a7K+jO+ST0, the public-header audit passes, both changed C++ files pass local C++20 syntax-only compilation, conventions/diff checks pass, and the current-main merge preview is clean. I found one required overlap follow-up before approval. Your overlap report identifies still-open #11848 as touching the same ApplicationHeap.cpp insertion point, and my merge preview confirms textual conflicts in ApplicationHeap.cpp and docs/dev/debt/libc.md. CONTRIBUTING.md requires the authors to agree which overlapping PR goes first and to record that order with Depends on: #N in the affected checklist. Please coordinate the order with #11848’s author and update the checklist accordingly. I am not asking to close or withdraw either PR. Your reported Windows 9/9 focused tests and patched-NID check are useful; I did not independently run that Windows suite. The available hosted checks at this head are conventions, intake and labels; the PR does not yet have hosted build checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5677412779 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12184#pullrequestreview-5677412779). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T03:23:58Z. **Review:** CHANGES_REQUESTED --- The code and focused test changes look sound in the scope I checked: the NID recomputes to `1a7K+jO+ST0`, the public-header audit passes, both changed C++ files pass local C++20 syntax-only compilation, conventions/diff checks pass, and the current-main merge preview is clean. I found one required overlap follow-up before approval. Your overlap report identifies still-open #11848 as touching the same `ApplicationHeap.cpp` insertion point, and my merge preview confirms textual conflicts in `ApplicationHeap.cpp` and `docs/dev/debt/libc.md`. CONTRIBUTING.md requires the authors to agree which overlapping PR goes first and to record that order with `Depends on: #N` in the affected checklist. Please coordinate the order with #11848’s author and update the checklist accordingly. I am not asking to close or withdraw either PR. Your reported Windows 9/9 focused tests and patched-NID check are useful; I did not independently run that Windows suite. The available hosted checks at this head are conventions, intake and labels; the PR does not yet have hosted build checks.
adriadam10 commented 2026-10-28 11:13:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T11:13:10Z.

Review: CHANGES_REQUESTED


Code, test and debt entry look right (alias to calloc, overflow/zero/callback-failure rows, unverified native routing recorded). One point left, the one @MarcZX10 requested:

  • #11848 is open, older, and touches the same spot in core/libs/tests/ApplicationHeap.cpp and docs/dev/debt/libc.md, so the two conflict textually. CONTRIBUTING asks the authors to agree which goes first and to record it. Please agree the order with #11848's author and put the result in Depends on in the checklist (#11848 if that one lands first). Rebase onto main afterwards.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681703745 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12184#pullrequestreview-5681703745). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-28T11:13:10Z. **Review:** CHANGES_REQUESTED --- Code, test and debt entry look right (alias to `calloc`, overflow/zero/callback-failure rows, unverified native routing recorded). One point left, the one @MarcZX10 requested: - #11848 is open, older, and touches the same spot in `core/libs/tests/ApplicationHeap.cpp` and `docs/dev/debt/libc.md`, so the two conflict textually. CONTRIBUTING asks the authors to agree which goes first and to record it. Please agree the order with #11848's author and put the result in `Depends on` in the checklist (`#11848` if that one lands first). Rebase onto main afterwards.
MarcZX10 commented 2026-11-14 06:43:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T06:43:54Z.

Review: APPROVED


Reviewed — looks good

The wrapper and declaration follow the existing calloc path, and the inspected tests cover zeroing, overflow, zero-sized requests, and allocation failure; the author reports the Windows test run, which I did not perform.

What I ran

Reviewed head f727bbacfb303b6932984abd2b7290323a8b3b7c. Read the prepared description, commits, manifest and diff, and all four changed files listed as reviewed. Used the provided repository reader to inspect the allocation helper and relevant tests. No commands or tests were run by me.

Results

Check Result Note
Diff and changed code review passed Four changed files read
Tests reported by author not run Windows x86-64; reported 9/9 passing
PS5 behavior not run Native allocator routing and error behavior unverified

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported build, CTest results, public-header audit, conventions check and NID export check were not independently run. No PS5 module, title or console behavior was tested. Files excluded by rule: none listed in files.json because that file was not included in the prepared bundle; exclusion status not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5902374589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12184#pullrequestreview-5902374589). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T06:43:54Z. **Review:** APPROVED --- # Reviewed — looks good The wrapper and declaration follow the existing `calloc` path, and the inspected tests cover zeroing, overflow, zero-sized requests, and allocation failure; the author reports the Windows test run, which I did not perform. ## What I ran Reviewed head `f727bbacfb303b6932984abd2b7290323a8b3b7c`. Read the prepared description, commits, manifest and diff, and all four changed files listed as reviewed. Used the provided repository reader to inspect the allocation helper and relevant tests. No commands or tests were run by me. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code review | passed | Four changed files read | | Tests reported by author | not run | Windows x86-64; reported 9/9 passing | | PS5 behavior | not run | Native allocator routing and error behavior unverified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The reported build, CTest results, public-header audit, conventions check and NID export check were not independently run. No PS5 module, title or console behavior was tested. Files excluded by rule: none listed in `files.json` because that file was not included in the prepared bundle; exclusion status not verified. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-17 22:22:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T22:22:42Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head: ecd9477b745fbd1640c851360ffec78a1b9168cd, base main.
  • Read the diff of all four changed files: Api.hpp, FileAndHeap.cpp, ApplicationHeap.cpp and libc.md.
  • Read the head of FileAndHeap.cpp at lines 1100–1135 (the calloc wrapper it forwards to).
  • Searched the head for the new name and for the NID.
  • No build and no test run in this review.

Results

Check Result Note
Changed hunks read passed 4 of 4 files, from the diff
Full file text not run files/ not opened
Build and CTest not run Author reports 9/9
Export NID not run Author reports it in the patched output
Head search passed Name appears only in the wrapper, its declaration and the test

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • The build and the application_heap_ CTest run, including the 9/9 count. These are the author's report, not a run here.
  • The NID 1a7K+jO+ST0 as the export that a PS5 or the patched libc.prx resolves. The head search found the NID only in docs/dev/debt/libc.md:9. The export table is not in the repository at the head, so the mapping is not checked.
  • Routing through the application allocator and the error behaviour of the console wrapper. The PR says this is unmeasured, and the review agrees.
  • The source permalinks in the debt entry. I did not open them. The Microsoft STL link names tzdb.cpp at lines 647–649, so whether those lines show the forwarding the entry describes is not verified.
  • The textual merge with PR #11848 that the description mentions. Not checked.

To get this to a good state

Nothing is required.

Optional: confirm that the Microsoft STL permalink in docs/dev/debt/libc.md:9 shows the calloc forwarding it describes. If it does not, point the entry at the right source.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5947622473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12184#pullrequestreview-5947622473). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T22:22:42Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head: `ecd9477b745fbd1640c851360ffec78a1b9168cd`, base `main`. - Read the diff of all four changed files: `Api.hpp`, `FileAndHeap.cpp`, `ApplicationHeap.cpp` and `libc.md`. - Read the head of `FileAndHeap.cpp` at lines 1100–1135 (the calloc wrapper it forwards to). - Searched the head for the new name and for the NID. - No build and no test run in this review. ## Results | Check | Result | Note | |---|---|---| | Changed hunks read | passed | 4 of 4 files, from the diff | | Full file text | not run | `files/` not opened | | Build and CTest | not run | Author reports 9/9 | | Export NID | not run | Author reports it in the patched output | | Head search | passed | Name appears only in the wrapper, its declaration and the test | ## Findings **Blocking** None. **Non-blocking** None. ## Not verified - The build and the `application_heap_` CTest run, including the 9/9 count. These are the author's report, not a run here. - The NID `1a7K+jO+ST0` as the export that a PS5 or the patched `libc.prx` resolves. The head search found the NID only in `docs/dev/debt/libc.md:9`. The export table is not in the repository at the head, so the mapping is not checked. - Routing through the application allocator and the error behaviour of the console wrapper. The PR says this is unmeasured, and the review agrees. - The source permalinks in the debt entry. I did not open them. The Microsoft STL link names `tzdb.cpp` at lines 647–649, so whether those lines show the forwarding the entry describes is not verified. - The textual merge with PR #11848 that the description mentions. Not checked. ## To get this to a good state Nothing is required. Optional: confirm that the Microsoft STL permalink in `docs/dev/debt/libc.md:9` shows the calloc forwarding it describes. If it does not, point the entry at the right source.
malekaifa commented 2026-11-23 23:46:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-23T23:46:06Z.

Review: CHANGES_REQUESTED


Current exact head ecd9477b745fbd1640c851360ffec78a1b9168cd is not mergeable. The earlier overlap-order blocker is no longer the issue: #11848 (freezero) has merged, so its edits are now upstream and should simply be preserved.

The __std_calloc_crt implementation itself still looks sound: it forwards to the existing checked guest calloc path, the tests cover zeroing, multiplication overflow, zero dimensions and callback failure, and current-head Windows evidence reports the 11 application_heap* tests passing. The debt entry correctly marks the PS5 allocator-domain/error semantics as unmeasured.

Please rebase/restack this branch onto current main, resolve the now-upstream #11848 changes in ApplicationHeap.cpp and docs/dev/debt/libc.md by preserving both sides, and rerun the focused application_heap* tests plus conventions/diff checks. Then request exact-head review. The old Depends on coordination with #11848 is historical now; it should not remain as a live blocker after the rebase.

I am requesting changes for integration state, not for the wrapper semantics.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6031347522 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12184#pullrequestreview-6031347522). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-11-23T23:46:06Z. **Review:** CHANGES_REQUESTED --- Current exact head `ecd9477b745fbd1640c851360ffec78a1b9168cd` is not mergeable. The earlier overlap-order blocker is no longer the issue: #11848 (`freezero`) has merged, so its edits are now upstream and should simply be preserved. The `__std_calloc_crt` implementation itself still looks sound: it forwards to the existing checked guest `calloc` path, the tests cover zeroing, multiplication overflow, zero dimensions and callback failure, and current-head Windows evidence reports the 11 `application_heap*` tests passing. The debt entry correctly marks the PS5 allocator-domain/error semantics as unmeasured. Please rebase/restack this branch onto current `main`, resolve the now-upstream #11848 changes in `ApplicationHeap.cpp` and `docs/dev/debt/libc.md` by preserving both sides, and rerun the focused `application_heap*` tests plus conventions/diff checks. Then request exact-head review. The old `Depends on` coordination with #11848 is historical now; it should not remain as a live blocker after the rebase. I am requesting changes for integration state, not for the wrapper semantics. AI-assisted: yes
ligmaSec commented 2026-12-03 13:24:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:24:58Z.

Review: COMMENTED


Built the focused checks against the existing Linux runtime. ApplicationHeap passed, including the allocation-wrapper checks.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170650805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12184#pullrequestreview-6170650805). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:24:58Z. **Review:** COMMENTED --- Built the focused checks against the existing Linux runtime. `ApplicationHeap` passed, including the allocation-wrapper checks. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/12184:upstream-pr/12184'
git switch 'upstream-pr/12184'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/12184'
git switch 'upstream-pr/12184'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/12184'
git switch 'upstream-pr/12184'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/12184'
git switch 'main'
git merge --squash 'upstream-pr/12184'
git switch 'main'
git merge --ff-only 'upstream-pr/12184'
git switch 'main'
git merge 'upstream-pr/12184'
git push origin 'main'
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!12184
No description provided.