kernelx: VirtualProtect commits lazy pages in its range first #1182

Open
emirduran707 wants to merge 1 commit from upstream-pr/1191 into main
emirduran707 commented 2026-11-24 13:03:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T13:03:30Z.


MapTitlePhysicalPages / XMemMapPhysicalPages map fresh pages into a title's own reservation lazily: the page stays reserved (lazy::mark) until it is first touched. A title that maps pages and calls VirtualProtect on them before touching them got FALSE with ERROR_INVALID_ADDRESS (487). Windows' VirtualProtect fails when any page in the range is not committed. On the console the pages are mapped, and XCL's non-lazy path for the same call commits them, so there the call succeeds. lazy.rs itself notes that kernel calls fail on lazy pages and that buffers passed to them are committed first (ensure). The VirtualProtect wrapper did not do that.

VirtualProtect, and VirtualProtectEx for the current process (matching both the pseudo-handle and real current-process handles via CompareObjectHandles), now call lazy::ensure_for_protect on the range first:

  • Pre-validates that every 4 KiB page in [addr, addr + size) is either already MEM_COMMIT or marked lazy (MEM_RESERVE in LAZY) before committing any lazy page, so a mixed range containing an uncommitted non-lazy or free page fails VirtualProtect with ERROR_INVALID_ADDRESS and leaves lazy pages uncommitted and still marked lazy.
  • Commits lazy pages through the supplied process handle via VirtualAllocEx, so a real handle lacking PROCESS_VM_OPERATION fails with ERROR_ACCESS_DENIED without committing or unmarking any lazy page.
  • Skips pre-commit when old is null.

What is in it

  • crates/xcl/src/hle/kernelx/lazy.rs: ensure_for_protect(proc_, p, len).
  • crates/xcl/src/hle/kernelx.rs: is_current_process_handle, VirtualProtect, VirtualProtectEx; four unit tests:
    • virtual_protect_commits_lazy_pages_first
    • virtual_protect_ex_commits_lazy_pages_through_real_handle (real handle opened with only PROCESS_VM_OPERATION)
    • virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages (real handle opened with only PROCESS_QUERY_LIMITED_INFORMATION -> ERROR_ACCESS_DENIED, page stays MEM_RESERVE and still lazy)
    • virtual_protect_mixed_range_leaves_lazy_page_uncommitted (lazy page + plain MEM_RESERVE page -> ERROR_INVALID_ADDRESS, lazy page stays MEM_RESERVE and still lazy)

#1034 adds a different line at the top of VirtualProtect; the two changes are independent (a rebase keeps both lines).

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on ecac22b (rebased onto main e1d84b7): 1425 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record)
    • All 4 hle::kernelx::tests::virtual_protect* tests pass.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) fail identically on unmodified main on this GPU.

Regression run

main (08db8020):

xcl-smoke v1
commit: 08db8020d323bf478964fcc586152cce54959cfc
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1553 (PresentX 1553)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13966 MB

this PR (ecac22b):

xcl-smoke v1
commit: ecac22b4021d4a68f1325e7390e5de72fb7ae0b7
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1585 (PresentX 1585)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13931 MB

Not tested

  • A title that protects freshly mapped pages before touching them; the smoke title's run is a regression check only.
  • NVIDIA and Intel GPUs, Linux / Wine.

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the initial change, test, and description; I reviewed the diff and ran the tests and smoke runs.
  • Antigravity with Gemini 4 Neon: rebased onto main e1d84b7, addressed the P1 review (CompareObjectHandles real-handle identity, committing through VirtualAllocEx to respect handle access rights, pre-validating mixed ranges to avoid partial commits, and adding the 3 new regression tests), reran the full workspace suite and 60 s smoke test, and updated this description.
