PE loader: under Rosetta 2 a title's masked stores call resumable helpers #1344
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1344
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1344"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Lucasyudi on GitHub · 2026-11-24 15:00 UTC · original
Lucasyudi:pe/maskmov-loader→main· +1731 −0 · 6 files · 4 commits · openStacked 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 frommac-on-main-wip(04e9301) tomain. 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-wipshow 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 givesand 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 ofmap_image_ex(after relocation, before the sections are protected):replace_masked_storesrunsmaskmov::planover the executable sections, copies the helpers and their unwind data near the image, registers them withRtlAddFunctionTable, writescall helper+ NOPs over each store, makes the helpers read-only and logs one line.masked_store_helpers(): on whenutil::rosetta(), or forced withXCL_MASKED_STORES=1/0.in_masked_store_helperfor crash lines. Testmasked_stores_of_a_mapped_image_call_helpers_with_unwind_data.util.rs:rosetta()/cpu_brand()(CPUID brand "VirtualApple …"), testrosetta_is_named_by_the_brand_string.eh.rs:alloc_near(near, size), memory within acall rel32's reach of the image, from the same branch.modules.rs:describe_addressnames an address in a helper.Tested
x86_64-pc-windows-gnuwith mingw-w64 (GCC 16.2.0), Rust 1.100.0, debug; test binaries run under CrossOver'swine.xcl.exebuilds.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 base0f1fdf6(#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 onmain). 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,
mainfirst, then this head, on the same machine: 101 % ofmain's frames, 105 % of its peak commit. Thereutil::rosetta()is false and nothing is replaced, so this shows that the step changes nothing on Windows, not that a replacement works.Mac (not a passing pair yet). @mikebuckets171 ran the same title on an M5 Pro with CrossOver 26 + D3DMetal,
main930e8b4against this head withXCL_MASKED_STORES=1(what Rosetta 2 gets by default):mainruns 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 underdev_create_uav_x(exit 0x5, 2 crashes;=0runs 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 plainmainlacks and hisddf3be7adds. That change is #1904 (the same patch asddf3be7), so this PR should land after it.8ee72c8+ that patch builds (check/maskmov-plus-vtableson my fork,595239d); a Mac title run of it is still open.Not tested
ddf3be7builds (check/maskmov-plus-vtableson my fork) but has not been run with a title.cargo test --workspaceas a whole (it does not finish under CrossOver, see #258).AI use
claude-opus-5-5): split the commits, broughtalloc_nearover, 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]>@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.rsat this head is the same file except for the module comment saying nothing calls it yet, and the loader step is the same lines pluseh::alloc_nearbrought over whole becausemaindoesn'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.
@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!
@Kalmarv on GitHub · 2026-11-24 17:38 UTC · original
Windows pair for
8ee72c8againstmain930e8b4(this PR's base), for the Regression run section you asked for. Both runs pass: no device removal, no crash, 101 % ofmain's frames, 105 % of its peak commit.Tested
scripts/smoke.ps1, the same retail title for 60 s each:mainat930e8b4first, then this PR's head, one after the other on the same machine.main930e8b4:this PR,
8ee72c8:Not tested
AI use: Claude Code (Claude Opus 5.5)
@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.
@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
8ee72c8on plainmainmyself.I don't think it's this PR. The loader step relies on nothing outside what came over with it:
eh::alloc_nearlooks 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
mainhas on D3DMetal anyway. D3DMetal reads the words in front of an object's vtable (type information, the C++ ABI offsets) and adjuststhisfrom them. Plainmain'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 inCreateUnorderedAccessViewwould be such a call, which fits an execute fault underdev_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 whatpr/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:
pr/native-host-vtablesruns past 1.9 s on your machine.If that holds, the Mac pair for this PR can't be made on plain
mainat all, with or without the switch. It would need the vtable change under both sides of the pair, and the description should say so.@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
mainunder Rosetta 2 the step is on by default (util::rosetta()), so your=1run 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+ddf3be7cherry-picks without conflicts (onlyd3d12x/real.rs) and builds forx86_64-pc-windows-gnuhere. It is on my fork ascheck/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).
@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 forcedXCL_MASKED_STORES=1on the head to ensure the change was exercised.Base
930e8b4:PR head
8ee72c8(XCL_MASKED_STORES=1):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_xat about 1.9 s, before a frame. On the exact head, a repeated toggle check gave the same result twice:=1crashed early;=0completed 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/1both 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 MBis 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 plusddf3be7), same M5 Pro / CrossOver setup:dev_create_uav_xfault at ~1.9 s is gone; the title instead hits a null-write access violation atgame_scarlett_master.exe+0x2215c35around 37.2 s and exits at 40.5 s. No frames were presented.XCL_MASKED_STORES=0, the bounded 60 s run completed without a crash, still at 0 frames. The recorded base930e8b4plusddf3be7also completed 60 s at 0 frames.a_native_hosts_table_keeps_its_prefix_and_other_tables_keep_theirstest 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 theGPU Loc Sigwatchdog 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.
@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-vtableson my fork (595239d, this head + that patch) against #1904's head50768d8, 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 onmain. No rush.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.