Linux wine write watch check #3100

Merged
leonida/mandy
kawaii-shakal merged 3 commits from linux-wine-write-watch-check into main 2026-12-02 13:50:31 +00:00

Pull request successfully merged and closed

kawaii-shakal commented 2026-12-02 10:44:32 +00:00

Claimed in the coordination issue as: LINUX-WINE-WRITE-WATCH-CHECK (#2570)

What and why

Both runtimes keep the title's graphics memory write-watched (MEM_WRITE_WATCH, d3d12/crates/leonida-hle/src/modules/xmem.rs). Wine answers write watches in one of two ways:

  • in the kernel (userfaultfd async write protection + PAGEMAP_SCAN, Linux 6.7+): upstream Wine from the 10.7 development release (absent in 10.6 and the stable 10.0), and Proton's Wine;
  • with signals (Wine 9.0/10.0, or any Wine on an older kernel): every first write to a watched page after a reset is a SIGSEGV.

scripts/play-linux.sh uses the system wine, and Ubuntu 24.04 ships 9.0, Debian 13 ships 10.0. The launcher now says so in one line and still starts the game:

  • the ntdll.so beside wine decides (the kernel path's messages name PAGEMAP_SCAN);
  • with no ntdll.so found, wine --version decides;
  • a kernel older than 6.7 is named too.
    LEONIDA_WINE_CHECK=0 leaves the line out. docs/linux.md gets a "Which Wine" section with the measurements, and scripts/write_watch_bench.c measures them under any Wine.

Tested

Measured on a 4-core cloud VM, Linux 6.18, our own memory only (no game):

  • Wine 9.0: 2.3-3.8 us per first write after a reset.
  • The same mechanism natively through userfaultfd + PAGEMAP_SCAN: 0.7-0.85 us. Not measured under Wine 10.7+/Proton itself.
  • The runtime's guard faults under Wine 9.0: 5-10 us.
    How many pages a frame writes under Wine was not measured.

Tests:

  • python3 -I tests/test_play_linux_wine_check.py: 6 tests OK. They cover the versions, the kernel boundary, the ntdll check in the lib / lib64 / Debian multiarch layouts, wine reached through a symlink, and the switch.
  • Red/green: with main's play-linux.sh the new tests fail (12 subtests).
  • test_play_linux.py, test_play_linux_defaults.py and test_docs_*.py (57) pass.
  • check_no_game_data.py is clean on the changed files.
  • sh -n and dash -n are clean.
  • The benchmark cross-builds with clang-cl + xwin with no warnings and runs under Wine 9.0.

GPUs tested: n/a (no GPU involved)

AI-assisted: yes. Written with Claude Code (Claude Opus 5.5); test runs by Claude Haiku agents; reviewed before opening by a separate read-only reviewer agent on Claude Opus, twice, whose findings were addressed (the 10.7 boundary, ntdll over version, docs wording, layout tests).

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

🤖 Generated with Claude Code

Claimed in the coordination issue as: LINUX-WINE-WRITE-WATCH-CHECK (#2570) ### What and why Both runtimes keep the title's graphics memory write-watched (`MEM_WRITE_WATCH`, `d3d12/crates/leonida-hle/src/modules/xmem.rs`). Wine answers write watches in one of two ways: - in the kernel (userfaultfd async write protection + `PAGEMAP_SCAN`, Linux 6.7+): upstream Wine from the 10.7 development release (absent in 10.6 and the stable 10.0), and Proton's Wine; - with signals (Wine 9.0/10.0, or any Wine on an older kernel): every first write to a watched page after a reset is a SIGSEGV. `scripts/play-linux.sh` uses the system `wine`, and Ubuntu 24.04 ships 9.0, Debian 13 ships 10.0. The launcher now says so in one line and still starts the game: - the `ntdll.so` beside `wine` decides (the kernel path's messages name `PAGEMAP_SCAN`); - with no `ntdll.so` found, `wine --version` decides; - a kernel older than 6.7 is named too. `LEONIDA_WINE_CHECK=0` leaves the line out. `docs/linux.md` gets a "Which Wine" section with the measurements, and `scripts/write_watch_bench.c` measures them under any Wine. ### Tested Measured on a 4-core cloud VM, Linux 6.18, our own memory only (no game): - Wine 9.0: 2.3-3.8 us per first write after a reset. - The same mechanism natively through userfaultfd + `PAGEMAP_SCAN`: 0.7-0.85 us. Not measured under Wine 10.7+/Proton itself. - The runtime's guard faults under Wine 9.0: 5-10 us. How many pages a frame writes under Wine was not measured. Tests: - `python3 -I tests/test_play_linux_wine_check.py`: 6 tests OK. They cover the versions, the kernel boundary, the ntdll check in the lib / lib64 / Debian multiarch layouts, `wine` reached through a symlink, and the switch. - Red/green: with main's `play-linux.sh` the new tests fail (12 subtests). - `test_play_linux.py`, `test_play_linux_defaults.py` and `test_docs_*.py` (57) pass. - `check_no_game_data.py` is clean on the changed files. - `sh -n` and `dash -n` are clean. - The benchmark cross-builds with clang-cl + xwin with no warnings and runs under Wine 9.0. GPUs tested: n/a (no GPU involved) AI-assisted: yes. Written with Claude Code (Claude Opus 5.5); test runs by Claude Haiku agents; reviewed before opening by a separate read-only reviewer agent on Claude Opus, twice, whose findings were addressed (the 10.7 boundary, ntdll over version, docs wording, layout tests). ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MoonEyes commented 2026-12-02 13:20:57 +00:00

RUN (independent run on Windows 11 with WSL2 Ubuntu (Linux 6.6, dash, Python 3), #3100 head 811b0c442, merged locally into main f6dd2242e with git merge --no-ff, no conflict)

Not the author's run: the tests were run by a separate agent on a different machine. The PR touches scripts/play-linux.sh, so the POSIX tests were run inside WSL (on native Windows they are skipped, not passed).

Red. With main's scripts/play-linux.sh swapped in (the PR's test file kept), tests/test_play_linux_wine_check.py fails: 6 tests ran, 13 failures (subtests). File restored afterwards, git status clean.

Green. On the merge:

  • python3 -I tests/test_play_linux_wine_check.py: 6 tests OK
  • tests/test_play_linux.py (1) and tests/test_play_linux_defaults.py (2): OK
  • all 13 tests/test_docs_*.py: pass
  • sh -n and dash -n scripts/play-linux.sh: clean
  • check_no_game_data.py on the 4 changed files: clean

Mutations of write_watch_kind in play-linux.sh, each run against the 6 tests:

  • Wine boundary 10.7 -> 10.6: killed (1 failure)
  • kernel boundary 6.7 -> 6.6: killed (2 failures)
  • ntdll.so check ignored (version only): killed (6 failures)
  • LEONIDA_WINE_CHECK=0 switch ignored: killed (1 failure)
  • lib64 ntdll layout removed: killed (2 failures)
  • symlink resolution (readlink -f) removed: killed (3 failures)
    6 of 6 killed.

Merge conditions.

  • CI on head 811b0c442: all 5 checks pass (change-scope, check, linux-python-and-viewer, no-game-data, semantic-tests).
  • No review, CHANGES_REQUESTED or unanswered question on the PR.
  • Claimed in #2570 by the author (LINUX-WINE-WRITE-WATCH-CHECK).
  • Author has merged PRs (#2494, #2436, #2378).
  • No Depends on.

Not covered. scripts/write_watch_bench.c was not built or run (no clang-cl/xwin here). The microsecond figures in docs/linux.md were not re-measured. No real Wine was launched: the tests use stand-in wine, uname and ntdll.so, so whether a given real Wine build contains PAGEMAP_SCAN in its ntdll.so is taken from the PR's description. The test file is skipped on native Windows.

Verdict: PASS

AI-assisted (Claude Code).

RUN (independent run on Windows 11 with WSL2 Ubuntu (Linux 6.6, dash, Python 3), #3100 head 811b0c442, merged locally into `main` f6dd2242e with `git merge --no-ff`, no conflict) Not the author's run: the tests were run by a separate agent on a different machine. The PR touches `scripts/play-linux.sh`, so the POSIX tests were run inside WSL (on native Windows they are skipped, not passed). **Red.** With `main`'s `scripts/play-linux.sh` swapped in (the PR's test file kept), `tests/test_play_linux_wine_check.py` fails: 6 tests ran, 13 failures (subtests). File restored afterwards, `git status` clean. **Green.** On the merge: - `python3 -I tests/test_play_linux_wine_check.py`: 6 tests OK - `tests/test_play_linux.py` (1) and `tests/test_play_linux_defaults.py` (2): OK - all 13 `tests/test_docs_*.py`: pass - `sh -n` and `dash -n scripts/play-linux.sh`: clean - `check_no_game_data.py` on the 4 changed files: clean **Mutations** of `write_watch_kind` in `play-linux.sh`, each run against the 6 tests: - Wine boundary 10.7 -> 10.6: killed (1 failure) - kernel boundary 6.7 -> 6.6: killed (2 failures) - ntdll.so check ignored (version only): killed (6 failures) - `LEONIDA_WINE_CHECK=0` switch ignored: killed (1 failure) - `lib64` ntdll layout removed: killed (2 failures) - symlink resolution (`readlink -f`) removed: killed (3 failures) 6 of 6 killed. **Merge conditions.** - CI on head 811b0c442: all 5 checks pass (change-scope, check, linux-python-and-viewer, no-game-data, semantic-tests). - No review, CHANGES_REQUESTED or unanswered question on the PR. - Claimed in #2570 by the author (LINUX-WINE-WRITE-WATCH-CHECK). - Author has merged PRs (#2494, #2436, #2378). - No `Depends on`. **Not covered.** `scripts/write_watch_bench.c` was not built or run (no clang-cl/xwin here). The microsecond figures in `docs/linux.md` were not re-measured. No real Wine was launched: the tests use stand-in `wine`, `uname` and `ntdll.so`, so whether a given real Wine build contains `PAGEMAP_SCAN` in its `ntdll.so` is taken from the PR's description. The test file is skipped on native Windows. **Verdict: PASS** AI-assisted (Claude Code).
MoonEyes commented 2026-12-02 13:21:31 +00:00

Merging. Head 811b0c442 merges cleanly with main bf7886746 and does not force a rebase of #2566. Independent red/green by MoonEyes' agent on head 811b0c442 (red: 13 failures with main's play-linux.sh; green: 6 wine-check tests plus the play-linux and docs tests pass in WSL; 6 of 6 mutations of write_watch_kind killed), see https://github.com/ProjectLeonida/mandy/pull/3100#issuecomment-7346734111, CI green including no-game-data, no open review or question, claimed item LINUX-WINE-WRITE-WATCH-CHECK in #2570. Merged by MoonEyes.

AI-assisted (Claude Code).

Merging. Head `811b0c442` merges cleanly with `main` `bf7886746` and does not force a rebase of #2566. Independent red/green by MoonEyes' agent on head 811b0c442 (red: 13 failures with main's play-linux.sh; green: 6 wine-check tests plus the play-linux and docs tests pass in WSL; 6 of 6 mutations of write_watch_kind killed), see https://github.com/ProjectLeonida/mandy/pull/3100#issuecomment-7346734111, CI green including no-game-data, no open review or question, claimed item LINUX-WINE-WRITE-WATCH-CHECK in #2570. Merged by MoonEyes. AI-assisted (Claude Code).
Sign in to join this conversation.
No description provided.