<!-- greyfinch-sync:ivall/xcl:issue:5472671430 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-24T13:03:30Z. --- `MapTitlePhysicalPages` / `XMemMapPhysicalPages` map fresh pages into a title's own reservation lazily: the page stays reserved (`lazy::mark`) until it is first touched. A title that maps pages and calls `VirtualProtect` on them before touching them got FALSE with `ERROR_INVALID_ADDRESS` (487). Windows' `VirtualProtect` fails when any page in the range is not committed. On the console the pages are mapped, and XCL's non-lazy path for the same call commits them, so there the call succeeds. `lazy.rs` itself notes that kernel calls fail on lazy pages and that buffers passed to them are committed first (`ensure`). The `VirtualProtect` wrapper did not do that. `VirtualProtect`, and `VirtualProtectEx` for the current process (matching both the pseudo-handle and real current-process handles via `CompareObjectHandles`), now call `lazy::ensure_for_protect` on the range first: - Pre-validates that every 4 KiB page in `[addr, addr + size)` is either already `MEM_COMMIT` or marked lazy (`MEM_RESERVE` in `LAZY`) before committing any lazy page, so a mixed range containing an uncommitted non-lazy or free page fails `VirtualProtect` with `ERROR_INVALID_ADDRESS` and leaves lazy pages uncommitted and still marked lazy. - Commits lazy pages through the supplied process handle via `VirtualAllocEx`, so a real handle lacking `PROCESS_VM_OPERATION` fails with `ERROR_ACCESS_DENIED` without committing or unmarking any lazy page. - Skips pre-commit when `old` is null. **What is in it** - `crates/xcl/src/hle/kernelx/lazy.rs`: `ensure_for_protect(proc_, p, len)`. - `crates/xcl/src/hle/kernelx.rs`: `is_current_process_handle`, `VirtualProtect`, `VirtualProtectEx`; four unit tests: - `virtual_protect_commits_lazy_pages_first` - `virtual_protect_ex_commits_lazy_pages_through_real_handle` (real handle opened with only `PROCESS_VM_OPERATION`) - `virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages` (real handle opened with only `PROCESS_QUERY_LIMITED_INFORMATION` -> `ERROR_ACCESS_DENIED`, page stays `MEM_RESERVE` and still lazy) - `virtual_protect_mixed_range_leaves_lazy_page_uncommitted` (lazy page + plain `MEM_RESERVE` page -> `ERROR_INVALID_ADDRESS`, lazy page stays `MEM_RESERVE` and still lazy) #1034 adds a different line at the top of `VirtualProtect`; the two changes are independent (a rebase keeps both lines). **Tested** - AMD Radeon RX 9060 XT (driver 32.0.31044.16), Ryzen 5 5600, Windows 11 Pro 26300, Rust 1.100.0; tests debug, smoke release - `cargo test --workspace --no-fail-fast -- --test-threads=4` on `ecac22b` (rebased onto `main` `e1d84b7`): `1425 passed, 2 failed, 46 ignored; 8 SKIPPED` (6 in `lower_dxil::tests::{f16,f32}_programs_on_the_gpu`; `heap_window_out_of_memory_falls_back_to_the_switch_form`; `pso_measurement_compiles_an_exact_synthetic_record`) - All 4 `hle::kernelx::tests::virtual_protect*` tests pass. - The 2 failures (`gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` seed 722 and `fuzz_validate_and_gpu_3` seed 1599) fail identically on unmodified `main` on this GPU. **Regression run** main (`08db8020`): ``` xcl-smoke v1 commit: 08db8020d323bf478964fcc586152cce54959cfc gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1553 (PresentX 1553) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13966 MB ``` this PR (`ecac22b`): ``` xcl-smoke v1 commit: ecac22b4021d4a68f1325e7390e5de72fb7ae0b7 gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1585 (PresentX 1585) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13931 MB ``` **Not tested** - A title that protects freshly mapped pages before touching them; the smoke title's run is a regression check only. - NVIDIA and Intel GPUs, Linux / Wine. **AI use** - Claude Code with Claude Opus 5.5: found the problem, wrote the initial change, test, and description; I reviewed the diff and ran the tests and smoke runs. - Antigravity with Gemini 4 Neon: rebased onto `main` `e1d84b7`, addressed the P1 review (`CompareObjectHandles` real-handle identity, committing through `VirtualAllocEx` to respect handle access rights, pre-validating mixed ranges to avoid partial commits, and adding the 3 new regression tests), reran the full workspace suite and 60 s smoke test, and updated this description.
fromthemoonx commented 2026-11-24 13:27:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-24T13:27:08Z.


Rerun on the new head dfc3100 (the preflight stops at a second reservation): passes on the RTX 3060, and the new test catches a preflight that crosses into the next reservation.

result
cargo test --workspace --no-fail-fast -- --test-threads=4, dfc3100 merged onto main 8b957be (clean) 1451 passed, 0 failed, 47 ignored; 25 SKIPPED lines
virtual_protect_adjacent_reservations_leave_lazy_pages_uncommitted alone, 40 runs; hle::kernelx:: (48 tests) at --test-threads=8, 30 runs 40 of 40; 30 of 30 (47 passed, 1 ignored each)
the same test with Some(base) if base != mbi.AllocationBase => return disabled (scratch) fails 3 of 3: first reservation must stay uncommitted, left 4096 (MEM_COMMIT), right 8192 (MEM_RESERVE)

Same RTX 3060 (driver 610.88), Rust 1.100.0, debug. AI use: Claude Code (Claude Opus 5.5) ran the tests and the scratch check and wrote this rerun.


Rerun on ecac22b: passed on the RTX 3060, and each of the three new tests caught the part it covers.

result
cargo test --workspace --no-fail-fast -- --test-threads=4, ecac22b merged onto main 08db802 (clean) 1433 passed, 0 failed, 47 ignored; 25 SKIPPED lines
each of the 4 virtual_protect* tests alone, 30 runs 30 of 30 each
hle::kernelx:: (46 tests), --test-threads=8, 30 runs 30 of 30
scratch: no lazy::ensure_for_protect call virtual_protect_commits_lazy_pages_first and virtual_protect_ex_commits_lazy_pages_through_real_handle fail
scratch: is_current_process_handle only proc_ == GetCurrentProcess() virtual_protect_ex_commits_lazy_pages_through_real_handle fails
scratch: plain lazy::ensure instead of ensure_for_protect virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages and virtual_protect_mixed_range_leaves_lazy_page_uncommitted fail

