The Bink heap shim duplicates the ERA heap policy #187

Closed
opened 2026-11-21 18:10:35 +00:00 by raulmoracode · 0 comments
raulmoracode commented 2026-11-21 18:10:35 +00:00 (Migrated from github.com)
Contributor

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


Problem

The desktop Bink shim and the ERA heap experiment implement the same XMemAlloc/XMemFree policy twice.

  • src/era_heap.cpp decodes the public XALLOC_ATTRIBUTES layout (page size, allocator id, alignment, memory type), aligns heap blocks, zeroes them and releases heap and graphics types.
  • tests/cpu/bink_heap_provider.cpp accepted the single word 0x05e50000, allocated with HeapAlloc and released with HeapFree, with no alignment or zeroing rule of its own.

The two agree today only because the Bink caller happens to request a 32-byte alignment and writes its own headroom. Nothing enforces that they stay in step, and #132 records this as a missing shared contract for shimmed calls.

Proposed change

Serve the binding from era_heap: windows_allocate calls era_heap::allocate(bytes, flags) and windows_release calls era_heap::release_with_attributes(base, flags). Keep the profile's own guard (a nonempty payload needs 64 bytes of headroom) and the observer hooks used by the test.

This does not widen which words the Bink profile accepts; it makes the allocation and release policy come from the one implementation that decodes the word.

Verification path

bink_heap_check.py gains 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. ctest --preset dev --no-tests=error -R '^(cpu_aot_bink_heap|era_heap_)' covers the binding and the heap scenarios.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532566063 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/188). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T18:10:35Z. --- ## Problem The desktop Bink shim and the ERA heap experiment implement the same `XMemAlloc`/`XMemFree` policy twice. - `src/era_heap.cpp` decodes the public `XALLOC_ATTRIBUTES` layout (page size, allocator id, alignment, memory type), aligns heap blocks, zeroes them and releases heap and graphics types. - `tests/cpu/bink_heap_provider.cpp` accepted the single word `0x05e50000`, allocated with `HeapAlloc` and released with `HeapFree`, with no alignment or zeroing rule of its own. The two agree today only because the Bink caller happens to request a 32-byte alignment and writes its own headroom. Nothing enforces that they stay in step, and #132 records this as a missing shared contract for shimmed calls. ## Proposed change Serve the binding from `era_heap`: `windows_allocate` calls `era_heap::allocate(bytes, flags)` and `windows_release` calls `era_heap::release_with_attributes(base, flags)`. Keep the profile's own guard (a nonempty payload needs 64 bytes of headroom) and the observer hooks used by the test. This does not widen which words the Bink profile accepts; it makes the allocation and release policy come from the one implementation that decodes the word. ## Verification path `bink_heap_check.py` gains 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. `ctest --preset dev --no-tests=error -R '^(cpu_aot_bink_heap|era_heap_)'` covers the binding and the heap scenarios. _AI-assisted._
Sign in to join this conversation.
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#187
No description provided.