Memory: size executable arenas for the requested allocation #1146

Open
anakatt wants to merge 1 commit from upstream-pr/1155 into main
anakatt commented 2026-11-24 12:35:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by anakatt on 2026-11-24T12:35:48Z.


I make alloc_code honor requests larger than its default 64 KiB arena. Previously, it committed only 64 KiB and advanced the allocation cursor by the larger requested size, returning a pointer without enough backing memory.

What is in it

  • stubs.rs: size each new arena for the aligned request, reject alignment overflow before locking, and compare against remaining capacity without overflowing an address addition.
  • VirtualQuery regression for large requests and a subsequent small request; overflow regression and allocation-contract documentation.

This is independent of #936's unwind registration; it does not add unwind metadata.

Tested

I ran debug tests on Windows 11 Pro ARM64 10.0.26100.1742 in UTM (4 GiB RAM, virtual virt-10.0 CPU, Red Hat VirtIO GPU DOD), with Rust 1.100.0 x86_64-pc-windows-msvc and Visual Studio 2022 Build Tools. The guest used main 47efa2ecea0a12934719ae69b81930cf02a4b1c3 plus the source changes committed as a59c84e8309560e5dbf90e17ae965ee6d0c82212.

  • Before the fix, cargo test --locked -p xcl --lib stubs::tests::executable_allocations_cover_the_requested_size -- --exact: 0 passed, 1 failed, 0 ignored, 720 filtered out. VirtualQuery showed 65,537 requested bytes backed by only 65,536 committed bytes; the test did not write past the allocation.
  • After the fix, cargo test --locked -p xcl --lib stubs::tests -- --test-threads=4: 5 passed, 0 failed, 0 ignored, 716 filtered out; no SKIPPED output. This includes the allocation regressions, generated stub execution and concurrent stub reuse.

Not tested

I have not run the release profile, full workspace suite, native x64 Windows hardware, D3D12 GPU execution or a real title. I have not observed a game requesting an executable allocation larger than 64 KiB; this reproduces the allocator contract failure directly.

Regression run

Not run. This remains a draft pending the required real-title xcl-smoke blocks from main and this PR's clean head, with the same title and duration.

AI use

I used omp (openai-codex/gpt-6-astra) to investigate, implement the fix and regressions, run the Windows tests, and prepare this PR.