Same machine, debug. The reports below are for older heads.


Full-suite run, to go with the kernelx run above.

Tested

  • NVIDIA GeForce RTX 3060 12 GB, driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 stable-x86_64-pc-windows-msvc; debug
  • Exact head d0211db87edcb1bbbc5b68463b70c0dc31f1294c, which is on current main 47efa2e: cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 742 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • Fails without the change: with kernelx.rs as on main plus only virtual_protect_commits_lazy_pages_first, the test fails with VirtualProtect on lazy pages, left: (0, 487), right: (1, 0): FALSE with ERROR_INVALID_ADDRESS, as the description says.
  • hle::kernelx tests (lazy pages included), 10 runs: 10 of 10 passed (32 passed, 1 ignored each)
  • e2e, 3 runs: 3 of 3 passed

Not tested

  • A retail title calling VirtualProtect on freshly mapped pages; release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the build and tests on the machine above, including the check without the change, and wrote this report from the output.
<!-- greyfinch-sync:ivall/xcl:comment:7132848507 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7132848507). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-11-24T13:27:08Z. --- **Rerun on the new head `dfc3100` (the preflight stops at a second reservation): passes on the RTX 3060, and the new test catches a preflight that crosses into the next reservation.** | | result | |---|---| | `cargo test --workspace --no-fail-fast -- --test-threads=4`, `dfc3100` merged onto `main` `8b957be` (clean) | 1451 passed, 0 failed, 47 ignored; 25 `SKIPPED` lines | | `virtual_protect_adjacent_reservations_leave_lazy_pages_uncommitted` alone, 40 runs; `hle::kernelx::` (48 tests) at `--test-threads=8`, 30 runs | 40 of 40; 30 of 30 (47 passed, 1 ignored each) | | the same test with `Some(base) if base != mbi.AllocationBase => return` disabled (scratch) | fails 3 of 3: `first reservation must stay uncommitted`, left `4096` (`MEM_COMMIT`), right `8192` (`MEM_RESERVE`) | Same RTX 3060 (driver 610.88), Rust 1.100.0, debug. AI use: Claude Code (Claude Opus 5.5) ran the tests and the scratch check and wrote this rerun. --- *Rerun on `ecac22b`:* passed on the RTX 3060, and each of the three new tests caught the part it covers. | | result | |---|---| | `cargo test --workspace --no-fail-fast -- --test-threads=4`, `ecac22b` merged onto `main` `08db802` (clean) | 1433 passed, 0 failed, 47 ignored; 25 `SKIPPED` lines | | each of the 4 `virtual_protect*` tests alone, 30 runs | 30 of 30 each | | `hle::kernelx::` (46 tests), `--test-threads=8`, 30 runs | 30 of 30 | | scratch: no `lazy::ensure_for_protect` call | `virtual_protect_commits_lazy_pages_first` and `virtual_protect_ex_commits_lazy_pages_through_real_handle` fail | | scratch: `is_current_process_handle` only `proc_ == GetCurrentProcess()` | `virtual_protect_ex_commits_lazy_pages_through_real_handle` fails | | scratch: plain `lazy::ensure` instead of `ensure_for_protect` | `virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages` and `virtual_protect_mixed_range_leaves_lazy_page_uncommitted` fail | Same machine, debug. The reports below are for older heads. --- Full-suite run, to go with the `kernelx` run above. **Tested** - NVIDIA GeForce RTX 3060 12 GB, driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974); rustc 1.100.0 `stable-x86_64-pc-windows-msvc`; debug - **Exact head `d0211db87edcb1bbbc5b68463b70c0dc31f1294c`**, which is on current `main` `47efa2e`: `cargo build --workspace`, then `cargo test --workspace --no-fail-fast -- --test-threads=4`: **742 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - **Fails without the change:** with `kernelx.rs` as on `main` plus only `virtual_protect_commits_lazy_pages_first`, the test fails with `VirtualProtect on lazy pages`, `left: (0, 487), right: (1, 0)`: FALSE with `ERROR_INVALID_ADDRESS`, as the description says. - `hle::kernelx` tests (lazy pages included), 10 runs: **10 of 10 passed** (32 passed, 1 ignored each) - `e2e`, 3 runs: **3 of 3 passed** **Not tested** - A retail title calling `VirtualProtect` on freshly mapped pages; release build. **AI use** - Claude Code (Claude Opus 5.5) ran the build and tests on the machine above, including the check without the change, and wrote this report from the output.
thehollowedone commented 2026-11-24 14:06:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-24T13:18:49Z.


Independent Windows check of the current ecac22b. This supersedes my earlier real-handle finding on d0211db; the current revision includes the access-rights and mixed-range changes.

Tested: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (driver 621.35), Rust 1.99.1 MSVC, debug, DXC 1.8.2502.11.

  • cargo test -p xcl --lib virtual_protect -- --nocapture --test-threads=1: 4 passed, 0 failed, 0 ignored. This includes the real current-process handle, insufficient-access/no-commit, and mixed-range/no-commit cases.
  • cargo build --workspace: passed.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1,427 passed, 0 failed, 46 ignored; 25 GPU skip notices. The four focused cases also passed in this run.

