PE loader: under Rosetta 2 a title's masked stores call resumable helpers #1344

Open
github-bot wants to merge 4 commits from github-bot/gh-1344 into main AGit
Owner

@⁠Lucasyudi on GitHub · 2026-11-24 15:00 UTC · original
Lucasyudi:pe/maskmov-loader → main · +1731 −0 · 6 files · 4 commits · open

Stacked on #1313 (on #1311, on #1303); only the top commit (8ee72c8) belongs here. Merge after #1904 (the native-host vtable change): on a Mac without it, a title crashes about 2 s in with this step on, see Regression run. Last of four PRs bringing @⁠Ahmet-Dedeler's masked-store fix for Rosetta 2 from mac-on-main-wip (04e9301) to main. Part of #258.

Rosetta 2 ends the process when an AVX masked store (VMASKMOVPS / PD, VPMASKMOVD / Q) faults past its first element, and under Wine on macOS the write watch turns every page boundary in a buffer such a store fills into a fault. Ahmet's runs on mac-on-main-wip show a retail title dying that way about 50 s into loading (rosetta error: unexpectedly need to EmulateForward …) and loading on past it with this change. Why the store has to be split, on this host (Apple M4 Pro, CrossOver 26.3), from the reproduction test in #1311 (maskmov::exec::the_instruction_itself_across_a_watched_page_boundary, run with --ignored): the real instruction across a write-watched page boundary gives

a fault on the first element was resumed; now one on the fourth
rosetta error: unexpectedly need to EmulateForward on a synchronous exception x86_rip=0x1810000 arm_pc=0x20022cf68 num_insts=35 inst_index=18 x86 instruction bytes: 0xc390048e4de2c4 0x0

and the process ends; no exception handler of the title or of XCL gets to run. The same instruction faulting on its first element is resumed normally, and so is a plain mov, which is what the helpers use.

