Handle the full ERA attribute word in era_heap on the desktop #134

Manually merged
github merged 1 commit from gh-pr/134/head into gh-pr/134/base 2026-11-26 21:29:17 +00:00
Owner

@⁠thegl0w on GitHub · 2026-11-21 16:49 UTC · original
thegl0w:era-heap-full-attributes → main · +247 −34 · 6 files · 1 commits · merged 2026-11-21 17:57 UTC

AI-generated: This change and its description were written by an AI assistant (Claude, using Claude Code) and submitted with the account owner's approval. The tests listed were run by the AI on the account owner's PC.

Refs #126

This PR covers desktop handling of the two recorded attribute words. It does not settle their Scarlett semantics, which stay open in #126.

Desktop handling (measured)

era_heap used to accept only the alignment field and returned null for both words recorded at the Bink and AMD XMemAlloc call sites. It now splits the word with SlimEra's Xbox One ERA layout: object type 0–13, page size 14–15, allocator ID 16–23, log2 alignment 24–28, memory type 29–32, reserved 33–63.

  • Heap (type 0): the CRT heap at the requested alignment (minimum 16), zero-filled. The page size is ignored, as in SlimEra's default heap.
  • Graphics (types 1–6): a separate VirtualAlloc(MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) region on the allocation granularity. This is ordinary CPU-visible memory; no GPU mapping or caching is modeled.
  • Tags: object type and allocator ID don't change placement.
  • Null pointer for physical types 7–9, undefined types 10–15, page-size value 3, any reserved bit, and graphics requests whose page size or alignment exceeds the allocation granularity.

release(void*) keeps its heap-only signature and behavior, so existing callers such as era_heap_reuse's unique_ptr<void, decltype(&era_heap::release)> are unchanged. The new release_with_attributes(void*, attributes) frees by attribute word, as XMemFree callers do.

Unconfirmed on Scarlett

  • That Scarlett uses the ERA layout. Under that layout the alignment fields give 32 bytes (Bink) and 256 bytes (AMD), matching each caller's own arithmetic. Two independent callers agreeing is evidence, not proof.
  • The meaning of allocator ID 0xe5.
  • The GPU visibility and caching of memory type 5 and the other graphics types.
  • The console's error conventions.

Tests

  • New era_heap_observed_words (desktop handling):
    • splits both words into the fields above;
    • Bink-style 97- and 193-byte blocks come back 32-byte aligned and zeroed, and the wrapper recovers its base;
    • AMD-rounded requests from 256 to 65,792 bytes start a committed read-write region on a 64 KiB boundary, are zeroed and writable, and VirtualQuery reports MEM_FREE after release_with_attributes;
    • nonzero tags leave heap placement unchanged.
  • era_heap_failure: reworked for the new policy. Each reserved bit is tried with a heap alignment and with the AMD word, along with types 7–15, page size 3, 4 MB graphics pages, a 128 KiB graphics alignment, zero size and excessive size.
  • era_heap_caller_layout: its Bink-style storage now uses the recorded Bink word.
  • era_heap_reuse (from main) is unchanged and passes.

Mutation check: each deliberately broken variant failed at least one case.

  • Removing the graphics path fails observed_words.
  • Accepting physical types fails failure.
  • Ignoring the heap alignment fails allocation and caller_layout.

Rebased on main at 583fee5. Windows 11 build 26300, MSVC 19.44.35229, CMake 4.4.4, dev preset (Debug):

ctest --preset dev --no-tests=error -R '^era_heap_' -V
100% tests passed out of 6

Outputs: era_heap_observed_words prints bink_blocks=2 amd_blocks=4 granularity=65536, and era_heap_reuse prints reuse_cases=9 recycled_address=9. src/era_heap.cpp also compiles cleanly with /W4 /WX /permissive-.

Full CI-equivalent run (cmake --build --preset dev, then ctest --preset dev --no-tests=error -E '_hardware$', with the requirements-dev.txt environment):

Tests passed Capability skips Compiler warnings
This branch 68/68 bvh_wave64_warp, wave_shuffle_warp 0
main 67/67 same two 0

The one extra test is era_heap_observed_words.

🤖 Generated with Claude Code