The test worktree was clean at the exact PR head. Not tested: my own retail smoke run, foreign-process handles, AMD hardware, or Wine. The author supplied paired main/head smoke blocks in the PR description; I did not independently reproduce those.

AI use: Codex (GPT-6.2 Sol) reviewed the diff, ran the tests on this machine, and drafted this report. AI-assisted.

<!-- greyfinch-sync:ivall/xcl:comment:7132650299 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7132650299). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-24T13:18:49Z. --- Independent Windows check of the current [`ecac22b`](https://github.com/xcl-dev/xcl/pull/1191/commits/ecac22b4021d4a68f1325e7390e5de72fb7ae0b7). This supersedes my earlier real-handle finding on `d0211db`; the current revision includes the access-rights and mixed-range changes. **Tested:** Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (driver 621.35), Rust 1.99.1 MSVC, debug, DXC 1.8.2502.11. - `cargo test -p xcl --lib virtual_protect -- --nocapture --test-threads=1`: 4 passed, 0 failed, 0 ignored. This includes the real current-process handle, insufficient-access/no-commit, and mixed-range/no-commit cases. - `cargo build --workspace`: passed. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1,427 passed, 0 failed, 46 ignored; 25 GPU skip notices. The four focused cases also passed in this run. The test worktree was clean at the exact PR head. **Not tested:** my own retail smoke run, foreign-process handles, AMD hardware, or Wine. The author supplied paired main/head smoke blocks in the PR description; I did not independently reproduce those. **AI use:** Codex (GPT-6.2 Sol) reviewed the diff, ran the tests on this machine, and drafted this report. AI-assisted.
DavidM1911 commented 2026-11-24 14:06:32 +00:00 (Migrated from github.com)

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


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 kernelx: 33 passed, 0 failed, 1 ignored — the VirtualProtect lazy-commit change keeps the kernelx suite green.

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

<!-- greyfinch-sync:ivall/xcl:comment:7132782254 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1191#issuecomment-7132782254). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T13:24:21Z. --- 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 kernelx`: **33 passed, 0 failed, 1 ignored** — the VirtualProtect lazy-commit change keeps the kernelx suite green. AI use: test runs by Devin (Cognition, SWE-2); no code changes.
JoaoPauluu commented 2026-11-24 15:05:57 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-24T14:34:45Z.


A run on Linux under Wine.

Tested

  • RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. d0211db as it is (based on 47efa2e), no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact). VirtualProtect is Wine's here, so this checks the lazy-page commit against Wine's memory manager.
  • hle::kernelx::tests::virtual_protect_commits_lazy_pages_first: ok, no SKIPPED.

Not tested

  • whether the new tests fail without the change on this stack; the rest of the suite on this head; a retail title; native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
<!-- greyfinch-sync:ivall/xcl:comment:7134605761 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1191#issuecomment-7134605761). Originally posted by [JoaoPauluu](https://github.com/JoaoPauluu) on 2026-11-24T14:34:45Z. --- A run on Linux under Wine. **Tested** - RTX 3060 12 GB (NVIDIA 620.70.06, 32-lane waves), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for `x86_64-pc-windows-gnu`. `d0211db` as it is (based on `47efa2e`), no uncommitted changes. The lib test binary runs under Wine, one test per process (`--exact`). `VirtualProtect` is Wine's here, so this checks the lazy-page commit against Wine's memory manager. - `hle::kernelx::tests::virtual_protect_commits_lazy_pages_first`: **ok**, no SKIPPED. **Not tested** - whether the new tests fail without the change on this stack; the rest of the suite on this head; a retail title; native Windows. **AI use** - Claude Code (Claude Opus 5.5) built the head, ran the tests and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.
4usphs commented 2026-11-25 12:06:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by 4usphs on 2026-11-25T11:52:36Z.


AMD run on the exact head d0211db (d0211db87e), as pushed on its base 47efa2e (not merged onto current main), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2.

Tested

  • Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug, clean checkout, XCL_TRANSLATED_CACHE=0; adapter picked with XCL_ADAPTER.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4:
    • AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: 742 passed, 0 failed, 41 ignored
    • AMD Radeon(TM) Graphics, the 9800X3D's iGPU (RDNA2, gfx1036), driver 32.0.21045.29003: 742 passed, 0 failed, 41 ignored
  • No SKIPPED tests on either adapter.
  • This PR's test virtual_protect_commits_lazy_pages_first runs and passes on both adapters.

Not tested

  • smoke or a retail title (I have none), a release build, Linux.

AI use

  • Claude Code (Claude Opus 5.5) read the diff, ran the tests and the base-commit controls on my PC and wrote this report. I have not reviewed the code.