<!-- greyfinch-sync:ivall/xcl:issue:5472260717 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1155). Originally posted by [anakatt](https://github.com/anakatt) on 2026-11-24T12:35:48Z. --- I make `alloc_code` honor requests larger than its default 64 KiB arena. Previously, it committed only 64 KiB and advanced the allocation cursor by the larger requested size, returning a pointer without enough backing memory. ## What is in it - `stubs.rs`: size each new arena for the aligned request, reject alignment overflow before locking, and compare against remaining capacity without overflowing an address addition. - `VirtualQuery` regression for large requests and a subsequent small request; overflow regression and allocation-contract documentation. This is independent of #936's unwind registration; it does not add unwind metadata. ## Tested I ran debug tests on Windows 11 Pro ARM64 10.0.26100.1742 in UTM (4 GiB RAM, virtual `virt-10.0` CPU, Red Hat VirtIO GPU DOD), with Rust 1.100.0 `x86_64-pc-windows-msvc` and Visual Studio 2022 Build Tools. The guest used main `47efa2ecea0a12934719ae69b81930cf02a4b1c3` plus the source changes committed as `a59c84e8309560e5dbf90e17ae965ee6d0c82212`. - Before the fix, `cargo test --locked -p xcl --lib stubs::tests::executable_allocations_cover_the_requested_size -- --exact`: **0 passed, 1 failed, 0 ignored**, 720 filtered out. `VirtualQuery` showed **65,537 requested bytes backed by only 65,536 committed bytes**; the test did not write past the allocation. - After the fix, `cargo test --locked -p xcl --lib stubs::tests -- --test-threads=4`: **5 passed, 0 failed, 0 ignored**, 716 filtered out; no `SKIPPED` output. This includes the allocation regressions, generated stub execution and concurrent stub reuse. ## Not tested I have not run the release profile, full workspace suite, native x64 Windows hardware, D3D12 GPU execution or a real title. I have not observed a game requesting an executable allocation larger than 64 KiB; this reproduces the allocator contract failure directly. ## Regression run Not run. This remains a draft pending the required real-title `xcl-smoke` blocks from main and this PR's clean head, with the same title and duration. ## AI use I used omp (`openai-codex/gpt-6-astra`) to investigate, implement the fix and regressions, run the Windows tests, and prepare this PR.
DavidM1911 commented 2026-11-24 13:03:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T12:51:46Z.


Independent verification on current main 384f7f7 (branch already contains it — clean).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib stubs: 7 passed, 0 failed.
  • cargo test -p xcl --lib arena: 5 passed, 0 failed, 1 ignored — gpu_unified_memory_arena and arena_blocks_come_from_the_pool_when_the_title_took_the_rest exercise the sized-arena path on the real backend.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

<!-- greyfinch-sync:ivall/xcl:comment:7132020822 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1155#issuecomment-7132020822). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T12:51:46Z. --- Independent verification on current `main` `384f7f7` (branch already contains it — clean). **Machine:** Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug. - `cargo test -p xcl --lib stubs`: **7 passed, 0 failed**. - `cargo test -p xcl --lib arena`: **5 passed, 0 failed, 1 ignored** — `gpu_unified_memory_arena` and `arena_blocks_come_from_the_pool_when_the_title_took_the_rest` exercise the sized-arena path on the real backend. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
eizispark commented 2026-11-24 14:06:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by eizispark on 2026-11-24T13:33:11Z.


Hardware test report — commit a59c84e

Verified clean merge with main (47efa2e) on a59c84e8309560e5dbf90e17ae965ee6d0c82212: pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 743 passed, 0 failed, 41 ignored (GPU tests skipped on this adapter: none), including stubs::tests::executable_allocations_cover_the_requested_size and stubs::tests::executable_allocation_rejects_size_overflow

Regression run
main (47efa2e):

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1677 (PresentX 1677)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14853 MB

PR (a59c84e):

xcl-smoke v1
commit: a59c84e8309560e5dbf90e17ae965ee6d0c82212
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1678 (PresentX 1678)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14855 MB

Not tested

  • retail paths requesting single executable stub thunks larger than 64 KB (ARENA_CHUNK); gameplay past the menus

AI use: Antigravity (Google DeepMind), Gemini (exact version string not exposed in runtime environment) — ran the workspace test suite and 60 s retail smoke check on the hardware above and formatted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7132994326 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1155#issuecomment-7132994326). Originally posted by [eizispark](https://github.com/eizispark) on 2026-11-24T13:33:11Z. --- ### Hardware test report — commit `a59c84e` Verified clean merge with `main` (`47efa2e`) on `a59c84e8309560e5dbf90e17ae965ee6d0c82212`: **pass**. **Tested** - Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, release + test profile - `cargo test --workspace --no-fail-fast -- --test-threads=4`: `743 passed, 0 failed, 41 ignored` (GPU tests skipped on this adapter: `none`), including `stubs::tests::executable_allocations_cover_the_requested_size` and `stubs::tests::executable_allocation_rejects_size_overflow` **Regression run** `main` (`47efa2e`): ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: AMD Radeon RX 9070 XT title: GTA6.Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1677 (PresentX 1677) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14853 MB ``` PR (`a59c84e`): ``` xcl-smoke v1 commit: a59c84e8309560e5dbf90e17ae965ee6d0c82212 gpu: AMD Radeon RX 9070 XT title: GTA6.Xbox.v1.0.2.1 seconds: 60 exit: 0x0 frames shown: 1678 (PresentX 1678) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14855 MB ``` **Not tested** - retail paths requesting single executable stub thunks larger than 64 KB (`ARENA_CHUNK`); gameplay past the menus **AI use**: Antigravity (Google DeepMind), Gemini (exact version string not exposed in runtime environment) — ran the workspace test suite and 60 s retail smoke check on the hardware above and formatted this report.
github-actions[bot] commented 2026-11-27 21:26:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-27T21:26:17Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7228443316 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1155#issuecomment-7228443316). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T21:26:17Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 04:56:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:56:12Z.


Triage (#1607) – head a59c84e

No open or merged PR makes the same change; main's stubs.rs alloc_code still always allocates a fixed ARENA_CHUNK, so a request larger than 64 KiB runs past the committed region. #2722 also edits stubs.rs but for stub argument recording, not the arena.
No problems found in the diff: the overflow check runs before ARENA is locked (so the should_panic test cannot poison the mutex), and size > a.1 - a.0 is only evaluated when the arena exists.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301253436 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1155#issuecomment-7301253436). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T04:56:12Z. --- **Triage (#1607)** – head a59c84e No open or merged PR makes the same change; main's stubs.rs alloc_code still always allocates a fixed ARENA_CHUNK, so a request larger than 64 KiB runs past the committed region. #2722 also edits stubs.rs but for stub argument recording, not the arena. No problems found in the diff: the overflow check runs before ARENA is locked (so the should_panic test cannot poison the mutex), and `size > a.1 - a.0` is only evaluated when the arena exists. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1155:upstream-pr/1155'
git switch 'upstream-pr/1155'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1155'
git switch 'upstream-pr/1155'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1155'
git switch 'upstream-pr/1155'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1155'
git switch 'main'
git merge --squash 'upstream-pr/1155'
git switch 'main'
git merge --ff-only 'upstream-pr/1155'
git switch 'main'
git merge 'upstream-pr/1155'
git push origin 'main'
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
xcl-dev/xcl!1146
No description provided.