feat(libc): implement __std_free_crt as free #13828

Merged
zaryabzip merged 2 commits from upstream-pr/13828 into main 2026-11-08 05:44:07 +00:00
zaryabzip commented 2026-10-31 08:30:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-31T08:30:40Z.


What

libc gains __std_free_crt (NID y-r+TFZgeUU), which forwards to free. Microsoft STL defines it as void __std_free_crt(void* p) noexcept { _free_crt(p); }, right after __std_calloc_crt, whose memory it releases. The name and NID are in ps5rs's libc list, as __std_calloc_crt's are.

@oneandonlydean noted on #12184 that this pair member isn't on main, so a title importing both would still have an unresolved import. #12184 adds __std_calloc_crt; this adds the other half on its own. It sits just before free in FileAndHeap.cpp and Api.hpp, so it merges cleanly with both #12184 (after calloc) and #11848 (after free). Its debt entry sits next to the application heap entries, where no open pull request changes the file, so it also merges cleanly with #9677 and #12560. I checked all four with git merge-tree. The debt entry says that whether the console's wrapper frees through the application allocator, as free does, isn't measured. libc goes from 1480 of 1496 to 1481 of 1497.

ApplicationHeap.cpp's scripting mode now also checks that __std_free_crt on a block from malloc reaches the application heap's free callback, and that a null pointer doesn't. The test calls the new declaration, so it doesn't build on main.

Tested

Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head 87b2b8895c merged into main e8c25dd3ba.

  • No warnings in FileAndHeap.cpp, Api.hpp or ApplicationHeap.cpp.
  • ctest -R ^application_heap: 12 of 12 pass on WSL2 and 10 of 10 on Windows (the guest_sdk modes are Linux-only). application_heap_scripting passes 3 of 3 on --repeat until-fail:3.
  • ctest -R public_headers: 65 of 65 pass on both hosts with the new declaration.
  • The patched libc.prx exports y-r+TFZgeUU at the same address as __std_free_crt_nid_postfix in the unpatched one.
  • The test calls the new declaration, so there is no build on main to compare; main's application_heap_scripting passes as before.
  • The head 498a8dadc3 differs from the tested 87b2b8895c only in where the debt entry sits.
  • tools/check_conventions.py passes. tools/pr_overlap.py finds no conflict with mergeable pull requests, and git merge-tree merges this cleanly with #12184, #11848, #9677 and #12560.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5095953791 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13828). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-31T08:30:40Z. --- ### What libc gains `__std_free_crt` (NID `y-r+TFZgeUU`), which forwards to `free`. [Microsoft STL](https://github.com/microsoft/STL/blob/b6f01e438b68ee497f9c08313e49d12bb2f0d8e0/stl/src/tzdb.cpp#L651-L653) defines it as `void __std_free_crt(void* p) noexcept { _free_crt(p); }`, right after `__std_calloc_crt`, whose memory it releases. The name and NID are in [ps5rs's libc list](https://github.com/claimore22/ps5rs/blob/5f252a658ff470bcb2b6cd15205fd8ca64ae4477/data/stubs/by_library/libc.txt), as `__std_calloc_crt`'s are. @oneandonlydean [noted on #12184](https://github.com/boykopovar/AnyPS5/pull/12184#issuecomment-6495227549) that this pair member isn't on `main`, so a title importing both would still have an unresolved import. #12184 adds `__std_calloc_crt`; this adds the other half on its own. It sits just before `free` in `FileAndHeap.cpp` and `Api.hpp`, so it merges cleanly with both #12184 (after `calloc`) and #11848 (after `free`). Its debt entry sits next to the application heap entries, where no open pull request changes the file, so it also merges cleanly with #9677 and #12560. I checked all four with `git merge-tree`. The debt entry says that whether the console's wrapper frees through the application allocator, as `free` does, isn't measured. libc goes from 1480 of 1496 to 1481 of 1497. `ApplicationHeap.cpp`'s `scripting` mode now also checks that `__std_free_crt` on a block from `malloc` reaches the application heap's free callback, and that a null pointer doesn't. The test calls the new declaration, so it doesn't build on `main`. ### Tested <!-- 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. --> Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1), both with the head 87b2b8895c merged into `main` e8c25dd3ba. - No warnings in `FileAndHeap.cpp`, `Api.hpp` or `ApplicationHeap.cpp`. - `ctest -R ^application_heap`: 12 of 12 pass on WSL2 and 10 of 10 on Windows (the `guest_sdk` modes are Linux-only). `application_heap_scripting` passes 3 of 3 on `--repeat until-fail:3`. - `ctest -R public_headers`: 65 of 65 pass on both hosts with the new declaration. - The patched `libc.prx` exports `y-r+TFZgeUU` at the same address as `__std_free_crt_nid_postfix` in the unpatched one. - The test calls the new declaration, so there is no build on `main` to compare; `main`'s `application_heap_scripting` passes as before. - The head 498a8dadc3 differs from the tested 87b2b8895c only in where the debt entry sits. - `tools/check_conventions.py` passes. `tools/pr_overlap.py` finds no conflict with mergeable pull requests, and `git merge-tree` merges this cleanly with #12184, #11848, #9677 and #12560. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-10-31 08:44:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T08:44:59Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The implementation and reported tests look sound, but an open PR overlap creates a real debt-file conflict and its landing order is not recorded.

