Skip to content

feat(libc): answer the two CRT heap entry points the STL calls - #16418

Closed
Opensource55 wants to merge 1 commit into
boykopovar:mainfrom
Opensource55:feat/libc-std-crt-heap
Closed

Opensource55 wants to merge 1 commit into
boykopovar:mainfrom
Opensource55:feat/libc-std-crt-heap

Conversation

@Opensource55

Copy link
Copy Markdown
Contributor

What

The libc bundled with PPSA01341 v01.007.000 exports __std_calloc_crt under NID 1a7K+jO+ST0 and __std_free_crt under y-r+TFZgeUU, both of which are the hashes their names carry under tools/nid_names.py, and this tree answered neither.

Both are one-standing-instruction forwards in the module:

118aa0: push %rbp
118aa1: mov  %rsp,%rbp
118aa4: call calloc (0x6110)     ; arguments untouched
118aa9: pop  %rbp
118aaa: ret

__std_free_crt (0x118ac0) is the same shape over free (0x6100). So the zeroing, the overflow rejection and the routing to whichever heap the title registered all belong to the calloc and free this tree already answers, and forwarding keeps a single heap rather than giving the STL a second one.

Tested

Windows 10 22H2 (19045.6456), MinGW-W64 GCC 15.2.0 (ucrt, Release build), head 81f0d44ee1 on top of main 5779a4ea51; no title was run.

guest_std_crt_heap is new (core/libs/tests/GuestStdCrtHeap.cpp):

  • a block from __std_calloc_crt comes back fully zeroed over the four counts 1, 3, 64, 4096 against the four sizes 1, 2, 7, 64;

  • sixty-four allocate-write-release rounds each come back zeroed again, so the release really returns the block to the heap;

  • a count of SIZE_MAX against a size of 2, and the same pair the other way round, answer null;

  • __std_free_crt(nullptr) is accepted.

  • Red side, with __std_calloc_crt forwarding to malloc instead of calloc: guest_std_crt_heap aborts on the zero check at line 22.

  • Green side: guest_std_crt_heap passes in 0.02 s, and guest_allocator_failures, guest_heap_rounding_overflow and guest_heap_trace_info still pass.

  • tools/check_conventions.py reports All conventions checks passed; objdump -p libc.prx lists both entries.

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

The libc bundled with PPSA01341 v01.007.000 exports __std_calloc_crt under
NID 1a7K+jO+ST0 and __std_free_crt under y-r+TFZgeUU, both of which are the
hashes their names carry under tools/nid_names.py, and this tree answered
neither.

Both are one-standing-instruction forwards in the module: __std_calloc_crt
(0x118aa0) calls calloc (0x6110) with its own arguments untouched and
__std_free_crt (0x118ac0) calls free (0x6100) the same way, so the
zeroing, the overflow rejection and the heap routing all belong to the
calloc and free this tree already answers rather than to a second heap.

guest_std_crt_heap checks that a block comes back zeroed over four counts
and four sizes, that sixty-four allocate-write-release rounds keep coming
back zeroed, that a count and size which cannot be multiplied are rejected
in either order, and that a null block is released.
@JJenkx

JJenkx commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 81f0d44ee1, merged onto main 4c03784113 (b66114bb87, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_std_crt_heap passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Progress report (f2dad16 → 81f0d44)

📈 System libraries: 29.86% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libc __std_calloc_crt_nid_postfix
libc __std_free_crt_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1639/1659 (98.79%) 1641/1661 (98.80%) +0.0015%

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 12184 core/libs/prx/libc/include/Api.hpp L300
core/libs/prx/libc/src/FileAndHeap.cpp L1029
__std_calloc_crt
PR 13828 __std_free_crt

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/CMakeLists.txt
PR 7447 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/FileAndHeap.cpp
PR 7715 core/libs/prx/libc/CMakeLists.txt
PR 8150 core/libs/prx/libc/CMakeLists.txt
PR 8417 core/libs/prx/libc/include/Api.hpp
PR 8965 core/libs/prx/libc/CMakeLists.txt
PR 9466 core/libs/prx/libc/CMakeLists.txt
PR 9526 core/libs/prx/libc/src/FileAndHeap.cpp
PR 10780 core/libs/prx/libc/include/Api.hpp
PR 11831 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
PR 12849 core/libs/prx/libc/CMakeLists.txt
PR 13449 core/libs/prx/libc/CMakeLists.txt
PR 13809 core/libs/prx/libc/CMakeLists.txt
PR 14298 core/libs/prx/libc/CMakeLists.txt
PR 14796 core/libs/prx/libc/include/Api.hpp
PR 15807 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/Api.hpp
PR 16004 core/libs/prx/libc/include/Api.hpp

@Opensource55

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate: #12184 and #13828 by @laloerraz has implemented __std_calloc_crt and __std_free_crt (with #13828) since 2026-10-28, and this PR adds nothing it does not.

I checked only my own branches before opening, which was not enough; the overlap bot caught it and it is right. The branch stays in my fork, and there is nothing here worth porting.

AI-assisted: yes.

@Opensource55
Opensource55 deleted the feat/libc-std-crt-heap branch November 13, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants