Check ERA heap zeroing on recycled blocks #103

Merged
Vonsek merged 3 commits from upstream-pr/104 into main 2026-11-21 16:58:43 +00:00
Vonsek commented 2026-11-21 15:59:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T15:59:43Z.


Change

Adds era_heap_reuse, a source-built allocation case for the Windows runtime item "Add a source-built allocation case with a measurable Windows result". It checks that era_heap::allocate returns zeroed memory when the CRT hands back a block that was just released with dirty contents. For alignment exponents 4, 6 and 12 and sizes 64, 257 and 4096 bytes, the test fills a block with 0xa5 and releases it. It then holds up to 32 new blocks of the same shape until the released address returns. Every block must read as zero. The run prints recycled_address, the number of the nine cases in which the dirty address came back. No runtime change was needed.

Verification

Linux, with a posix_memalign stand-in for _aligned_malloc/_aligned_free, using g++ and clang++ at -std=c++20 -O2: all five era_heap_check scenarios pass, and reuse prints reuse_cases=9 recycled_address=9. With the memset removed from src/era_heap.cpp, reuse fails. Under ASan/UBSan the case passes with recycled_address=0 because of the sanitizer's quarantine.

Windows: ctest --preset dev --no-tests=error -R '^era_heap_reuse$' -V at ba26c1a on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): passed in both configurations, printing reuse_cases=9 recycled_address=9 in Debug (the dev preset) and in Release (cmake --preset dev -B out/build/rel -DCMAKE_BUILD_TYPE=Release, then ctest --test-dir out/build/rel -R '^era_heap_reuse$' -V).

Evidence and follow-up

The fixture is synthetic and contains no external inputs. recycled_address is a measurement, not a pass condition, because low-fragmentation heap randomization can delay or prevent address reuse. The docs/experiments.md row records the glibc count and leaves the Windows count to be filled in from this run.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6531085041 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/104). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T15:59:43Z. --- ## Change Adds `era_heap_reuse`, a source-built allocation case for the Windows runtime item "Add a source-built allocation case with a measurable Windows result". It checks that `era_heap::allocate` returns zeroed memory when the CRT hands back a block that was just released with dirty contents. For alignment exponents 4, 6 and 12 and sizes 64, 257 and 4096 bytes, the test fills a block with `0xa5` and releases it. It then holds up to 32 new blocks of the same shape until the released address returns. Every block must read as zero. The run prints `recycled_address`, the number of the nine cases in which the dirty address came back. No runtime change was needed. ## Verification Linux, with a `posix_memalign` stand-in for `_aligned_malloc`/`_aligned_free`, using g++ and clang++ at `-std=c++20 -O2`: all five `era_heap_check` scenarios pass, and `reuse` prints `reuse_cases=9 recycled_address=9`. With the `memset` removed from `src/era_heap.cpp`, `reuse` fails. Under ASan/UBSan the case passes with `recycled_address=0` because of the sanitizer's quarantine. Windows: `ctest --preset dev --no-tests=error -R '^era_heap_reuse$' -V` at ba26c1a on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.12, RTX 5080 (driver 32.0.16.1692): passed in both configurations, printing `reuse_cases=9 recycled_address=9` in Debug (the `dev` preset) and in Release (`cmake --preset dev -B out/build/rel -DCMAKE_BUILD_TYPE=Release`, then `ctest --test-dir out/build/rel -R '^era_heap_reuse$' -V`). ## Evidence and follow-up The fixture is synthetic and contains no external inputs. `recycled_address` is a measurement, not a pass condition, because low-fragmentation heap randomization can delay or prevent address reuse. The `docs/experiments.md` row records the glibc count and leaves the Windows count to be filled in from this run.
upstream-sync closed this pull request 2026-11-24 06:41:20 +00:00
rasptum commented 2026-11-24 06:47:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-21T16:49:22Z.


Windows 10 data point at 1ab002f: Windows 10 22H2 (19045.6466), VS Build Tools 17.14 (MSVC 14.44.35207), SDK 10.0.26100. All five era_heap_* tests passed in both configurations, and era_heap_reuse printed reuse_cases=9 recycled_address=9 in each:

  • Debug (dev preset): 5/5 passed
  • Release (cmake --preset dev -B out/build/rel -DCMAKE_BUILD_TYPE=Release, then ctest --test-dir out/build/rel -R '^era_heap' -V): 5/5 passed

So the Windows 10 CRT heap returned the dirty address in all nine cases, the same count as your Windows 11 run.

AI-assisted (Claude Code); run locally on the configuration above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7065953976 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/104#issuecomment-7065953976). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-21T16:49:22Z. --- Windows 10 data point at `1ab002f`: Windows 10 22H2 (19045.6466), VS Build Tools 17.14 (MSVC 14.44.35207), SDK 10.0.26100. All five `era_heap_*` tests passed in both configurations, and `era_heap_reuse` printed `reuse_cases=9 recycled_address=9` in each: - Debug (`dev` preset): 5/5 passed - Release (`cmake --preset dev -B out/build/rel -DCMAKE_BUILD_TYPE=Release`, then `ctest --test-dir out/build/rel -R '^era_heap' -V`): 5/5 passed So the Windows 10 CRT heap returned the dirty address in all nine cases, the same count as your Windows 11 run. _AI-assisted (Claude Code); run locally on the configuration above._
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
R0Y00/Xbox2Windows!103
No description provided.