runtime: serve the Bink heap shim from era_heap #188

Merged
raulmoracode merged 1 commit from upstream-pr/189 into main 2026-11-21 18:13:09 +00:00
raulmoracode commented 2026-11-21 18:10:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T18:10:42Z.


Change

The Bink heap shim allocated with HeapAlloc and released with HeapFree, duplicating the policy that src/era_heap.cpp already implements from the decoded attribute word. The two could drift while both are described as XMemAlloc/XMemFree bindings.

windows_allocate now calls era_heap::allocate(bytes, flags) and windows_release calls era_heap::release_with_attributes(base, flags). The profile's guard (a nonempty payload needs 64 bytes of headroom) and the observer hooks used by the test are unchanged. The CMake target links src/era_heap.cpp and includes src.

bink_heap_check.py adds two direct calls to the binding: a 97- and a 129-byte request with 0x05e50000 must return a 32-byte-aligned, zeroed block, and the matching release must free it.

Fixes #188

Verification

Commit d4acade on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^(cpu_aot_bink_heap|era_heap_)'

Result:

7/7 Test #60: cpu_aot_bink_heap ................   Passed    0.07 sec
100% tests passed out of 7

The seven are cpu_aot_bink_heap and the six era_heap_* scenarios, including era_heap_observed_words from #134.

Evidence and follow-up

The added assertions are the control for the changed allocation path: they read alignment and contents from the returned block. The previous HeapAlloc path made neither guarantee, so the check is meaningful even though a deterministic unaligned, dirty-memory allocator is not part of the fixture. The existing 32-residue loop in bink_heap_check.py still covers the caller's own headroom arithmetic.

The package-only case cpu_aot_bink_package_heap needs BINK_HEAP_IMAGE and was not run; this change does not touch its translation.

The remaining half of the shared contract is graphics memory: era_heap already serves GRAPHICS_1–6 through VirtualAlloc, but no experiment allocates from that path yet.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532567301 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/189). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T18:10:42Z. --- ## Change The Bink heap shim allocated with `HeapAlloc` and released with `HeapFree`, duplicating the policy that `src/era_heap.cpp` already implements from the decoded attribute word. The two could drift while both are described as `XMemAlloc`/`XMemFree` bindings. `windows_allocate` now calls `era_heap::allocate(bytes, flags)` and `windows_release` calls `era_heap::release_with_attributes(base, flags)`. The profile's guard (a nonempty payload needs 64 bytes of headroom) and the observer hooks used by the test are unchanged. The CMake target links `src/era_heap.cpp` and includes `src`. `bink_heap_check.py` adds two direct calls to the binding: a 97- and a 129-byte request with `0x05e50000` must return a 32-byte-aligned, zeroed block, and the matching release must free it. Fixes #188 ## Verification Commit `d4acade` on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^(cpu_aot_bink_heap|era_heap_)' ``` Result: ```text 7/7 Test #60: cpu_aot_bink_heap ................ Passed 0.07 sec 100% tests passed out of 7 ``` The seven are `cpu_aot_bink_heap` and the six `era_heap_*` scenarios, including `era_heap_observed_words` from #134. ## Evidence and follow-up The added assertions are the control for the changed allocation path: they read alignment and contents from the returned block. The previous `HeapAlloc` path made neither guarantee, so the check is meaningful even though a deterministic unaligned, dirty-memory allocator is not part of the fixture. The existing 32-residue loop in `bink_heap_check.py` still covers the caller's own headroom arithmetic. The package-only case `cpu_aot_bink_package_heap` needs `BINK_HEAP_IMAGE` and was not run; this change does not touch its translation. The remaining half of the shared contract is graphics memory: `era_heap` already serves `GRAPHICS_1`–`6` through `VirtualAlloc`, but no experiment allocates from that path yet. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted._
upstream-sync closed this pull request 2026-11-24 06:41:44 +00:00
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!188
No description provided.