fix(libc): back every native mspace trace slot #8049

Merged
MarcZX10 merged 3 commits from upstream-pr/8049 into main 2026-10-20 05:30:55 +00:00
MarcZX10 commented 2026-10-19 18:47:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T18:47:52Z.


What

Extend the libc mspace trace table from 64 to 65 entries so the highest index selected by the native consumer, 64, has writable backing storage. Preserve the LibcHeapInfo ABI, mask, and base slot. Add a boundary test that obtains the returned table and writes both the base and final slots.

Tested

Linux, Debug build with AddressSanitizer: guest_heap_trace_info reproduced a global buffer overflow at slot 64 before the capacity change, then passed after it. Built guest_heap_trace_info_tests with Ninja.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4925756464 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8049). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T18:47:52Z. --- ### What Extend the libc mspace trace table from 64 to 65 entries so the highest index selected by the native consumer, 64, has writable backing storage. Preserve the `LibcHeapInfo` ABI, mask, and base slot. Add a boundary test that obtains the returned table and writes both the base and final slots. ### Tested Linux, Debug build with AddressSanitizer: `guest_heap_trace_info` reproduced a global buffer overflow at slot 64 before the capacity change, then passed after it. Built `guest_heap_trace_info_tests` with Ninja. ### Checklist - [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
github-actions[bot] commented 2026-10-19 18:59:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T18:59:19Z.


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 6044 core/libs/prx/libc/CMakeLists.txt
PR 6819 core/libs/prx/libc/CMakeLists.txt
PR 7081 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/prx/libc/CMakeLists.txt
PR 7332 core/libs/prx/libc/CMakeLists.txt
PR 7447 core/libs/prx/libc/CMakeLists.txt
PR 7715 core/libs/prx/libc/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274917817 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8049#issuecomment-6274917817). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T18:59:19Z. --- <!-- pr-overlap --> 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](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `core/libs/prx/libc/CMakeLists.txt` |
wachi35676 commented 2026-10-20 00:16:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T00:16:13Z.


Windows 11, Ryzen 5 9600X, WinLibs GCC 15.2.0 (UCRT), Release, BUILD_TESTING=ON. Head 0a3af80de merged onto main eb7500680.

  • guest_heap_trace_info passes.
  • Negative control: I put HeapDiagnostics.cpp back to the 64-entry table and rebuilt. The test still passes (1/1 Test #207: guest_heap_trace_info ... Passed). Without AddressSanitizer, the write to mstate_table[64] lands in whatever global comes next, and the read-back succeeds. The Windows CI and the default Linux build don't use ASan, so this test does not guard the fix there.
    • To make it fail without ASan, the test could check the slot's position: &info.mstate_table[64] lies inside the object the library owns, or an adjacent sentinel is unchanged. The other way is to run this test only in an ASan job.
  • The description says the "native consumer" selects index 64, but neither the PR, the commit messages nor a debt entry names that consumer or where index 64 comes from (a mask bit count, a tzcnt of 0, or something else). ae2e5cba7, which added the table, has no source for 64 either. A line naming the guest code that indexes slot 64 would let a reviewer check the bound.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6280250659 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8049#issuecomment-6280250659). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T00:16:13Z. --- Windows 11, Ryzen 5 9600X, WinLibs GCC 15.2.0 (UCRT), Release, `BUILD_TESTING=ON`. Head `0a3af80de` merged onto `main` eb7500680. - `guest_heap_trace_info` passes. - Negative control: I put `HeapDiagnostics.cpp` back to the 64-entry table and rebuilt. The test still passes (`1/1 Test #207: guest_heap_trace_info ... Passed`). Without AddressSanitizer, the write to `mstate_table[64]` lands in whatever global comes next, and the read-back succeeds. The Windows CI and the default Linux build don't use ASan, so this test does not guard the fix there. - To make it fail without ASan, the test could check the slot's position: `&info.mstate_table[64]` lies inside the object the library owns, or an adjacent sentinel is unchanged. The other way is to run this test only in an ASan job. - The description says the "native consumer" selects index 64, but neither the PR, the commit messages nor a debt entry names that consumer or where index 64 comes from (a mask bit count, a `tzcnt` of 0, or something else). `ae2e5cba7`, which added the table, has no source for 64 either. A line naming the guest code that indexes slot 64 would let a reviewer check the bound. AI-assisted: yes (Claude Code); results above were run on this machine.
MarcZX10 commented 2026-10-20 01:27:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T01:27:19Z.


Thanks for checking the non-ASan negative control. I pushed 40cd706127 as a follow-up. It names the 65-slot capacity and asserts both the required count and the backing array extent at compile time, so reducing the table to 64 now fails a normal build, including without AddressSanitizer. The returned-pointer test still writes and reads slots 0 and 64. On Linux, I compiled and ran the exact test with HeapDiagnostics.cpp; both passed. As a negative control, changing the declared capacity to 64 fails at the compile-time assertion. The conventions checker and git diff --check pass.\n\nI also searched the current repository for consumers of mstate_table; it only contains this export returning the pointer, so I cannot cite an in-tree caller that selects index 64. The PR description currently states that selection as observed behavior, but the trace or source identifying the native consumer is not attached here yet.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281163690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8049#issuecomment-6281163690). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T01:27:19Z. --- Thanks for checking the non-ASan negative control. I pushed `40cd706127` as a follow-up. It names the 65-slot capacity and asserts both the required count and the backing array extent at compile time, so reducing the table to 64 now fails a normal build, including without AddressSanitizer. The returned-pointer test still writes and reads slots 0 and 64. On Linux, I compiled and ran the exact test with `HeapDiagnostics.cpp`; both passed. As a negative control, changing the declared capacity to 64 fails at the compile-time assertion. The conventions checker and `git diff --check` pass.\n\nI also searched the current repository for consumers of `mstate_table`; it only contains this export returning the pointer, so I cannot cite an in-tree caller that selects index 64. The PR description currently states that selection as observed behavior, but the trace or source identifying the native consumer is not attached here yet.
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!8049
No description provided.