<!-- greyfinch-sync:ivall/xcl:comment:7161621329 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7161621329). Originally posted by [4usphs](https://github.com/4usphs) on 2026-11-25T11:52:36Z. --- AMD run on the exact head `d0211db` (d0211db87edcb1bbbc5b68463b70c0dc31f1294c), as pushed on its base `47efa2e` (not merged onto current `main`), on two AMD adapters with native 64-lane waves: RDNA4 and the console's generation, RDNA2. **Tested** - Ryzen 7 9800X3D, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug, clean checkout, `XCL_TRANSLATED_CACHE=0`; adapter picked with `XCL_ADAPTER`. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: - AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: **742 passed, 0 failed, 41 ignored** - AMD Radeon(TM) Graphics, the 9800X3D's iGPU (RDNA2, `gfx1036`), driver 32.0.21045.29003: **742 passed, 0 failed, 41 ignored** - No `SKIPPED` tests on either adapter. - This PR's test `virtual_protect_commits_lazy_pages_first` runs and passes on both adapters. **Not tested** - smoke or a retail title (I have none), a release build, Linux. **AI use** - Claude Code (Claude Opus 5.5) read the diff, ran the tests and the base-commit controls on my PC and wrote this report. I have not reviewed the code.
xpatfussy69x commented 2026-11-25 12:06:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by xpatfussy69x on 2026-11-25T11:58:25Z.


Test report for head d0211db as pushed (not merged onto current main) – NVIDIA, wave32.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; 32 GB RAM; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored
  • SKIPPED GPU tests on this adapter: 2 (no wave64)
  • this PR's test virtual_protect_commits_lazy_pages_first ran and passed
  • no XCL_SAMPLE_* data set (game-data tests not run)

Not tested

  • a smoke run on a title; AMD / native wave64; release build; the head merged onto current main

AI use

  • Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.
<!-- greyfinch-sync:ivall/xcl:comment:7161750652 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7161750652). Originally posted by [xpatfussy69x](https://github.com/xpatfussy69x) on 2026-11-25T11:58:25Z. --- Test report for head `d0211db` as pushed (not merged onto current `main`) – NVIDIA, wave32. **Tested** - NVIDIA GeForce RTX 3060 12 GB (Ampere, 32-lane waves only), driver 32.0.16.2124; AMD Ryzen 5 7500F; 32 GB RAM; Windows NT 10.0.26300; Rust 1.100.0 (stable-x86_64-pc-windows-msvc); debug; DXC 1.9.2609.5 - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 742 passed, 0 failed, 41 ignored - SKIPPED GPU tests on this adapter: 2 (no wave64) - this PR's test `virtual_protect_commits_lazy_pages_first` ran and passed - no `XCL_SAMPLE_*` data set (game-data tests not run) **Not tested** - a smoke run on a title; AMD / native wave64; release build; the head merged onto current `main` **AI use** - Claude (Claude Opus 5.5) wrote the script that ran the suite on my PC, read the log and wrote and posted this report with my approval; the run is mine.
ClosetPie107 commented 2026-11-25 13:05:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-25T12:28:14Z.


Linux / AMD RDNA4 (RADV) test report for head d0211db merged locally onto main 1a0bbe3 (clean merge).

Environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton v3.1 (#257 + dxil-spirv 53aac418), DXVK v3.1.1-209, DXC 1.9.2609.5, x86_64-pc-windows-gnu cross-compile

Tested (debug test binary under Wine, --test-threads=1 --nocapture)

  • hle::kernelx::tests: 40 passed, 0 failed, 1 ignored (scatter_timing), 0 skipped (1.20 s), including virtual_protect_commits_lazy_pages_first.

Not tested: full workspace suite, retail title run, native Windows.

AI use: T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7162416050 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7162416050). Originally posted by [ClosetPie107](https://github.com/ClosetPie107) on 2026-11-25T12:28:14Z. --- Linux / AMD RDNA4 (RADV) test report for head `d0211db` merged locally onto `main` `1a0bbe3` (clean merge). **Environment** - AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS - Proton Experimental (`experimental-11.0-20261112`), vkd3d-proton v3.1 (`#257` + `dxil-spirv` `53aac418`), DXVK `v3.1.1-209`, DXC `1.9.2609.5`, `x86_64-pc-windows-gnu` cross-compile **Tested** (debug test binary under Wine, `--test-threads=1 --nocapture`) - `hle::kernelx::tests`: **40 passed, 0 failed, 1 ignored (`scatter_timing`), 0 skipped** (1.20 s), including `virtual_protect_commits_lazy_pages_first`. **Not tested:** full workspace suite, retail title run, native Windows. **AI use:** T3 Code / Antigravity (Gemini 4 Neon) merged, built, ran the tests on this machine, and drafted this report.
bmjask commented 2026-11-25 21:33:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T21:33:32Z.

Review: COMMENTED


P1 VirtualProtectEx scope bug: lazy::ensure runs only for proc_ == GetCurrentProcess(), so a real handle opened on current process is rejected despite same identity (Windows reproduction returns ERROR_INVALID_ADDRESS; CompareObjectHandles recognizes it). Use robust same-process handle identity and commit through supplied handle respecting access; add real-handle success plus insufficient-access/no-side-effect coverage. Also decide/test whether ensure-before-VirtualProtect validation may commit lazy pages even when mixed range validation ultimately fails. Current Windows check fails and needs refresh.

<!-- greyfinch-sync:ivall/xcl:review:6065276697 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#pullrequestreview-6065276697). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T21:33:32Z. **Review:** COMMENTED --- P1 VirtualProtectEx scope bug: lazy::ensure runs only for proc_ == GetCurrentProcess(), so a real handle opened on current process is rejected despite same identity (Windows reproduction returns ERROR_INVALID_ADDRESS; CompareObjectHandles recognizes it). Use robust same-process handle identity and commit through supplied handle respecting access; add real-handle success plus insufficient-access/no-side-effect coverage. Also decide/test whether ensure-before-VirtualProtect validation may commit lazy pages even when mixed range validation ultimately fails. Current Windows check fails and needs refresh.
emirduran707 commented 2026-11-25 23:09:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-25T23:03:46Z.


Thanks for the thorough review @bmjask! Addressed all points in ecac22b (rebased onto current main e1d84b7 so Windows CI refreshes cleanly):

  1. Real current-process handles & access rights: is_current_process_handle now matches both GetCurrentProcess() and real handles to the current process via CompareObjectHandles. Lazy commits now go through VirtualAllocEx(proc_, ...) inside lazy::ensure_for_protect, so a handle with PROCESS_VM_OPERATION commits and succeeds while a handle lacking PROCESS_VM_OPERATION fails with ERROR_ACCESS_DENIED without committing or unmarking any lazy page.
  2. Mixed-range atomicity: ensure_for_protect now pre-walks [addr, addr + size) with VirtualQuery (and skips when old is null) so if any page in the range is MEM_FREE or non-lazy MEM_RESERVE, no lazy pages are committed before VirtualProtect(Ex) returns ERROR_INVALID_ADDRESS.
  3. New tests (all 4 passing locally on Windows 11 26300, 1425 passed, 2 pre-existing RX 9060 XT fuzz failed, 46 ignored; 60 s smoke 1585 frames, 13931 MB peak, 0 device removals, 0 crashes):
    • virtual_protect_ex_commits_lazy_pages_through_real_handle
    • virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages
    • virtual_protect_mixed_range_leaves_lazy_page_uncommitted
<!-- greyfinch-sync:ivall/xcl:comment:7177102412 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7177102412). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-25T23:03:46Z. --- Thanks for the thorough review @bmjask! Addressed all points in `ecac22b` (rebased onto current `main` `e1d84b7` so Windows CI refreshes cleanly): 1. **Real current-process handles & access rights**: `is_current_process_handle` now matches both `GetCurrentProcess()` and real handles to the current process via `CompareObjectHandles`. Lazy commits now go through `VirtualAllocEx(proc_, ...)` inside `lazy::ensure_for_protect`, so a handle with `PROCESS_VM_OPERATION` commits and succeeds while a handle lacking `PROCESS_VM_OPERATION` fails with `ERROR_ACCESS_DENIED` without committing or unmarking any lazy page. 2. **Mixed-range atomicity**: `ensure_for_protect` now pre-walks `[addr, addr + size)` with `VirtualQuery` (and skips when `old` is null) so if any page in the range is `MEM_FREE` or non-lazy `MEM_RESERVE`, no lazy pages are committed before `VirtualProtect(Ex)` returns `ERROR_INVALID_ADDRESS`. 3. **New tests** (all 4 passing locally on Windows 11 26300, `1425 passed, 2 pre-existing RX 9060 XT fuzz failed, 46 ignored`; 60 s smoke `1585 frames, 13931 MB peak, 0 device removals, 0 crashes`): - `virtual_protect_ex_commits_lazy_pages_through_real_handle` - `virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages` - `virtual_protect_mixed_range_leaves_lazy_page_uncommitted`
DavidM1911 commented 2026-11-26 04:07:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T03:52:39Z.


Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

<!-- greyfinch-sync:ivall/xcl:comment:7182100190 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7182100190). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T03:52:39Z. --- Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
futurepro62 commented 2026-11-26 06:06:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-26T05:36:43Z.


