Skip to content

feat(libc): implement malloc_stats - #17724

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
zkiller1236:feat/libc-malloc-stats
Nov 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
zkiller1236:feat/libc-malloc-stats

Conversation

@zkiller1236

Copy link
Copy Markdown
Contributor

What

malloc_stats (libSceLibcInternal, NID CC-BLMBu9-I) was a parameterless stub that threw NotImplemented. It is now int malloc_stats(void* stats) in libc, next to malloc_stats_fast, and the libSceLibcInternal stub is removed so imports reach the libc export.

  • With an application allocator it calls entry 7 of the replacement table. In KytyPS5's MallocReplace malloc_stats sits immediately before malloc_stats_fast (entry 8) and malloc_usable_size (entry 9), which libc already calls. A table that leaves the entry null throws, as malloc_stats_fast does.
  • With the default allocator it fills the block exactly as malloc_stats_fast does, since the default heap's accounting is already exact: size 0x28 / version 1 returns 0 and writes the four sizes; any other size or version returns 1 and writes nothing; a null block throws.
  • The two stats paths share one helper in ApplicationHeap.cpp.

The debt entry moves from libSceLibcInternal.md to libc.md: nothing is measured on a PS5, the one-pointer signature follows malloc_stats_fast and the sceLibcMspaceMallocStats block, and the size/version check was measured only for malloc_stats_fast (#11870).

Tested

Linux x86-64, GCC, Release with BUILD_TESTING=ON, on main 9490483.

  • application_heap_stats, application_heap_stats_default and application_heap_stats_missing pass. They now also check that malloc_stats calls entry 7 (not entry 8) with the caller's pointer, null included, and returns its result; that an allocation from inside the callback is rejected; that the default heap returns the same values as malloc_stats_fast before and after allocating and freeing; that invalid sizes/versions return 1 with the block unchanged; that null throws; and that a missing entry throws.
  • Negative control: pointing malloc_stats at entry 8 makes application_heap_stats abort.
  • nm -D shows malloc_stats_nid_postfix exported by libc.prx and no longer by libSceLibcInternal.prx.
  • check_conventions.py --base origin/main passes. pr_overlap.py reports only feat(libc): answer the CRT setup table and heap parameter queries #17008, which edits the neighbouring lines in Api.hpp and FileAndHeap.cpp but not these functions, so either merge order works and the later one resolves a one-line conflict.

Windows and PS5/title execution are untested.

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 assisted with the implementation, tests and review.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Windows check of head eef67f07fd, merged onto main a26b7827e1 (fc2f86a974, 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.

  • application_heap_stats, application_heap_stats_default, application_heap_stats_missing pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Progress report (7525f56 → eef67f0)

📈 System libraries: 35.02% (+0.0026%, +1 implemented, -1 removed functions)

✅ 1 implemented
Library Name
libc malloc_stats_nid_postfix
🗑️ 1 removed
Library Name
libSceLibcInternal malloc_stats_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1738/1746 (99.54%) 1739/1747 (99.54%) +0.0003%
libSceLibcInternal 323/1137 (28.41%) 323/1136 (28.43%) +0.03%

@github-actions

github-actions Bot commented Nov 9, 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 18389 docs/dev/debt/libc.md L78

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 docs/dev/debt/libSceLibcInternal.md
docs/dev/debt/libc.md
PR 7447 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9087 docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9466 docs/dev/debt/libc.md
PR 9526 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 10409 docs/dev/debt/libc.md
PR 10780 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 11109 docs/dev/debt/libc.md
PR 11172 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11625 docs/dev/debt/libc.md
PR 11634 docs/dev/debt/libc.md
PR 11661 docs/dev/debt/libc.md
PR 11689 docs/dev/debt/libc.md
PR 11698 docs/dev/debt/libc.md
PR 11726 docs/dev/debt/libc.md
PR 11848 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12574 docs/dev/debt/libc.md
PR 12682 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12688 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12700 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12849 core/libs/prx/libc/src/GuestHeap.cpp
docs/dev/debt/libc.md
PR 12965 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 13449 docs/dev/debt/libc.md
PR 13778 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
docs/dev/debt/libSceLibcInternal.md
PR 13782 docs/dev/debt/libSceLibcInternal.md
PR 13794 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libSceLibcInternal.md
docs/dev/debt/libc.md
PR 14834 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
docs/dev/debt/libSceLibcInternal.md
PR 15095 docs/dev/debt/libc.md
PR 15822 docs/dev/debt/libSceLibcInternal.md
PR 16237 docs/dev/debt/libSceLibcInternal.md
PR 17008 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 17010 core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libc.md
PR 17259 docs/dev/debt/libc.md
PR 17300 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
docs/dev/debt/libSceLibcInternal.md
PR 18122 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libSceLibcInternal.md
docs/dev/debt/libc.md
PR 18135 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp
core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libSceLibcInternal.md
PR 18347 docs/dev/debt/libc.md
PR 18524 docs/dev/debt/libc.md

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head eef67f07fd, merged onto main 28237a8567 (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release, BUILD_TESTING=ON, Python 3.15.

  • Tests built from this PR's test files: application_heap_stats, application_heap_stats_default, application_heap_stats_missing.
  • All of them pass in 3 of 3 runs.
  • Negative control: with this PR's code reverted to main, the tests do not build (core/libs/tests/ApplicationHeapStats.cpp:84:18: error: 'malloc_stats_nid_postfix' was not declared in this scope; did you mean 'malloc_stats_fast_nid_postfix'?), which is expected when the tests use interfaces the PR adds or changes.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit 34c50d6 into boykopovar:main Nov 12, 2026
22 checks passed
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.

4 participants