eh: harden is_writable for PAGE_GUARD, multi-region spans, and lazy pages #626

Open
opened 2026-11-26 04:27:43 +00:00 by github-bot · 1 comment
Owner

@⁠Grimkaaah on GitHub · 2026-11-24 02:39 UTC · original

Problem

eh::is_writable (used by emulated CLZERO / ClzeroLoop) answers with a single VirtualQuery. That is wrong in four ways (originally listed as item 3 of #278; items 1–2 are on main, item 4 is #321):

  1. PAGE_GUARD. PAGE_READWRITE | PAGE_GUARD (0x104) passes & (PAGE_READWRITE | PAGE_EXECUTE_READWRITE) != 0, so the VEH can write through a guard page instead of letting the real fault happen.
  2. One region only. A ClzeroLoop can cover adjacent committed runs with different protect; one query only sees the first.
  3. Unchecked va + bytes. A wrapping end is undefined.
  4. Lazy physical pages. A page still in MEM_RESERVE (lazy map) makes is_writable false → 0xC000001D, instead of committing via lazy::ensure and zeroing.

Plan

Match the shape of dstorage::writable: checked_add → lazy::ensure → UMA coherent-window fast path → walk every VirtualQuery region covering [va, end), requiring a writable protect and no PAGE_GUARD. Unit tests with VirtualAlloc for guard, multi-region, hole, overflow, and a lazy page.

Complements #501 (sparse-window fast path); does not touch the CLWB race (#321).

Tracking

Split out of #278 item 3 so the fix can land as one small PR.

**@⁠Grimkaaah** on GitHub · 2026-11-24 02:39 UTC · [original](https://github.com/xcl-dev/xcl/issues/626) ## Problem `eh::is_writable` (used by emulated `CLZERO` / `ClzeroLoop`) answers with a single `VirtualQuery`. That is wrong in four ways (originally listed as item 3 of #278; items 1–2 are on `main`, item 4 is #321): 1. **`PAGE_GUARD`.** `PAGE_READWRITE | PAGE_GUARD` (0x104) passes `& (PAGE_READWRITE | PAGE_EXECUTE_READWRITE) != 0`, so the VEH can write through a guard page instead of letting the real fault happen. 2. **One region only.** A `ClzeroLoop` can cover adjacent committed runs with different protect; one query only sees the first. 3. **Unchecked `va + bytes`.** A wrapping end is undefined. 4. **Lazy physical pages.** A page still in `MEM_RESERVE` (lazy map) makes `is_writable` false → `0xC000001D`, instead of committing via `lazy::ensure` and zeroing. ## Plan Match the shape of `dstorage::writable`: `checked_add` → `lazy::ensure` → UMA coherent-window fast path → walk every `VirtualQuery` region covering `[va, end)`, requiring a writable protect and **no** `PAGE_GUARD`. Unit tests with `VirtualAlloc` for guard, multi-region, hole, overflow, and a lazy page. Complements #501 (sparse-window fast path); does not touch the CLWB race (#321). ## Tracking Split out of #278 item 3 so the fix can land as one small PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:27:43 +00:00
Author
Owner

@⁠Grimkaaah on GitHub · 2026-11-24 02:44 UTC · original

Complete PR: https://github.com/ivall/xcl/pull/523 (rebased, smoke on main + head, lib tests 648 passed).

**@⁠Grimkaaah** on GitHub · 2026-11-24 02:44 UTC · [original](https://github.com/xcl-dev/xcl/issues/626#issuecomment-7120430882) Complete PR: https://github.com/ivall/xcl/pull/523 (rebased, smoke on main + head, lib tests 648 passed).
This discussion has been locked. Commenting is limited to contributors.
No description provided.