NVIDIA and AMD full-suite run, to go with the reports above by fromthemoonx, thehollowedone, since none of them covers AMD. Tested exact head ecac22b4 (on its base e1d84b7).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1415 passed, 0 failed, 44 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, dispatch_chain_native_wave64_builds_whole, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: virtual_protect_commits_lazy_pages_first, virtual_protect_ex_commits_lazy_pages_through_real_handle, virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages, virtual_protect_mixed_range_leaves_lazy_page_uncommitted.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1426 passed, 0 failed, 46 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main b49be183 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (#1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7183644107 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7183644107). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T05:36:43Z. --- NVIDIA and AMD full-suite run, to go with the reports above by fromthemoonx, thehollowedone, since none of them covers AMD. Tested exact head `ecac22b4` (on its base `e1d84b7`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests`: **1415 passed, 0 failed, 44 ignored**. SKIPPED (no wave64): `a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu`, `a_per_lane_2d_or_3d_group_runs_on_the_gpu`, `coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu`, `cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu`, `dispatch_chain_native_wave64_builds_whole`, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, `the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu`. - The new tests ran and passed: `virtual_protect_commits_lazy_pages_first`, `virtual_protect_ex_commits_lazy_pages_through_real_handle`, `virtual_protect_ex_insufficient_access_does_not_commit_lazy_pages`, `virtual_protect_mixed_range_leaves_lazy_page_uncommitted`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1`: **1426 passed, 0 failed, 46 ignored**. SKIPPED: `f16_programs_on_the_gpu` (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `--skip` leaves out tests that fail on main `b49be183` too, not because of this PR. On NVIDIA: `heap_window_out_of_memory_falls_back_to_the_switch_form` (#1651), the four `gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu` tests, `const_and_null_mask_operands_agree_with_hlsl_on_the_gpu` and `mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu` ([follow-up on #1651](https://github.com/xcl-dev/xcl/issues/1651#issuecomment-7146069648)) fail because `runner::skip_test` turns their skips into failures under `XCL_REQUIRE_GPU=mesh`, and `gpu::dxil::fuzz_tests` seeds 70, 545, 1019 and 1507 fail `CreateComputePipelineState` with `E_OUTOFMEMORY` on this card (drivers 616.64 and 621.40). On AMD: `fuzz_validate_and_gpu_1` fails on seed 540 (`res[833]` 0x7 vs CPU 0x6). The AMD run does not set `XCL_REQUIRE_GPU`. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
gut0to commented 2026-11-26 16:15:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T16:15:52Z.

Review: COMMENTED


AI-assisted review: I inspected this change and its added tests; I did not run the test suite. I found one edge case where the preflight can still leave side effects after VirtualProtect fails.

<!-- greyfinch-sync:ivall/xcl:review:6077396242 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#pullrequestreview-6077396242). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T16:15:52Z. **Review:** COMMENTED --- AI-assisted review: I inspected this change and its added tests; I did not run the test suite. I found one edge case where the preflight can still leave side effects after VirtualProtect fails.
gut0to commented 2026-11-26 16:15:52 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T16:15:52Z.

Code review location: crates/xcl/src/hle/kernelx/lazy.rs; line 141

@@ -100,6 +100,77 @@ pub fn ensure(p: usize, len: usize) {
     }
 }
 
+/// Commit lazy pages in `[p, p + len)` through `proc_` for `VirtualProtect` / `VirtualProtectEx`.
+///
+/// Only commits when every page in the range is already `MEM_COMMIT` or marked lazy (so a mixed
+/// range containing an uncommitted non-lazy or free page fails `VirtualProtect` with no side
+/// effects), and commits through `proc_` via `VirtualAllocEx` so handles lacking
+/// `PROCESS_VM_OPERATION` fail without committing or unmarking any lazy page.
+pub(super) unsafe fn ensure_for_protect(proc_: HANDLE, p: usize, len: usize) {
+    const SYS_PAGE: usize = 0x1000;
+    if len == 0 {
+        return;
+    }
+    let Some(end) = p.checked_add(len) else {
+        return;
+    };
+    let pages: Vec<usize> = {
+        let g = LAZY.read().unwrap_or_else(|e| e.into_inner());
+        if g.is_empty() {
+            return;
+        }
+        g.range(p & !(PAGE - 1)..end).copied().collect()
+    };
+    if pages.is_empty() {
+        return;
+    }
+    let start_4k = p & !(SYS_PAGE - 1);
+    let Some(end_4k) = end.checked_add(SYS_PAGE - 1).map(|e| e & !(SYS_PAGE - 1)) else {
+        return;
+    };
+    let mut cur = start_4k;
+    while cur < end_4k {
+        let mut mbi: MEMORY_BASIC_INFORMATION = std::mem::zeroed();
+        if VirtualQuery(cur as *const c_void, &mut mbi, std::mem::size_of_val(&mbi)) == 0 {
+            return;
+        }
+        let seg_end = (mbi.BaseAddress as usize).saturating_add(mbi.RegionSize).min(end_4k);
+        if seg_end <= cur {
+            return;
+        }
+        if mbi.State == MEM_COMMIT {

Could the preflight also verify that every region in the requested range has the same AllocationBase? VirtualProtect fails with ERROR_INVALID_ADDRESS when a range spans two adjacent but separately reserved regions. If both regions are marked lazy, this loop currently commits each page and removes its lazy mark before the native VirtualProtect call fails, so the failed operation changes both reservations. A focused test with two adjacent reservations could assert the call fails and both pages remain reserved/lazy. AI-assisted review; I inspected the diff and tests but did not run them.

<!-- greyfinch-sync:ivall/xcl:review-comment:4710979222 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#discussion_r4710979222). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T16:15:52Z. **Code review location:** `crates/xcl/src/hle/kernelx/lazy.rs`; line 141 ~~~~diff @@ -100,6 +100,77 @@ pub fn ensure(p: usize, len: usize) { } } +/// Commit lazy pages in `[p, p + len)` through `proc_` for `VirtualProtect` / `VirtualProtectEx`. +/// +/// Only commits when every page in the range is already `MEM_COMMIT` or marked lazy (so a mixed +/// range containing an uncommitted non-lazy or free page fails `VirtualProtect` with no side +/// effects), and commits through `proc_` via `VirtualAllocEx` so handles lacking +/// `PROCESS_VM_OPERATION` fail without committing or unmarking any lazy page. +pub(super) unsafe fn ensure_for_protect(proc_: HANDLE, p: usize, len: usize) { + const SYS_PAGE: usize = 0x1000; + if len == 0 { + return; + } + let Some(end) = p.checked_add(len) else { + return; + }; + let pages: Vec<usize> = { + let g = LAZY.read().unwrap_or_else(|e| e.into_inner()); + if g.is_empty() { + return; + } + g.range(p & !(PAGE - 1)..end).copied().collect() + }; + if pages.is_empty() { + return; + } + let start_4k = p & !(SYS_PAGE - 1); + let Some(end_4k) = end.checked_add(SYS_PAGE - 1).map(|e| e & !(SYS_PAGE - 1)) else { + return; + }; + let mut cur = start_4k; + while cur < end_4k { + let mut mbi: MEMORY_BASIC_INFORMATION = std::mem::zeroed(); + if VirtualQuery(cur as *const c_void, &mut mbi, std::mem::size_of_val(&mbi)) == 0 { + return; + } + let seg_end = (mbi.BaseAddress as usize).saturating_add(mbi.RegionSize).min(end_4k); + if seg_end <= cur { + return; + } + if mbi.State == MEM_COMMIT { ~~~~ --- Could the preflight also verify that every region in the requested range has the same AllocationBase? VirtualProtect fails with ERROR_INVALID_ADDRESS when a range spans two adjacent but separately reserved regions. If both regions are marked lazy, this loop currently commits each page and removes its lazy mark before the native VirtualProtect call fails, so the failed operation changes both reservations. A focused test with two adjacent reservations could assert the call fails and both pages remain reserved/lazy. AI-assisted review; I inspected the diff and tests but did not run them.
emirduran707 commented 2026-11-26 20:16:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-26T20:16:42Z.


Good catch, thank you! Updated in dfc3100c:

  • lazy::ensure_for_protect now tracks mbi.AllocationBase across the VirtualQuery preflight loop and returns early if any region has a null or differing AllocationBase, so a VirtualProtect spanning two adjacent reservations leaves both untouched before failing with ERROR_INVALID_ADDRESS.
  • Added virtual_protect_adjacent_reservations_leave_lazy_pages_uncommitted in crates/xcl/src/hle/kernelx.rs verifying that both adjacent lazy reservations stay MEM_RESERVE and keep their lazy marks when the spanning VirtualProtect fails.
  • Re-ran hle::kernelx::tests::virtual_protect (5/5 passed) and hle::kernelx::lazy::tests (2/2 passed).
<!-- greyfinch-sync:ivall/xcl:comment:7202488009 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7202488009). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-26T20:16:42Z. --- Good catch, thank you! Updated in `dfc3100c`: - `lazy::ensure_for_protect` now tracks `mbi.AllocationBase` across the `VirtualQuery` preflight loop and returns early if any region has a null or differing `AllocationBase`, so a `VirtualProtect` spanning two adjacent reservations leaves both untouched before failing with `ERROR_INVALID_ADDRESS`. - Added `virtual_protect_adjacent_reservations_leave_lazy_pages_uncommitted` in `crates/xcl/src/hle/kernelx.rs` verifying that both adjacent lazy reservations stay `MEM_RESERVE` and keep their lazy marks when the spanning `VirtualProtect` fails. - Re-ran `hle::kernelx::tests::virtual_protect` (5/5 passed) and `hle::kernelx::lazy::tests` (2/2 passed).
Foniass commented 2026-12-01 05:03:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:03:24Z.


Triage (#1607) – head dfc3100

No open or merged PR commits lazy pages before VirtualProtect / VirtualProtectEx; main still calls the OS directly on a range that may hold uncommitted lazy pages.
The branch conflicts with main: VirtualProtect / VirtualProtectEx in kernelx.rs now call note_protection and use own_process, so the rebase has to keep both (and can reuse own_process instead of the new is_current_process_handle).
Minor: ensure_for_protect commits the pages before mem::VirtualProtect runs, so a call that then fails for another reason (bad protection flags) still leaves them committed.
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:7301376698 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1191#issuecomment-7301376698). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:03:24Z. --- **Triage (#1607)** – head dfc3100 No open or merged PR commits lazy pages before VirtualProtect / VirtualProtectEx; main still calls the OS directly on a range that may hold uncommitted lazy pages. The branch conflicts with main: VirtualProtect / VirtualProtectEx in kernelx.rs now call `note_protection` and use `own_process`, so the rebase has to keep both (and can reuse `own_process` instead of the new `is_current_process_handle`). Minor: `ensure_for_protect` commits the pages before `mem::VirtualProtect` runs, so a call that then fails for another reason (bad protection flags) still leaves them committed. 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/1191:upstream-pr/1191'
git switch 'upstream-pr/1191'

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/1191'
git switch 'upstream-pr/1191'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1191'
git switch 'upstream-pr/1191'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1191'
git switch 'main'
git merge --squash 'upstream-pr/1191'
git switch 'main'
git merge --ff-only 'upstream-pr/1191'
git switch 'main'
git merge 'upstream-pr/1191'
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!1182
No description provided.