This commit turns the replacement on: at image load, under Rosetta 2 only, each masked store becomes a call to a helper (#1311) found by plan (#1313).

What is in it

  • loader.rs: step 3b of map_image_ex (after relocation, before the sections are protected): replace_masked_stores runs maskmov::plan over the executable sections, copies the helpers and their unwind data near the image, registers them with RtlAddFunctionTable, writes call helper + NOPs over each store, makes the helpers read-only and logs one line. masked_store_helpers(): on when util::rosetta(), or forced with XCL_MASKED_STORES=1 / 0. in_masked_store_helper for crash lines. Test masked_stores_of_a_mapped_image_call_helpers_with_unwind_data.
  • util.rs: rosetta() / cpu_brand() (CPUID brand "VirtualApple …"), test rosetta_is_named_by_the_brand_string.
  • eh.rs: alloc_near(near, size), memory within a call rel32's reach of the image, from the same branch.
  • modules.rs: describe_address names an address in a helper.
  • Code and tests are Ahmet's, unchanged; the commit keeps him as author.

Tested

  • Apple M4 Pro, macOS 27.2.1, CrossOver 26.3, Rosetta 2. Cross-built for x86_64-pc-windows-gnu with mingw-w64 (GCC 16.2.0), Rust 1.100.0, debug; test binaries run under CrossOver's wine. xcl.exe builds.
  • loader:: 3 passed, util:: 6 passed, maskmov:: 7 passed / 1 ignored (the reproduction in #1311), 0 failed. The loader test logs "test image: 2 masked stores (1 VPMASKMOVD, 1 VPMASKMOVQ) call 2 helpers … 1 of them in functions without unwind data".
  • tests/e2e.rs (the test title, under Rosetta 2, so the step runs on every image it loads) on this head and on its base 0f1fdf6 (#1313, no runtime change): the same 31 PASS and 2 FAIL on both, the same checks (the run then stops at the D3DMetal crash described in #258, as on main). The test title has no masked stores, so this shows only that the step does not disturb loading, not that a replacement works in a title.

Regression run

From @⁠Kalmarv, native Windows (NVIDIA GeForce RTX 5070 Ti, driver 610.74, Ryzen 9 9950X, Windows 11 Pro 26200, release builds), the same retail title for 60 s each, main first, then this head, on the same machine: 101 % of main's frames, 105 % of its peak commit. There util::rosetta() is false and nothing is replaced, so this shows that the step changes nothing on Windows, not that a replacement works.

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1290 (PresentX 1290)
presents per 2 s (last 3): 8 37 41
device removals: 0
crashes: 0
peak commit: 26245 MB
xcl-smoke v1
commit: 8ee72c81fcdbc56ece270bb9b2bed336bb85d0a3
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1301 (PresentX 1301)
presents per 2 s (last 3): 30 41 45
device removals: 0
crashes: 0
peak commit: 27636 MB

Mac (not a passing pair yet). @⁠mikebuckets171 ran the same title on an M5 Pro with CrossOver 26 + D3DMetal, main 930e8b4 against this head with XCL_MASKED_STORES=1 (what Rosetta 2 gets by default): main runs 60 s with 0 frames; this head replaces 1,130 masked stores with 465 helpers in 38 ms and then crashes about 1.9 s in, with an execute access violation under dev_create_uav_x (exit 0x5, 2 crashes; =0 runs the 60 s). On his Mac port tree (db065d8) the same switch runs 60 s, 928 frames. @⁠Ahmet-Dedeler's reading (in the thread, not yet confirmed by a run) is that the title now gets far enough to hit D3DMetal reading the words in front of XCL's extended vtables, which plain main lacks and his ddf3be7 adds. That change is #1904 (the same patch as ddf3be7), so this PR should land after it. 8ee72c8 + that patch builds (check/maskmov-plus-vtables on my fork, 595239d); a Mac title run of it is still open.

Not tested

  • A retail title: not here. Ahmet's numbers on his branch (1,130 stores replaced in a retail executable in 67 ms, loading past the old stop) are from his runs, not mine.
  • Windows test suite: not built with MSVC, not run; the pair above is a title run only.
  • A passing Mac title run: see above; this head plus ddf3be7 builds (check/maskmov-plus-vtables on my fork) but has not been run with a title.
  • cargo test --workspace as a whole (it does not finish under CrossOver, see #258).

AI use

  • Claude Code with Claude Opus 5.5 (claude-opus-5-5): split the commits, brought alloc_near over, ran the tests above and wrote this description. The code and tests are Ahmet's.
**@⁠Lucasyudi** on GitHub · 2026-11-24 15:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344) `Lucasyudi:pe/maskmov-loader` → `main` · +1731 −0 · 6 files · 4 commits · open Stacked on #1313 (on #1311, on #1303); only the top commit (`8ee72c8`) belongs here. **Merge after #1904** (the native-host vtable change): on a Mac without it, a title crashes about 2 s in with this step on, see **Regression run**. Last of four PRs bringing @⁠Ahmet-Dedeler's masked-store fix for Rosetta 2 from `mac-on-main-wip` (`04e9301`) to `main`. Part of #258. Rosetta 2 ends the process when an AVX masked store (VMASKMOVPS / PD, VPMASKMOVD / Q) faults past its first element, and under Wine on macOS the write watch turns every page boundary in a buffer such a store fills into a fault. Ahmet's runs on `mac-on-main-wip` show a retail title dying that way about 50 s into loading (`rosetta error: unexpectedly need to EmulateForward …`) and loading on past it with this change. Why the store has to be split, on this host (Apple M4 Pro, CrossOver 26.3), from the reproduction test in #1311 (`maskmov::exec::the_instruction_itself_across_a_watched_page_boundary`, run with `--ignored`): the real instruction across a write-watched page boundary gives ``` a fault on the first element was resumed; now one on the fourth rosetta error: unexpectedly need to EmulateForward on a synchronous exception x86_rip=0x1810000 arm_pc=0x20022cf68 num_insts=35 inst_index=18 x86 instruction bytes: 0xc390048e4de2c4 0x0 ``` and the process ends; no exception handler of the title or of XCL gets to run. The same instruction faulting on its first element is resumed normally, and so is a plain `mov`, which is what the helpers use. This commit turns the replacement on: at image load, under Rosetta 2 only, each masked store becomes a call to a helper (#1311) found by `plan` (#1313). **What is in it** - `loader.rs`: step 3b of `map_image_ex` (after relocation, before the sections are protected): `replace_masked_stores` runs `maskmov::plan` over the executable sections, copies the helpers and their unwind data near the image, registers them with `RtlAddFunctionTable`, writes `call helper` + NOPs over each store, makes the helpers read-only and logs one line. `masked_store_helpers()`: on when `util::rosetta()`, or forced with `XCL_MASKED_STORES=1` / `0`. `in_masked_store_helper` for crash lines. Test `masked_stores_of_a_mapped_image_call_helpers_with_unwind_data`. - `util.rs`: `rosetta()` / `cpu_brand()` (CPUID brand "VirtualApple …"), test `rosetta_is_named_by_the_brand_string`. - `eh.rs`: `alloc_near(near, size)`, memory within a `call rel32`'s reach of the image, from the same branch. - `modules.rs`: `describe_address` names an address in a helper. - Code and tests are Ahmet's, unchanged; the commit keeps him as author. **Tested** - Apple M4 Pro, macOS 27.2.1, CrossOver 26.3, Rosetta 2. Cross-built for `x86_64-pc-windows-gnu` with mingw-w64 (GCC 16.2.0), Rust 1.100.0, debug; test binaries run under CrossOver's `wine`. `xcl.exe` builds. - `loader::` 3 passed, `util::` 6 passed, `maskmov::` 7 passed / 1 ignored (the reproduction in #1311), 0 failed. The loader test logs "test image: 2 masked stores (1 VPMASKMOVD, 1 VPMASKMOVQ) call 2 helpers … 1 of them in functions without unwind data". - `tests/e2e.rs` (the test title, under Rosetta 2, so the step runs on every image it loads) on this head and on its base `0f1fdf6` (#1313, no runtime change): the same 31 PASS and 2 FAIL on both, the same checks (the run then stops at the D3DMetal crash described in #258, as on `main`). The test title has no masked stores, so this shows only that the step does not disturb loading, not that a replacement works in a title. **Regression run** From @⁠Kalmarv, native Windows (NVIDIA GeForce RTX 5070 Ti, driver 610.74, Ryzen 9 9950X, Windows 11 Pro 26200, release builds), the same retail title for 60 s each, `main` first, then this head, on the same machine: 101 % of `main`'s frames, 105 % of its peak commit. There `util::rosetta()` is false and nothing is replaced, so this shows that the step changes nothing on Windows, not that a replacement works. ``` xcl-smoke v1 commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 60 exit: 0x0 frames shown: 1290 (PresentX 1290) presents per 2 s (last 3): 8 37 41 device removals: 0 crashes: 0 peak commit: 26245 MB ``` ``` xcl-smoke v1 commit: 8ee72c81fcdbc56ece270bb9b2bed336bb85d0a3 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 60 exit: 0x0 frames shown: 1301 (PresentX 1301) presents per 2 s (last 3): 30 41 45 device removals: 0 crashes: 0 peak commit: 27636 MB ``` **Mac (not a passing pair yet).** @⁠mikebuckets171 ran the same title on an M5 Pro with CrossOver 26 + D3DMetal, `main` `930e8b4` against this head with `XCL_MASKED_STORES=1` (what Rosetta 2 gets by default): `main` runs 60 s with 0 frames; this head replaces 1,130 masked stores with 465 helpers in 38 ms and then crashes about 1.9 s in, with an execute access violation under `dev_create_uav_x` (`exit 0x5`, 2 crashes; `=0` runs the 60 s). On his Mac port tree (`db065d8`) the same switch runs 60 s, 928 frames. @⁠Ahmet-Dedeler's reading (in the thread, not yet confirmed by a run) is that the title now gets far enough to hit D3DMetal reading the words in front of XCL's extended vtables, which plain `main` lacks and his `ddf3be7` adds. That change is #1904 (the same patch as `ddf3be7`), so this PR should land after it. `8ee72c8` + that patch builds (`check/maskmov-plus-vtables` on my fork, `595239d`); a Mac title run of it is still open. **Not tested** - A retail title: not here. Ahmet's numbers on his branch (1,130 stores replaced in a retail executable in 67 ms, loading past the old stop) are from his runs, not mine. - Windows test suite: not built with MSVC, not run; the pair above is a title run only. - A passing Mac title run: see above; this head plus `ddf3be7` builds (`check/maskmov-plus-vtables` on my fork) but has not been run with a title. - `cargo test --workspace` as a whole (it does not finish under CrossOver, see #258). **AI use** - Claude Code with Claude Opus 5.5 (`claude-opus-5-5`): split the commits, brought `alloc_near` over, ran the tests above and wrote this description. The code and tests are Ahmet's.
Rosetta 2 runs VMASKMOVPS / PD and VPMASKMOVD / Q to memory an element at
a time and resumes a fault only on the first element; a fault on a later
one ends the process ("rosetta error: unexpectedly need to EmulateForward
on a synchronous exception"). Under Wine on macOS the write watch keeps
pages protected, so a title's masked store that crosses into a watched
page ends the run. The remedy (later commits) replaces each such store at
image load with a call to a helper that stores one element at a time.

This commit is the first part: `maskmov::insn_len`, the length of an
x86-64 instruction (to walk a function from its start to a candidate
site), and `maskmov::decode`, the four stores with any memory operand.
Nothing calls them yet.

Split out of mac-on-main-wip b51552b (#258).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The second part of the masked-store replacement for Rosetta 2.
`maskmov::helper` writes position-independent code that does what one
store does: it takes the address into R8 while every register still holds
the title's value, spills source and mask to its stack, and stores each
selected element with a plain `mov` (CDQ / JRCXZ on the mask's sign: no
flag and no vector register written, a masked-out element not touched).
A plain `mov` faults and resumes like any store, element by element.
`call_site` is the `call` + NOPs that replaces a store; `UNWIND_INFO` is
the unwind data all helpers share, so a fault in a helper unwinds into the
title's function like one at the store.

Tests: the helper's bytes, and under `exec` (Windows x86-64 only) each of
224 stores (4 kinds x XMM / YMM x 28 operand shapes) run against the
instruction itself for every mask - registers, flags, YMM0-15, stack and
memory identical; a masked-out tail at the end of a mapping; a fault on a
later element in a write-watched page resumed. The ignored test runs the
instruction itself across a watched page boundary: under Rosetta 2 it
ends the process, which is the finding.

Split out of mac-on-main-wip b51552b (#258).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The third part of the masked-store replacement for Rosetta 2.
`maskmov::plan` finds the stores in the executable sections of a mapped
image and writes their helpers. A byte pattern alone is not taken: the
instructions are walked with `insn_len` from the start of the function the
unwind data names, and the walk has to arrive exactly at the pattern. A
pattern outside every function is walked to from the end of the function
before it (a leaf function has no unwind data), within 64 KiB. Stores with
the same bytes share a helper (a RIP-relative one gets its own). Every
pattern left alone is recorded with why.

Test: a made-up image with a store in a function, two in a row, one in a
leaf function, the pattern inside another instruction's immediate, behind
an EVEX instruction the walk does not know, and far from any function.

Split out of mac-on-main-wip b51552b (#258).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The last part of the masked-store replacement (#258). Rosetta 2 ends the
process when an AVX masked store faults past its first element, and under
Wine on macOS the write watch makes every page boundary in a buffer such a
store fills a fault. At image load (after relocation, before the sections
are protected) `loader::replace_masked_stores` runs `maskmov::plan` over
the executable sections, copies the helpers with their unwind data into
memory within a call's reach of the image (`eh::alloc_near`), registers
them with RtlAddFunctionTable, writes `call helper` + NOPs over each store
and makes the helpers read-only. One log line says what was done.

On by default only when the title's code runs through Rosetta 2
(`util::rosetta`: CPUID brand "VirtualApple ..."); on a CPU nothing
changes. XCL_MASKED_STORES=1 / 0 forces it on or off. A crash line names
an address in a helper as one (`modules::describe_address`).

Test: a mapped image with a store in a function and one in a leaf
function; both become calls to helpers, store what the instruction would,
and a fault in a helper is in memory XCL names, unwinds back to the store
with the title's registers, and is resumed. util: Rosetta 2 told from a
CPU by the brand string.

From mac-on-main-wip 04e9301; `alloc_near` (with its `size` argument)
from that branch's eh.rs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:23 +00:00
Author
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-24 15:44 UTC · original

Checked the stack against my originals (b51552b and 04e9301 on Ahmet-Dedeler/xcl). maskmov.rs at this head is the same file except for the module comment saying nothing calls it yet, and the loader step is the same lines plus eh::alloc_near brought over whole because main doesn't have one. So the split didn't change what the code does. Thanks for doing it this way.

What it still needs is the Mac smoke pair with a title for this last one, as you said. I can't add a Windows pair.

**@⁠Ahmet-Dedeler** on GitHub · 2026-11-24 15:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344#issuecomment-7136546698) Checked the stack against my originals (b51552b and 04e9301 on `Ahmet-Dedeler/xcl`). `maskmov.rs` at this head is the same file except for the module comment saying nothing calls it yet, and the loader step is the same lines plus `eh::alloc_near` brought over whole because `main` doesn't have one. So the split didn't change what the code does. Thanks for doing it this way. What it still needs is the Mac smoke pair with a title for this last one, as you said. I can't add a Windows pair.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 16:11 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 16:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344#issuecomment-7137258482) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. Thanks!
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-24 17:38 UTC · original

Windows pair for 8ee72c8 against main 930e8b4 (this PR's base), for the Regression run section you asked for. Both runs pass: no device removal, no crash, 101 % of main's frames, 105 % of its peak commit.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), AMD Ryzen 9 9950X, Windows 11 Pro 26200, native Windows (no Rosetta, no Wine), release builds with their pdbs.
  • scripts/smoke.ps1, the same retail title for 60 s each: main at 930e8b4 first, then this PR's head, one after the other on the same machine.

main 930e8b4:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1290 (PresentX 1290)
presents per 2 s (last 3): 8 37 41
device removals: 0
crashes: 0
peak commit: 26245 MB

this PR, 8ee72c8:

xcl-smoke v1
commit: 8ee72c81fcdbc56ece270bb9b2bed336bb85d0a3
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1301 (PresentX 1301)
presents per 2 s (last 3): 30 41 45
device removals: 0
crashes: 0
peak commit: 27636 MB

Not tested

  • Whether the loader step is reached at all on native Windows in these 60 s (not logged here); this shows only that the run is unchanged.
  • World loading: a 60 s run ends before it.
  • macOS / Rosetta 2, AMD, the test suite.

AI use: Claude Code (Claude Opus 5.5)

**@⁠Kalmarv** on GitHub · 2026-11-24 17:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344#issuecomment-7139485832) Windows pair for `8ee72c8` against `main` `930e8b4` (this PR's base), for the **Regression run** section you asked for. Both runs pass: no device removal, no crash, 101 % of `main`'s frames, 105 % of its peak commit. **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), AMD Ryzen 9 9950X, Windows 11 Pro 26200, native Windows (no Rosetta, no Wine), release builds with their pdbs. - `scripts/smoke.ps1`, the same retail title for 60 s each: `main` at `930e8b4` first, then this PR's head, one after the other on the same machine. `main` `930e8b4`: ``` xcl-smoke v1 commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56 gpu: NVIDIA GeForce RTX 5070 Ti title: GTA VI seconds: 60 exit: 0x0 frames shown: 1290 (PresentX 1290) presents per 2 s (last 3): 8 37 41 device removals: 0 crashes: 0 peak commit: 26245 MB ``` this PR, `8ee72c8`: ``` xcl-smoke v1 commit: 8ee72c81fcdbc56ece270bb9b2bed336bb85d0a3 gpu: NVIDIA GeForce RTX 5070 Ti title: GTA VI seconds: 60 exit: 0x0 frames shown: 1301 (PresentX 1301) presents per 2 s (last 3): 30 41 45 device removals: 0 crashes: 0 peak commit: 27636 MB ``` **Not tested** - Whether the loader step is reached at all on native Windows in these 60 s (not logged here); this shows only that the run is unchanged. - World loading: a 60 s run ends before it. - macOS / Rosetta 2, AMD, the test suite. **AI use:** Claude Code (Claude Opus 5.5)
Author
Owner

@⁠Lucasyudi on GitHub · 2026-11-24 17:50 UTC · original

@⁠Kalmarv thanks, pasted both blocks under Regression run with your hardware line. A Mac pair is still open.

**@⁠Lucasyudi** on GitHub · 2026-11-24 17:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344#issuecomment-7139770718) @⁠Kalmarv thanks, pasted both blocks under **Regression run** with your hardware line. A Mac pair is still open.
Author
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-24 19:15 UTC · original

@⁠mikebuckets171 @⁠Lucasyudi thanks for the pair. A likely explanation for the crash with the switch on, from reading the code and not from a run. I haven't run 8ee72c8 on plain main myself.

I don't think it's this PR. The loader step relies on nothing outside what came over with it: eh::alloc_near looks for a free 64 KiB-aligned region within 0x7000_0000 of the image end, allocates it RWX, and the helpers, one unwind record and the function entries go there. I can't see a way for that pool to sit where D3D12.X expects something.

What I think happens is that the title now gets far enough to hit the wall plain main has on D3DMetal anyway. D3DMetal reads the words in front of an object's vtable (type information, the C++ ABI offsets) and adjusts this from them. Plain main's extended vtables don't have that prefix, so the first host call that is handed an XCL-wrapped object jumps through garbage. The resource in CreateUnorderedAccessView would be such a call, which fits an execute fault under dev_create_uav_x. With the switch off the title doesn't reach that call within 60 s (0 frames), so nothing crashes. That prefix is what pr/native-host-vtables (ddf3be7 on my fork) adds, and it's why the same switch runs fine on the port tree.

Two checks, either is enough:

  1. The faulting address in your log is in no module, and it differs between your two runs or looks like data.
  2. This head plus pr/native-host-vtables runs past 1.9 s on your machine.

If that holds, the Mac pair for this PR can't be made on plain main at all, with or without the switch. It would need the vtable change under both sides of the pair, and the description should say so.

**@⁠Ahmet-Dedeler** on GitHub · 2026-11-24 19:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344#issuecomment-7141836425) @⁠mikebuckets171 @⁠Lucasyudi thanks for the pair. A likely explanation for the crash with the switch on, from reading the code and not from a run. I haven't run 8ee72c8 on plain `main` myself. I don't think it's this PR. The loader step relies on nothing outside what came over with it: `eh::alloc_near` looks for a free 64 KiB-aligned region within 0x7000_0000 of the image end, allocates it RWX, and the helpers, one unwind record and the function entries go there. I can't see a way for that pool to sit where D3D12.X expects something. What I think happens is that the title now gets far enough to hit the wall plain `main` has on D3DMetal anyway. D3DMetal reads the words in front of an object's vtable (type information, the C++ ABI offsets) and adjusts `this` from them. Plain `main`'s extended vtables don't have that prefix, so the first host call that is handed an XCL-wrapped object jumps through garbage. The resource in `CreateUnorderedAccessView` would be such a call, which fits an execute fault under `dev_create_uav_x`. With the switch off the title doesn't reach that call within 60 s (0 frames), so nothing crashes. That prefix is what `pr/native-host-vtables` (ddf3be7 on my fork) adds, and it's why the same switch runs fine on the port tree. Two checks, either is enough: 1. The faulting address in your log is in no module, and it differs between your two runs or looks like data. 2. This head plus `pr/native-host-vtables` runs past 1.9 s on your machine. If that holds, the Mac pair for this PR can't be made on plain `main` at all, with or without the switch. It would need the vtable change under both sides of the pair, and the description should say so.
Author
Owner

@⁠Lucasyudi on GitHub · 2026-11-24 19:24 UTC · original

@⁠mikebuckets171 thanks, that is the run this PR needed, and it is not a passing pair: on plain main under Rosetta 2 the step is on by default (util::rosetta()), so your =1 run is what a Mac user of this head gets. I'll say that in the description now rather than leave the Windows pair looking like the whole story.

@⁠Ahmet-Dedeler for your check 2, to save a step: 8ee72c8 + ddf3be7 cherry-picks without conflicts (only d3d12x/real.rs) and builds for x86_64-pc-windows-gnu here. It is on my fork as check/maskmov-plus-vtables (595239d), not a PR. I have no title on this Mac, so I can't run it myself.

If the crash goes away there, I'd rather this PR wait for the vtable change than land first and turn a 0-frame run into a crash at 1.9 s on main: I'll mark it stacked on that PR once it is opened, and the Mac pair can be made with it on both sides, as Ahmet says.

AI use: Claude Code with Claude Opus 5.5 (cherry-pick, build, this comment).

**@⁠Lucasyudi** on GitHub · 2026-11-24 19:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344#issuecomment-7142051006) @⁠mikebuckets171 thanks, that is the run this PR needed, and it is not a passing pair: on plain `main` under Rosetta 2 the step is on by default (`util::rosetta()`), so your `=1` run is what a Mac user of this head gets. I'll say that in the description now rather than leave the Windows pair looking like the whole story. @⁠Ahmet-Dedeler for your check 2, to save a step: `8ee72c8` + `ddf3be7` cherry-picks without conflicts (only `d3d12x/real.rs`) and builds for `x86_64-pc-windows-gnu` here. It is on my fork as `check/maskmov-plus-vtables` (`595239d`), not a PR. I have no title on this Mac, so I can't run it myself. If the crash goes away there, I'd rather this PR wait for the vtable change than land first and turn a 0-frame run into a crash at 1.9 s on `main`: I'll mark it stacked on that PR once it is opened, and the Mac pair can be made with it on both sides, as Ahmet says. AI use: Claude Code with Claude Opus 5.5 (cherry-pick, build, this comment).
Author
Owner

@⁠mikebuckets171 on GitHub · 2026-11-24 18:52 UTC · original · edited 2026-11-24 19:59 UTC

M5 Pro / CrossOver Mac title run (D3DMetal, Rosetta 2; release cross-build cargo build --release --locked -p xcl --target x86_64-pc-windows-gnullvm; same title, 60 s). This uses the PR's recorded base and exact head. I forced XCL_MASKED_STORES=1 on the head to ensure the change was exercised.

Base 930e8b4:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: AMD Compatibility Mode
title: retail (Xbox Series X|S package, private drive)
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

PR head 8ee72c8 (XCL_MASKED_STORES=1):

xcl-smoke v1
commit: 8ee72c81fcdbc56ece270bb9b2bed336bb85d0a3
gpu: AMD Compatibility Mode
title: retail (Xbox Series X|S package, private drive)
seconds: 60
exit: 0x5
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0 0
device removals: 0
crashes: 2
peak commit: 0 MB

The head's log confirms 1,130 masked stores rewritten to 465 helpers (38 ms), then reports an execute access violation through dev_create_uav_x at about 1.9 s, before a frame. On the exact head, a repeated toggle check gave the same result twice: =1 crashed early; =0 completed 60 s (still 0 frames). So this is not a passing regression pair, and it does not show the original masked-store fault being reached.

As a separate integration check on the local Mac-port tree db065d8 (not the PR head), XCL_MASKED_STORES=0/1 both completed 60 s without crashes, at 914/928 frames; the enabled run logged the same 1,130 replacements. The disabled run also survived, so this demonstrates the code runs in the fuller Mac stack, not that the fix prevented a failure.

peak commit: 0 MB is unavailable as a memory measurement here. AI use: OpenCode, GPT-6 Luna ran the builds/smokes and wrote this report.

Follow-up: the author-requested native-host-vtable check (595239d, #1344 head plus ddf3be7), same M5 Pro / CrossOver setup:

  • With masked-store helpers enabled (the Mac default), the log confirms 1,130 game stores rewritten to 465 helpers (41 ms). The earlier dev_create_uav_x fault at ~1.9 s is gone; the title instead hits a null-write access violation at game_scarlett_master.exe+0x2215c35 around 37.2 s and exits at 40.5 s. No frames were presented.
  • On the same combined head with XCL_MASKED_STORES=0, the bounded 60 s run completed without a crash, still at 0 frames. The recorded base 930e8b4 plus ddf3be7 also completed 60 s at 0 frames.
  • The vtable patch's a_native_hosts_table_keeps_its_prefix_and_other_tables_keep_theirs test passed under CrossOver: 1 passed, 0 failed (738 filtered out).

This confirms the vtable change moves execution past the earlier host-vtable fault. It does not establish that #1344's masked-store fix has completed a successful title load: the enabled combined head reaches a later title fault, while both controls remain before the first frame. The null write is at +0x2215c35; I cannot identify it as the GPU Loc Sig watchdog from this run.

AI use for this follow-up: OpenCode, GPT-6 Luna, built the combined tree, ran the unit test and title checks, and wrote this report.

**@⁠mikebuckets171** on GitHub · 2026-11-24 18:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344#issuecomment-7141263944) · edited 2026-11-24 19:59 UTC **M5 Pro / CrossOver Mac title run** (D3DMetal, Rosetta 2; release cross-build `cargo build --release --locked -p xcl --target x86_64-pc-windows-gnullvm`; same title, 60 s). This uses the PR's recorded base and exact head. I forced `XCL_MASKED_STORES=1` on the head to ensure the change was exercised. Base `930e8b4`: ``` xcl-smoke v1 commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56 gpu: AMD Compatibility Mode title: retail (Xbox Series X|S package, private drive) seconds: 60 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 0 MB ``` PR head `8ee72c8` (`XCL_MASKED_STORES=1`): ``` xcl-smoke v1 commit: 8ee72c81fcdbc56ece270bb9b2bed336bb85d0a3 gpu: AMD Compatibility Mode title: retail (Xbox Series X|S package, private drive) seconds: 60 exit: 0x5 frames shown: none logged (the run did not reach its end) presents per 2 s (last 3): 0 0 device removals: 0 crashes: 2 peak commit: 0 MB ``` The head's log confirms 1,130 masked stores rewritten to 465 helpers (38 ms), then reports an execute access violation through `dev_create_uav_x` at about 1.9 s, before a frame. On the exact head, a repeated toggle check gave the same result twice: `=1` crashed early; `=0` completed 60 s (still 0 frames). So this is not a passing regression pair, and it does not show the original masked-store fault being reached. As a separate integration check on the local Mac-port tree `db065d8` (not the PR head), `XCL_MASKED_STORES=0/1` both completed 60 s without crashes, at 914/928 frames; the enabled run logged the same 1,130 replacements. The disabled run also survived, so this demonstrates the code runs in the fuller Mac stack, not that the fix prevented a failure. `peak commit: 0 MB` is unavailable as a memory measurement here. **AI use:** OpenCode, GPT-6 Luna ran the builds/smokes and wrote this report. **Follow-up: the author-requested native-host-vtable check** (`595239d`, #1344 head plus `ddf3be7`), same M5 Pro / CrossOver setup: - With masked-store helpers enabled (the Mac default), the log confirms 1,130 game stores rewritten to 465 helpers (41 ms). The earlier `dev_create_uav_x` fault at ~1.9 s is gone; the title instead hits a null-write access violation at `game_scarlett_master.exe+0x2215c35` around 37.2 s and exits at 40.5 s. No frames were presented. - On the same combined head with `XCL_MASKED_STORES=0`, the bounded 60 s run completed without a crash, still at 0 frames. The recorded base `930e8b4` plus `ddf3be7` also completed 60 s at 0 frames. - The vtable patch's `a_native_hosts_table_keeps_its_prefix_and_other_tables_keep_theirs` test passed under CrossOver: 1 passed, 0 failed (738 filtered out). This confirms the vtable change moves execution past the earlier host-vtable fault. It does **not** establish that #1344's masked-store fix has completed a successful title load: the enabled combined head reaches a later title fault, while both controls remain before the first frame. The null write is at `+0x2215c35`; I cannot identify it as the `GPU Loc Sig` watchdog from this run. AI use for this follow-up: OpenCode, GPT-6 Luna, built the combined tree, ran the unit test and title checks, and wrote this report.
Author
Owner

@⁠Lucasyudi on GitHub · 2026-11-25 23:10 UTC · original

@⁠mikebuckets171 I only now saw that #1904 is your upstreaming of ddf3be7 (same patch), so this PR now says to merge after it. If you have a slot for one more Mac run: check/maskmov-plus-vtables on my fork (595239d, this head + that patch) against #1904's head 50768d8, 60 s, default switches. That would show whether the crash at 1.9 s was the missing prefix, as @⁠Ahmet-Dedeler read it, and whether the replacement then runs in a title on main. No rush.

**@⁠Lucasyudi** on GitHub · 2026-11-25 23:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/1344#issuecomment-7177233131) @⁠mikebuckets171 I only now saw that #1904 is your upstreaming of `ddf3be7` (same patch), so this PR now says to merge after it. If you have a slot for one more Mac run: `check/maskmov-plus-vtables` on my fork (`595239d`, this head + that patch) against #1904's head `50768d8`, 60 s, default switches. That would show whether the crash at 1.9 s was the missing prefix, as @⁠Ahmet-Dedeler read it, and whether the replacement then runs in a title on `main`. No rush.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1344/head:github-bot/gh-1344'
git switch 'github-bot/gh-1344'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1344'
git switch 'github-bot/gh-1344'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1344'
git switch 'github-bot/gh-1344'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1344'
git switch 'main'
git merge --squash 'github-bot/gh-1344'
git switch 'main'
git merge --ff-only 'github-bot/gh-1344'
git switch 'main'
git merge 'github-bot/gh-1344'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.