**@⁠thegl0w** on GitHub · 2026-11-21 16:49 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/134) `thegl0w:era-heap-full-attributes` → `main` · +247 −34 · 6 files · 1 commits · merged 2026-11-21 17:57 UTC > **AI-generated:** This change and its description were written by an AI assistant (Claude, using Claude Code) and submitted with the account owner's approval. The tests listed were run by the AI on the account owner's PC. Refs #126 This PR covers **desktop handling** of the two recorded attribute words. It does not settle their Scarlett semantics, which stay open in #126. ## Desktop handling (measured) `era_heap` used to accept only the alignment field and returned null for both words recorded at the Bink and AMD `XMemAlloc` call sites. It now splits the word with SlimEra's Xbox One ERA layout: object type 0–13, page size 14–15, allocator ID 16–23, log2 alignment 24–28, memory type 29–32, reserved 33–63. - **Heap (type 0):** the CRT heap at the requested alignment (minimum 16), zero-filled. The page size is ignored, as in SlimEra's default heap. - **Graphics (types 1–6):** a separate `VirtualAlloc(MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)` region on the allocation granularity. This is ordinary CPU-visible memory; no GPU mapping or caching is modeled. - **Tags:** object type and allocator ID don't change placement. - **Null pointer** for physical types 7–9, undefined types 10–15, page-size value 3, any reserved bit, and graphics requests whose page size or alignment exceeds the allocation granularity. `release(void*)` keeps its heap-only signature and behavior, so existing callers such as `era_heap_reuse`'s `unique_ptr<void, decltype(&era_heap::release)>` are unchanged. The new `release_with_attributes(void*, attributes)` frees by attribute word, as `XMemFree` callers do. ## Unconfirmed on Scarlett - That Scarlett uses the ERA layout. Under that layout the alignment fields give 32 bytes (Bink) and 256 bytes (AMD), matching each caller's own arithmetic. Two independent callers agreeing is evidence, not proof. - The meaning of allocator ID `0xe5`. - The GPU visibility and caching of memory type 5 and the other graphics types. - The console's error conventions. ## Tests - **New `era_heap_observed_words`** (desktop handling): - splits both words into the fields above; - Bink-style 97- and 193-byte blocks come back 32-byte aligned and zeroed, and the wrapper recovers its base; - AMD-rounded requests from 256 to 65,792 bytes start a committed read-write region on a 64 KiB boundary, are zeroed and writable, and `VirtualQuery` reports `MEM_FREE` after `release_with_attributes`; - nonzero tags leave heap placement unchanged. - **`era_heap_failure`:** reworked for the new policy. Each reserved bit is tried with a heap alignment and with the AMD word, along with types 7–15, page size 3, 4 MB graphics pages, a 128 KiB graphics alignment, zero size and excessive size. - **`era_heap_caller_layout`:** its Bink-style storage now uses the recorded Bink word. - **`era_heap_reuse`** (from main) is unchanged and passes. **Mutation check:** each deliberately broken variant failed at least one case. - Removing the graphics path fails `observed_words`. - Accepting physical types fails `failure`. - Ignoring the heap alignment fails `allocation` and `caller_layout`. Rebased on `main` at `583fee5`. Windows 11 build 26300, MSVC 19.44.35229, CMake 4.4.4, dev preset (Debug): ``` ctest --preset dev --no-tests=error -R '^era_heap_' -V 100% tests passed out of 6 ``` Outputs: `era_heap_observed_words` prints `bink_blocks=2 amd_blocks=4 granularity=65536`, and `era_heap_reuse` prints `reuse_cases=9 recycled_address=9`. `src/era_heap.cpp` also compiles cleanly with `/W4 /WX /permissive-`. **Full CI-equivalent run** (`cmake --build --preset dev`, then `ctest --preset dev --no-tests=error -E '_hardware$'`, with the `requirements-dev.txt` environment): | | Tests passed | Capability skips | Compiler warnings | |---|---|---|---| | This branch | 68/68 | `bvh_wave64_warp`, `wave_shuffle_warp` | 0 | | `main` | 67/67 | same two | 0 | The one extra test is `era_heap_observed_words`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Split the attribute word with the Xbox One ERA layout and serve heap and
graphics memory types on the desktop. Object type and allocator ID are
carried as tags. Physical types, undefined values, reserved bits and
graphics alignments above the allocation granularity still return null.
release(void*) keeps its heap-only behavior; release_with_attributes frees
by attribute word as XMemFree callers do. Add era_heap_observed_words for
the recorded Bink and AMD words.

This covers desktop handling only. Whether Scarlett uses the ERA layout,
the meaning of allocator ID 0xe5 and the GPU visibility of graphics types
remain open.

Refs #126

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:29:16 +00:00
github manually merged commit a8c92e3a8f into gh-pr/134/base 2026-11-26 21:29:17 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 17:17 UTC · original

Please resolve the conflict with main and keep #126 open for the unresolved Scarlett semantics. Please use Refs #126 and distinguish desktop handling of the observed words from confirmed allocator-ID and GPU-visibility behavior.

**@⁠R0Y00** on GitHub · 2026-11-21 17:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/134#issuecomment-7066364401) Please resolve the conflict with main and keep #126 open for the unresolved Scarlett semantics. Please use Refs #126 and distinguish desktop handling of the observed words from confirmed allocator-ID and GPU-visibility behavior.
This discussion has been locked. Commenting is limited to contributors.
No description provided.