Repository navigation
Conversation
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 (xcl-dev#258).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 (xcl-dev#258). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 (xcl-dev#258). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pers The last part of the masked-store replacement (xcl-dev#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 <noreply@anthropic.com>
|
Checked the stack against my originals (b51552b and 04e9301 on 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. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Windows pair for Tested
this PR, Not tested
AI use: Claude Code (Claude Opus 5.5) |
|
@Kalmarv thanks, pasted both blocks under Regression run with your hardware line. A Mac pair is still open. |
|
M5 Pro / CrossOver Mac title run (D3DMetal, Rosetta 2; release cross-build Base PR head The head's log confirms 1,130 masked stores rewritten to 465 helpers (38 ms), then reports an execute access violation through As a separate integration check on the local Mac-port tree
Follow-up: the author-requested native-host-vtable check (
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 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 @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 I don't think it's this PR. The loader step relies on nothing outside what came over with it: What I think happens is that the title now gets far enough to hit the wall plain Two checks, either is enough:
If that holds, the Mac pair for this PR can't be made on plain |
|
@mikebuckets171 thanks, that is the run this PR needed, and it is not a passing pair: on plain @Ahmet-Dedeler for your check 2, to save a step: 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 AI use: Claude Code with Claude Opus 5.5 (cherry-pick, build, this comment). |
|
@mikebuckets171 I only now saw that #1904 is your upstreaming of |
# Conflicts: # crates/xcl/src/util.rs
|
Still waiting for a maintainer, and for #1904 to land first (see the top of the description). Merges cleanly into |
|
Stacked on #1313 (on #1311, on #1303); the shared maskmov.rs lines are the stack, not a duplicate. Only the top commit 8ee72c8 (loader.rs AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
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 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 PE loader: helpers that do a masked store an element at a time #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(PE loader: find a title's masked stores by walking its functions #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 macOS (Apple Silicon, CrossOver + D3DMetal): the newer retail game reaches its first-run menus at 30 fps #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. The nearest thing so far: @vakaobr'smac/integration(efef307, for testing, not merging) carries this commit and #1904 together with other Mac PRs, and @shortside's retail run of it with no switches (so this step on) ran the 330 s cap with 3,391 frames and no crash (#258 (comment)). That run has many other changes in it and nomainrun beside it, so it is not a pair.Not tested
ddf3be7builds (check/maskmov-plus-vtableson my fork) but has not been run with a title on its own, only inside the integration branch above.cargo test --workspaceas a whole (it does not finish under CrossOver, see macOS (Apple Silicon, CrossOver + D3DMetal): the newer retail game reaches its first-run menus at 30 fps #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.