What I ran

Reviewed head 87b2b8895c5ee30ebafd7f141d254602a08b1225 against PR base e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf. I also checked a merge preview against current main 45e39c7ad16c93871809eee8c81c3865596e883f; it merged cleanly. Environment: Debian 12 Linux, Python 3.11.2, GCC 12.2.0. I did not build the project or run C++ tests locally.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13828 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf --head 87b2b8895c5ee30ebafd7f141d254602a08b1225 --json
python3 /marc/AnyPS5/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/head-87b2b8895c5e-c8e3bdfc --json core/libs/tests/ApplicationHeap.cpp
python3 tools/pr_stack_check.py 13828 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/stack
python3 tools/pr_overlap.py --branch 87b2b8895c5ee30ebafd7f141d254602a08b1225
git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 6ac7ce9e401899294b07fd56eea0ec72a6fb0980
git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 e52854d1b6ecef00ae86bf9b86c90333000dbadf
git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 c272bbe1b3d1fa9cdd9e56d7e9c56d01ef04df15

Results

Check Result
Diff and conventions Passed.
Current-main merge preview Passed against 45e39c7ad16c93871809eee8c81c3865596e883f.
Export ABI audit Passed with 3 unrelated existing explicit-alias warnings; no finding for __std_free_crt. The precheck’s isolated copy lacked the local-only audit helper, so I ran the audit directly against the exact base and head.
Test-quality check Heuristic flagged possible test-registration trouble; source inspection confirms ApplicationHeap.cpp is built into application_heap_tests and the scripting test is registered.
PR overlap The current overlap report identifies open #9677 in docs/dev/debt/libc.md at current-main line 68. Pairwise merge preview with #9677 reports a content conflict in that file. Pairwise previews with #12184 and #11848 are clean.
Hosted CI at final refresh Windows, Ubuntu and Windows relinker, ASan, Ubuntu register-context, conventions, intake, eligibility, labels, report, and library-portability passed. Linux product tests were skipped. macOS relinker, register-context and write-watch jobs were queued.
Unedited check output

Precheck command output:

/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/report.md
/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/report.json
Conclusion: checks failed

The precheck’s conventions output:

All conventions checks passed.

Direct ABI-audit summary:

status: passed_with_warnings
findings: 3
target findings: []

Test-quality output:

{
  "findings": [
    {
      "path": "core/libs/tests/ApplicationHeap.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}

Relevant overlap-report row:

| [PR 9677](https://www.github.com/boykopovar/AnyPS5/pull/9677) | `docs/dev/debt/libc.md` [L68](https://github.com/boykopovar/AnyPS5/blob/45e39c7ad16c93871809eee8c81c3865596e883f/docs/dev/debt/libc.md#L68) |  |  |

Pairwise merge output with #9677:

9a8378c1e68c49c4cb99af789d4095288
100644 568e1931c1abf7cdfc763a4e8d7e8c0c5cebefb6 1	docs/dev/debt/libc.md
100644 e463077515d88ae6063cace01c374095eee7260c 2	docs/dev/debt/libc.md
100644 90228bbb4bdc6574e8e1aff000bde82daa0c8854 3	docs/dev/debt/libc.md
Auto-merging core/libs/prx/libc/src/Time.cpp
Auto-merging core/libs/prx/libkernel/Time/Time.cpp
Auto-merging core/libs/tests/GuestProcessTime.cpp
Auto-merging docs/dev/debt/libc.md
CONFLICT (content): Merge conflict in docs/dev/debt/libc.md
EXIT:1

Current hosted check snapshot:

linux	completed	skipped
register-context (macos-15-intel, Release)	queued	
relinker (macos-latest, clang++, x86_64)	queued	
relinker (macos-latest, clang++)	queued	
relinker-asan	completed	success
relinker (ubuntu-latest, g++)	completed	success
windows	completed	success
write-watch (macos-15)	queued	
register-context (ubuntu-latest, Release)	completed	success
write-watch (macos-15-intel)	queued	
relinker (windows-latest, g++)	completed	success
register-context (ubuntu-latest, Debug)	completed	success
labels	completed	success
conventions	completed	success
intake	completed	success
eligibility	completed	success
report	completed	success
library-portability	completed	success

Findings

Blocking

  • Unresolved landing order with #9677. The live overlap report identifies a shared edit in docs/dev/debt/libc.md, and a pairwise merge preview of these exact heads confirms a content conflict. The repository requires agreeing with the other PR author on which lands first and recording that order with Depends on; this PR still says Depends on: none, and no agreement with #9677’s author is recorded. Please coordinate the order and update the relevant checklist entry or entries, then recheck the pairwise merge.

Non-blocking

  • The scripting test currently allocates with malloc_nid_postfix before calling __std_free_crt. A direct __std_calloc_crt to __std_free_crt case would exercise the exact allocation/free pair motivating this PR; the existing callback test still gives useful evidence for the shared heap path.

Sources

Not verified

  • No local build, C++ tests or negative control. The PR description reports exact-head builds and focused CTest runs on WSL2 and Windows, but those runs were not independently reproduced here.
  • No console measurement. macOS CI jobs were still queued; Linux product tests were skipped.

To get this to a good state

Please agree and record the landing order with #9677’s author. I will rerun the overlap and merge checks, then reassess the new exact head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5722033512 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13828#pullrequestreview-5722033512). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T08:44:59Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The implementation and reported tests look sound, but an open PR overlap creates a real debt-file conflict and its landing order is not recorded. ## What I ran Reviewed head `87b2b8895c5ee30ebafd7f141d254602a08b1225` against PR base `e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf`. I also checked a merge preview against current `main` `45e39c7ad16c93871809eee8c81c3865596e883f`; it merged cleanly. Environment: Debian 12 Linux, Python 3.11.2, GCC 12.2.0. I did not build the project or run C++ tests locally. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13828 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828 python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf --head 87b2b8895c5ee30ebafd7f141d254602a08b1225 --json python3 /marc/AnyPS5/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/head-87b2b8895c5e-c8e3bdfc --json core/libs/tests/ApplicationHeap.cpp python3 tools/pr_stack_check.py 13828 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/stack python3 tools/pr_overlap.py --branch 87b2b8895c5ee30ebafd7f141d254602a08b1225 git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 6ac7ce9e401899294b07fd56eea0ec72a6fb0980 git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 e52854d1b6ecef00ae86bf9b86c90333000dbadf git merge-tree 87b2b8895c5ee30ebafd7f141d254602a08b1225 c272bbe1b3d1fa9cdd9e56d7e9c56d01ef04df15 ``` ## Results | Check | Result | |---|---| | Diff and conventions | Passed. | | Current-main merge preview | Passed against `45e39c7ad16c93871809eee8c81c3865596e883f`. | | Export ABI audit | Passed with 3 unrelated existing explicit-alias warnings; no finding for `__std_free_crt`. The precheck’s isolated copy lacked the local-only audit helper, so I ran the audit directly against the exact base and head. | | Test-quality check | Heuristic flagged possible test-registration trouble; source inspection confirms `ApplicationHeap.cpp` is built into `application_heap_tests` and the scripting test is registered. | | PR overlap | The current overlap report identifies open #9677 in `docs/dev/debt/libc.md` at current-main line 68. Pairwise merge preview with #9677 reports a content conflict in that file. Pairwise previews with #12184 and #11848 are clean. | | Hosted CI at final refresh | Windows, Ubuntu and Windows relinker, ASan, Ubuntu register-context, conventions, intake, eligibility, labels, report, and library-portability passed. Linux product tests were skipped. macOS relinker, register-context and write-watch jobs were queued. | <details> <summary>Unedited check output</summary> Precheck command output: ```text /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/report.md /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13828/report.json Conclusion: checks failed ``` The precheck’s conventions output: ```text All conventions checks passed. ``` Direct ABI-audit summary: ```text status: passed_with_warnings findings: 3 target findings: [] ``` Test-quality output: ```json { "findings": [ { "path": "core/libs/tests/ApplicationHeap.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." } ], "negative_control_candidates": [], "limits": [ "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.", "A test that passes against base is not by itself proof that the PR test is inadequate.", "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error." ] } ``` Relevant overlap-report row: ```text | [PR 9677](https://www.github.com/boykopovar/AnyPS5/pull/9677) | `docs/dev/debt/libc.md` [L68](https://github.com/boykopovar/AnyPS5/blob/45e39c7ad16c93871809eee8c81c3865596e883f/docs/dev/debt/libc.md#L68) | | | ``` Pairwise merge output with #9677: ```text 9a8378c1e68c49c4cb99af789d4095288 100644 568e1931c1abf7cdfc763a4e8d7e8c0c5cebefb6 1 docs/dev/debt/libc.md 100644 e463077515d88ae6063cace01c374095eee7260c 2 docs/dev/debt/libc.md 100644 90228bbb4bdc6574e8e1aff000bde82daa0c8854 3 docs/dev/debt/libc.md Auto-merging core/libs/prx/libc/src/Time.cpp Auto-merging core/libs/prx/libkernel/Time/Time.cpp Auto-merging core/libs/tests/GuestProcessTime.cpp Auto-merging docs/dev/debt/libc.md CONFLICT (content): Merge conflict in docs/dev/debt/libc.md EXIT:1 ``` Current hosted check snapshot: ```text linux completed skipped register-context (macos-15-intel, Release) queued relinker (macos-latest, clang++, x86_64) queued relinker (macos-latest, clang++) queued relinker-asan completed success relinker (ubuntu-latest, g++) completed success windows completed success write-watch (macos-15) queued register-context (ubuntu-latest, Release) completed success write-watch (macos-15-intel) queued relinker (windows-latest, g++) completed success register-context (ubuntu-latest, Debug) completed success labels completed success conventions completed success intake completed success eligibility completed success report completed success library-portability completed success ``` </details> ## Findings ### Blocking - **Unresolved landing order with #9677.** The live overlap report identifies a shared edit in `docs/dev/debt/libc.md`, and a pairwise merge preview of these exact heads confirms a content conflict. The repository requires agreeing with the other PR author on which lands first and recording that order with `Depends on`; this PR still says `Depends on: none`, and no agreement with #9677’s author is recorded. Please coordinate the order and update the relevant checklist entry or entries, then recheck the pairwise merge. ### Non-blocking - The scripting test currently allocates with `malloc_nid_postfix` before calling `__std_free_crt`. A direct `__std_calloc_crt` to `__std_free_crt` case would exercise the exact allocation/free pair motivating this PR; the existing callback test still gives useful evidence for the shared heap path. ## Sources - [Current contribution rule for overlap order](https://github.com/boykopovar/AnyPS5/blob/45e39c7ad16c93871809eee8c81c3865596e883f/CONTRIBUTING.md#L69). - [The overlapping #9677 debt edit at its reviewed head](https://github.com/boykopovar/AnyPS5/blob/6ac7ce9e401899294b07fd56eea0ec72a6fb0980/docs/dev/debt/libc.md#L63). - [The new export implementation](https://github.com/boykopovar/AnyPS5/blob/87b2b8895c5ee30ebafd7f141d254602a08b1225/core/libs/prx/libc/src/FileAndHeap.cpp#L658-L664) and [its current test](https://github.com/boykopovar/AnyPS5/blob/87b2b8895c5ee30ebafd7f141d254602a08b1225/core/libs/tests/ApplicationHeap.cpp#L278-L283). - [Test registration on current main](https://github.com/boykopovar/AnyPS5/blob/45e39c7ad16c93871809eee8c81c3865596e883f/core/libs/prx/libc/CMakeLists.txt#L1213-L1225). - [Microsoft STL wrapper source pinned by the PR](https://github.com/microsoft/STL/blob/b6f01e438b68ee497f9c08313e49d12bb2f0d8e0/stl/src/tzdb.cpp#L651-L653). ## Not verified - No local build, C++ tests or negative control. The PR description reports exact-head builds and focused CTest runs on WSL2 and Windows, but those runs were not independently reproduced here. - No console measurement. macOS CI jobs were still queued; Linux product tests were skipped. ## To get this to a good state Please agree and record the landing order with #9677’s author. I will rerun the overlap and merge checks, then reassess the new exact head.
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!13828
No description provided.