Skip to content

feat(libc): implement malloc_stats_fast through the application allocator - #2039

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
Aryansh1520:feat/libc-malloc-stats-fast
Oct 9, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
Aryansh1520:feat/libc-malloc-stats-fast

Conversation

@Aryansh1520

Copy link
Copy Markdown
Contributor

What

A title that replaces the allocator through its libc parameters also supplies malloc_stats_fast in that table, at the entry already recorded in MallocReplace. PPSA28997 (God of War Sons of Sparta) calls it. malloc_stats_fast is now exported and forwarded to the title's function, under the same checks and callback scope as the other application-heap calls. Without a replacement allocator that provides it, the call throws.

Tested

  • Linux (CachyOS, kernel 7.2), GCC: PPSA28997 (God of War Sons of Sparta) runs past the calls.
  • tools/check_conventions.py --base origin/main and tools/pr_overlap.py --branch pass.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

…ator

A title that replaces the allocator through its libc parameters also
supplies malloc_stats_fast in that table, and PPSA28997 calls it. It is
now forwarded to the title's function. Without a replacement allocator
that provides it, the call throws.
@github-actions github-actions Bot added the libc label Oct 9, 2026
@MarcZX10

MarcZX10 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

The callback path follows the existing heap lock and callback-scope pattern. Please add coverage for forwarding a supplied slot-8 callback and for the missing-allocator/missing-slot error paths; these are the new behavior and currently have no regression test. GitHub reports no checks on this head, so please get the relevant CI jobs running before merge.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Same as #2038: the log line where PPSA28997 stops on main at malloc_stats_fast, please.

@Aryansh1520

Copy link
Copy Markdown
Contributor Author

Added coverage in bdeef94 (application_heap_tests):

  • forwarding: a replacement table with a slot-8 callback. malloc_stats_fast passes the caller's pointer through, including null, and returns the callback's result.
  • callback scope: a slot-8 callback that calls back into the heap is rejected as a recursive allocator callback.
  • missing allocator: malloc_stats_fast before any allocator is registered throws.
  • missing slot: it throws with the default host allocator (application_heap_default) and with a replacement allocator whose slot 8 is null (new application_heap_missing_stats). In the second case the other heap calls still work and no callback runs.

Removing the forwarding, the missing-slot check or the callback scope each makes a test fail.

Where PPSA28997 stops: malloc_stats_fast is imported by eboot.elf. When it was a not-implemented stub in my local build, the title aborted during startup:

[libc] unhandled exception 'St13runtime_error' thrown from 0x7fcc74250769
terminate called after throwing an instance of 'std::runtime_error'
  what():  malloc_stats_fast not implemented

Main doesn't export it at all (KuOuD58hqn4). On main (as of Oct 8) the title stops earlier, at LTov9gMEqCU (std::ios_base::_Addstd, #545).

The build workflows on this head are waiting for approval to run (fork PR).

@Aryansh1520

Copy link
Copy Markdown
Contributor Author

Moved the malloc_stats_fast checks out of ApplicationHeap.cpp into their own test, ApplicationHeapStats.cpp, in 7fc6fac. It runs in three modes: application_heap_stats, application_heap_stats_default and application_heap_stats_missing. This PR no longer touches the file #1900 changes. The coverage is the same as before: forwarding, the nested-call rejection, no allocator, the default allocator and a missing slot 8. Removing the forwarding, the slot check or the callback scope still fails a test. I also checked that the PR merges cleanly with #1900 and that malloc_stats_fast only uses state #1900 keeps.

@popcoder565

Copy link
Copy Markdown
Contributor

Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 7fc6fac1, merged onto main d70b899 together with #1324, #2193 and #2247.

No title was run.

🤖 Addressed by Claude Code

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on Linux (GCC), merged onto current main: build + ctest green (532/532); the three application_heap_stats* tests pass and do not link without the change. Slot 8 of MallocReplace matches malloc_stats_fast in KytyPS5's replace table, and the checks and callback scope match the other application-heap calls. Windows run by @popcoder565 also passes. Merging.

@adriadam10
adriadam10 merged commit befbf64 into boykopovar:main Oct 9, 2026
6 checks passed
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Progress report (d70b899 → 7fc6fac)

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

✅ 1 implemented
Library Name
libc malloc_stats_fast_nid_postfix

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.

5 participants