VFS: ReadFileEx, WriteFile and scatter/gather commit lazy pages first #1345

Merged
emirduran707 merged 1 commit from upstream-pr/1355 into main 2026-11-30 09:10:42 +00:00
emirduran707 commented 2026-11-24 15:09:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-24T15:09:01Z.


Pages a title maps from physical memory into its own reservation stay reserved until first touched (lazy::mark). Kernel calls do not fault them in, they fail, so XCL commits the buffers of the file calls it routes first (lazy.rs). Only ReadFile did that.

On Windows, ReadFileEx, ReadFileScatter, WriteFile, WriteFileEx and WriteFileGather go to their own Nt* calls and never reach the ReadFile hook (measured on Windows 11 26300). On a buffer that is only reserved:

  • ReadFileEx fails with ERROR_NOACCESS (998), and its completion routine never runs;
  • WriteFile fails with ERROR_INVALID_USER_BUFFER (1784).

So a title that reads with ReadFileEx into, or writes from, freshly mapped memory got an error where the console succeeds.

These five calls are now hooked in kernelbase, next to ReadFile. They commit the lazy pages of their buffers before calling the original. For scatter/gather that means each FILE_SEGMENT_ELEMENT page, with each array entry read fault-safely via ReadProcessMemory(GetCurrentProcess(), ...) (after lazy::ensure on the entry address) so an invalid or unreadable segment array pointer never faults in the hook and is left for the kernel API to reject with its normal error. A committed lazy page holds zeros, which is what it held, so writes stay correct. lazy::ensure returns at once for an empty range and takes a shared lock otherwise.

What is in it

  • crates/xcl/src/vfs_hooks.rs: the five hooks and fault-safe ensure_segments.
  • crates/xcl/src/hle/kernelx/lazy.rs: mark is pub for the integration test.
  • crates/xcl/tests/lazy_file_io.rs (new): ReadFileEx into a lazy page, WriteFile and WriteFileEx from one, ReadFileScatter / WriteFileGather with segments in two lazy pages, and scatter_and_gather_reject_invalid_segment_array_without_crashing (testing both an unmapped pointer 0x1000 and a PAGE_NOACCESS page).

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 e5c2bc6 (rebased onto main e1d84b7): 1426 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 5 tests in tests/lazy_file_io.rs pass (including scatter_and_gather_reject_invalid_segment_array_without_crashing).
    • 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 (e5c2bc6):

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

Not tested

  • A title that uses these calls on freshly mapped memory; the smoke title's run is a regression check only.
  • Direct Nt* file calls (not hooked, as before); Wine; NVIDIA and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: found the problem, wrote the initial change, tests, and description; I reviewed the diff and ran the tests and smoke runs.
  • Antigravity with Gemini 4 Neon: rebased onto main e1d84b7, made ensure_segments fault-safe with ReadProcessMemory and added scatter_and_gather_reject_invalid_segment_array_without_crashing, reran the full workspace suite and 60 s smoke test, and updated this description.
<!-- greyfinch-sync:ivall/xcl:issue:5474809534 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-24T15:09:01Z. --- Pages a title maps from physical memory into its own reservation stay reserved until first touched (`lazy::mark`). Kernel calls do not fault them in, they fail, so XCL commits the buffers of the file calls it routes first (`lazy.rs`). Only `ReadFile` did that. On Windows, `ReadFileEx`, `ReadFileScatter`, `WriteFile`, `WriteFileEx` and `WriteFileGather` go to their own `Nt*` calls and never reach the `ReadFile` hook (measured on Windows 11 26300). On a buffer that is only reserved: - `ReadFileEx` fails with `ERROR_NOACCESS` (998), and its completion routine never runs; - `WriteFile` fails with `ERROR_INVALID_USER_BUFFER` (1784). So a title that reads with `ReadFileEx` into, or writes from, freshly mapped memory got an error where the console succeeds. These five calls are now hooked in `kernelbase`, next to `ReadFile`. They commit the lazy pages of their buffers before calling the original. For scatter/gather that means each `FILE_SEGMENT_ELEMENT` page, with each array entry read fault-safely via `ReadProcessMemory(GetCurrentProcess(), ...)` (after `lazy::ensure` on the entry address) so an invalid or unreadable segment array pointer never faults in the hook and is left for the kernel API to reject with its normal error. A committed lazy page holds zeros, which is what it held, so writes stay correct. `lazy::ensure` returns at once for an empty range and takes a shared lock otherwise. **What is in it** - `crates/xcl/src/vfs_hooks.rs`: the five hooks and fault-safe `ensure_segments`. - `crates/xcl/src/hle/kernelx/lazy.rs`: `mark` is `pub` for the integration test. - `crates/xcl/tests/lazy_file_io.rs` (new): `ReadFileEx` into a lazy page, `WriteFile` and `WriteFileEx` from one, `ReadFileScatter` / `WriteFileGather` with segments in two lazy pages, and `scatter_and_gather_reject_invalid_segment_array_without_crashing` (testing both an unmapped pointer `0x1000` and a `PAGE_NOACCESS` page). **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 `e5c2bc6` (rebased onto `main` `e1d84b7`): `1426 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 5 tests in `tests/lazy_file_io.rs` pass (including `scatter_and_gather_reject_invalid_segment_array_without_crashing`). - 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 (`e5c2bc6`): ``` xcl-smoke v1 commit: e5c2bc6e23664e79579fabb31cbbe1cb386c8b44 gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1577 (PresentX 1578) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13962 MB ``` **Not tested** - A title that uses these calls on freshly mapped memory; the smoke title's run is a regression check only. - Direct `Nt*` file calls (not hooked, as before); Wine; NVIDIA and Intel GPUs. **AI use** - Claude Code with Claude Opus 5.5: found the problem, wrote the initial change, tests, and description; I reviewed the diff and ran the tests and smoke runs. - Antigravity with Gemini 4 Neon: rebased onto `main` `e1d84b7`, made `ensure_segments` fault-safe with `ReadProcessMemory` and added `scatter_and_gather_reject_invalid_segment_array_without_crashing`, reran the full workspace suite and 60 s smoke test, and updated this description.
futurepro62 commented 2026-11-24 16:06:59 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:16:38Z.


Full-suite run, since this PR has no test report yet. Tested exact head b5d3ae8 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 755 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: read_file_ex_into_a_lazy_page_reads_the_data, write_file_from_a_lazy_page_writes_zeros, write_file_ex_from_a_lazy_page_writes_zeros, scatter_and_gather_with_lazy_segments_move_the_data.

Not tested

  • AMD, 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:7135753421 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1355#issuecomment-7135753421). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T15:16:38Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `b5d3ae8` (on its base `930e8b4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **755 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `read_file_ex_into_a_lazy_page_reads_the_data`, `write_file_from_a_lazy_page_writes_zeros`, `write_file_ex_from_a_lazy_page_writes_zeros`, `scatter_and_gather_with_lazy_segments_move_the_data`. **Not tested** - AMD, 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.
DavidM1911 commented 2026-11-24 17:06:26 +00:00 (Migrated from github.com)

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


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7137714164 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1355#issuecomment-7137714164). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T16:28:11Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. Thanks!
thehollowedone commented 2026-11-25 10:10:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-25T09:20:57Z.


Independent Windows run on b5d3ae8. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11.

The clean cargo build --workspace --offline --locked -j 4 passed. cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 755 passed, 0 failed, 41 ignored. Cargo's pass count includes two native wave64 runtime skips. All four stock lazy I/O tests passed.

A scratch extension of lazy_file_io verified 16,384 bytes in each direction at a 4 KiB file offset. The scatter read put four distinct payloads into nonadjacent lazy pages in segment-array order. The gather write preserved the new order, read zeros from a fresh lazy page, and left the file's prefix and suffix intact. An unreferenced page stayed reserved. In a fresh process without the file hooks, the same scatter request completed zero bytes with Windows error 998. The focused test filter was local_scatter_gather_reordered_segments_and_nonzero_offsets.

Synthetic valid requests only. Retail streaming was outside the test scope. AI use: Codex (GPT-6, exact variant unspecified) prepared the scratch fixture, ran the tests and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7158209746 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#issuecomment-7158209746). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-25T09:20:57Z. --- Independent Windows run on [b5d3ae8](https://github.com/xcl-dev/xcl/commit/b5d3ae8f5c318d60223dfacb6652268059003dfa). Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11. The clean `cargo build --workspace --offline --locked -j 4` passed. `cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4` finished with **755 passed, 0 failed, 41 ignored**. Cargo's pass count includes two native wave64 runtime skips. All four stock lazy I/O tests passed. A scratch extension of `lazy_file_io` verified 16,384 bytes in each direction at a 4 KiB file offset. The scatter read put four distinct payloads into nonadjacent lazy pages in segment-array order. The gather write preserved the new order, read zeros from a fresh lazy page, and left the file's prefix and suffix intact. An unreferenced page stayed reserved. In a fresh process without the file hooks, the same scatter request completed zero bytes with Windows error 998. The focused test filter was `local_scatter_gather_reordered_segments_and_nonzero_offsets`. Synthetic valid requests only. Retail streaming was outside the test scope. AI use: Codex (GPT-6, exact variant unspecified) prepared the scratch fixture, ran the tests and drafted this report.
oni-swr commented 2026-11-25 19:09:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T18:54:57Z.


AMD RDNA3 full-suite run on exact head b5d3ae8 (b5d3ae8f5c318d60223dfacb6652268059003dfa), merged onto main 3f27770 (clean merge, local detached merge commit, nothing pushed).

Tested

  • AMD Radeon RX 7800 XT (driver 32.0.31035.1003, wave64 hardware), Ryzen 7 5700X3D, Windows 11 Pro 10.0.26200, rustc 1.100.0 MSVC, DXC from Windows SDK 10.0.26100.0, debug build.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on the merged tree: 1359 passed, 2 failed, 46 ignored. the new hle::kernelx::lazy tests passed.
  • The 2 failures are in main too: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier.
  • Baseline, main 3f27770 alone, same command and machine: 1352 passed, 5 failed, 46 ignored. The 3 extra baseline failures (title_textures::placed_title_textures_share_vram_and_preserve_pixels, title_textures::transitions_apply_when_their_list_is_submitted, vram::d32s8_targets_take_their_own_size_of_video_memory) passed in this run; I did not rerun the baseline, so I can't say if they are flaky or load-dependent.
  • SKIPPED (the same set as on main): f16_programs_on_the_gpu and f32_programs_on_the_gpu (refusals for unsupported V_*_F16 forms), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).

Not tested

  • scripts/smoke.ps1 / the regression run, any retail title, a release build, other GPUs. A single run, not repeated.

AI use

  • Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report; I read the logs for the counts above.
<!-- greyfinch-sync:ivall/xcl:comment:7171575210 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#issuecomment-7171575210). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T18:54:57Z. --- AMD RDNA3 full-suite run on exact head `b5d3ae8` (`b5d3ae8f5c318d60223dfacb6652268059003dfa`), merged onto `main` `3f27770` (clean merge, local detached merge commit, nothing pushed). **Tested** - AMD Radeon RX 7800 XT (driver 32.0.31035.1003, wave64 hardware), Ryzen 7 5700X3D, Windows 11 Pro 10.0.26200, rustc 1.100.0 MSVC, DXC from Windows SDK 10.0.26100.0, debug build. - `cargo test --workspace --no-fail-fast -- --test-threads=4` on the merged tree: **1359 passed, 2 failed, 46 ignored**. the new `hle::kernelx::lazy` tests passed. - The 2 failures are in `main` too: `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` and `gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`. - Baseline, `main` `3f27770` alone, same command and machine: 1352 passed, 5 failed, 46 ignored. The 3 extra baseline failures (`title_textures::placed_title_textures_share_vram_and_preserve_pixels`, `title_textures::transitions_apply_when_their_list_is_submitted`, `vram::d32s8_targets_take_their_own_size_of_video_memory`) passed in this run; I did not rerun the baseline, so I can't say if they are flaky or load-dependent. - SKIPPED (the same set as on `main`): `f16_programs_on_the_gpu` and `f32_programs_on_the_gpu` (refusals for unsupported V_*_F16 forms), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). **Not tested** - `scripts/smoke.ps1` / the regression run, any retail title, a release build, other GPUs. A single run, not repeated. **AI use** - Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report; I read the logs for the counts above.
bmjask commented 2026-11-25 21:46:13 +00:00 (Migrated from github.com)

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

Review: COMMENTED


P1: ensure_segments raw-dereferences FILE_SEGMENT_ELEMENT array before original ReadFileScatter/WriteFileGather. Invalid/unreadable segment pointer can crash XCL instead of letting kernel API return error. Use fault-safe read/validate each segment-array entry and add invalid-array regression; valid lazy commits/ordinary async behavior otherwise look sound.

<!-- greyfinch-sync:ivall/xcl:review:6065416545 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#pullrequestreview-6065416545). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T21:46:13Z. **Review:** COMMENTED --- P1: ensure_segments raw-dereferences FILE_SEGMENT_ELEMENT array before original ReadFileScatter/WriteFileGather. Invalid/unreadable segment pointer can crash XCL instead of letting kernel API return error. Use fault-safe read/validate each segment-array entry and add invalid-array regression; valid lazy commits/ordinary async behavior otherwise look sound.
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:50Z.


Thanks for the catch @bmjask! Fixed in e5c2bc6 (rebased onto current main e1d84b7):

  • ensure_segments now checks n == 0 / pointer arithmetic overflow and reads each FILE_SEGMENT_ELEMENT entry through ReadProcessMemory(GetCurrentProcess(), ...) (after lazy::ensure on the entry address) instead of raw-dereferencing segs, so an invalid or unreadable segment array pointer returns cleanly to the original ReadFileScatter / WriteFileGather API instead of crashing.
  • Added scatter_and_gather_reject_invalid_segment_array_without_crashing in crates/xcl/tests/lazy_file_io.rs covering both an unmapped pointer (0x1000) and a PAGE_NOACCESS page for both ReadFileScatter and WriteFileGather (all 5 integration tests pass; full workspace suite 1426 passed, 2 pre-existing RX 9060 XT fuzz failed, 46 ignored; 60 s smoke 1577 frames, 13962 MB peak, 0 device removals, 0 crashes).
<!-- greyfinch-sync:ivall/xcl:comment:7177103510 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#issuecomment-7177103510). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-25T23:03:50Z. --- Thanks for the catch @bmjask! Fixed in `e5c2bc6` (rebased onto current `main` `e1d84b7`): - `ensure_segments` now checks `n == 0` / pointer arithmetic overflow and reads each `FILE_SEGMENT_ELEMENT` entry through `ReadProcessMemory(GetCurrentProcess(), ...)` (after `lazy::ensure` on the entry address) instead of raw-dereferencing `segs`, so an invalid or unreadable segment array pointer returns cleanly to the original `ReadFileScatter` / `WriteFileGather` API instead of crashing. - Added `scatter_and_gather_reject_invalid_segment_array_without_crashing` in `crates/xcl/tests/lazy_file_io.rs` covering both an unmapped pointer (`0x1000`) and a `PAGE_NOACCESS` page for both `ReadFileScatter` and `WriteFileGather` (all 5 integration tests pass; full workspace suite `1426 passed, 2 pre-existing RX 9060 XT fuzz failed, 46 ignored`; 60 s smoke `1577 frames, 13962 MB peak, 0 device removals, 0 crashes`).
DavidM1911 commented 2026-11-26 05:05:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T05:03:16Z.


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:7183138450 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#issuecomment-7183138450). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T05:03:16Z. --- 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
LocranKing commented 2026-11-30 04:31:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by LocranKing on 2026-11-30T04:31:15Z.


merge-check claim
head: e5c2bc6e23

<!-- greyfinch-sync:ivall/xcl:comment:7268847241 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#issuecomment-7268847241). Originally posted by [LocranKing](https://github.com/LocranKing) on 2026-11-30T04:31:15Z. --- merge-check claim head: e5c2bc6e23664e79579fabb31cbbe1cb386c8b44
LocranKing commented 2026-11-30 04:43:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by LocranKing on 2026-11-30T04:43:23Z.


merge-check
base: f3bb664968
head: e5c2bc6e23
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2864 passed, 1 failed, 51 ignored (28 SKIPPED: 22 no wave64, 2 no d3d12SDKLayers.dll, 2 no heap windows, 1 no D3D12 debug layer, 1 Windows Developer Mode required to disable driver cache); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 (also fails identically on base f3bb6649 alone with left (0, 0) vs right (3735928559, 3405691582), introduced on main between f97120dc and f3bb6649). All 5 new integration tests in tests/lazy_file_io.rs passed.
review: none blocking. Read the whole diff across all 3 files (lazy.rs, vfs_hooks.rs, tests/lazy_file_io.rs) and checked the merge result on f3bb6649. ReadFileEx, WriteFile and WriteFileEx guard against null buffers and call lazy::ensure(buf, n) like hk_read_file; ensure_segments checks overflow, commits lazy segment-array pages before reading each 8-byte FILE_SEGMENT_ELEMENT fault-safely via ReadProcessMemory(GetCurrentProcess(), ...), stops at a null terminator or unreadable entry so the kernel API returns its normal error, and commits each 4 KiB segment page. LAZY lock operations do not log or call WriteFile, so hooking WriteFile cannot re-enter LAZY. No duplicates in #1607 or open/merged PRs. Follow-up note (out of scope here): hk_read_file on main now also notifies d3d12x::file_reads::returned for DMA reads into graphics memory, which a separate PR could extend to ReadFileEx/ReadFileScatter if needed.
performance: reasoned: no frame-time or extra memory cost. ReadFileEx/WriteFile/WriteFileEx add one shared LAZY RwLock read + BTreeSet range lookup (same as hk_read_file) ahead of an Nt* file syscall; scatter/gather does one in-process ReadProcessMemory per 4 KiB segment; only lazy pages explicitly passed to file I/O are committed, matching the author's matched smoke pair (1577 vs 1553 frames, 13962 vs 13966 MB peak commit).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3060 Ti 8 GB (driver 621.40 / 32.0.16.2140, wave32), AMD Ryzen 5 5500, Windows 11 build 26300.9974, rustc 1.100.0 (debug), DXC 1.9.2602.17 via XCL_DXC_DIR; Antigravity (Gemini 4 Carbon (High)) ran the merge, build, test suite, base failure verification, duplicate search, and diff review.

<!-- greyfinch-sync:ivall/xcl:comment:7269024950 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#issuecomment-7269024950). Originally posted by [LocranKing](https://github.com/LocranKing) on 2026-11-30T04:43:23Z. --- merge-check base: f3bb66496801c6c710d7c1fd82d75dc776e389e4 head: e5c2bc6e23664e79579fabb31cbbe1cb386c8b44 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2864 passed, 1 failed, 51 ignored (28 SKIPPED: 22 no wave64, 2 no d3d12SDKLayers.dll, 2 no heap windows, 1 no D3D12 debug layer, 1 Windows Developer Mode required to disable driver cache); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 (also fails identically on base f3bb6649 alone with left (0, 0) vs right (3735928559, 3405691582), introduced on main between f97120dc and f3bb6649). All 5 new integration tests in tests/lazy_file_io.rs passed. review: none blocking. Read the whole diff across all 3 files (lazy.rs, vfs_hooks.rs, tests/lazy_file_io.rs) and checked the merge result on f3bb6649. ReadFileEx, WriteFile and WriteFileEx guard against null buffers and call lazy::ensure(buf, n) like hk_read_file; ensure_segments checks overflow, commits lazy segment-array pages before reading each 8-byte FILE_SEGMENT_ELEMENT fault-safely via ReadProcessMemory(GetCurrentProcess(), ...), stops at a null terminator or unreadable entry so the kernel API returns its normal error, and commits each 4 KiB segment page. LAZY lock operations do not log or call WriteFile, so hooking WriteFile cannot re-enter LAZY. No duplicates in #1607 or open/merged PRs. Follow-up note (out of scope here): hk_read_file on main now also notifies d3d12x::file_reads::returned for DMA reads into graphics memory, which a separate PR could extend to ReadFileEx/ReadFileScatter if needed. performance: reasoned: no frame-time or extra memory cost. ReadFileEx/WriteFile/WriteFileEx add one shared LAZY RwLock read + BTreeSet range lookup (same as hk_read_file) ahead of an Nt* file syscall; scatter/gather does one in-process ReadProcessMemory per 4 KiB segment; only lazy pages explicitly passed to file I/O are committed, matching the author's matched smoke pair (1577 vs 1553 frames, 13962 vs 13966 MB peak commit). verdict: safe to merge hardware / tool and model: NVIDIA GeForce RTX 3060 Ti 8 GB (driver 621.40 / 32.0.16.2140, wave32), AMD Ryzen 5 5500, Windows 11 build 26300.9974, rustc 1.100.0 (debug), DXC 1.9.2602.17 via XCL_DXC_DIR; Antigravity (Gemini 4 Carbon (High)) ran the merge, build, test suite, base failure verification, duplicate search, and diff review.
thehollowedone commented 2026-11-30 04:53:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-30T04:53:32Z.


Follow-up on exact head e5c2bc6e23664e79579fabb31cbbe1cb386c8b44: the ReadFileEx and WriteFileEx tests stop after at most fifty SleepEx(100, TRUE) calls. If the request is still pending then, the WriteFileEx test lets its stack OVERLAPPED leave scope, and the later assertion failure unwinds the lazy buffer. Windows requires both the OVERLAPPED and data buffer to remain valid until completion (ReadFileEx, WriteFileEx). I confirmed this from the test paths and API contract; I did not reproduce a delayed completion.

A safe timeout path is to request cancellation for that specific OVERLAPPED with CancelIoEx, then keep the handle, structure and buffer alive and continue alertable waits until the completion routine records completion before asserting the timeout. Microsoft’s cancellation contract says cancellation does not itself wait for I/O completion.

AI use: Codex (GPT-6.2 Sol) checked the test lifetime paths and drafted this follow-up.

<!-- greyfinch-sync:ivall/xcl:comment:7269171464 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#issuecomment-7269171464). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-30T04:53:32Z. --- Follow-up on exact head [`e5c2bc6e23664e79579fabb31cbbe1cb386c8b44`](https://github.com/xcl-dev/xcl/commit/e5c2bc6e23664e79579fabb31cbbe1cb386c8b44): the `ReadFileEx` and `WriteFileEx` tests stop after at most fifty `SleepEx(100, TRUE)` calls. If the request is still pending then, the `WriteFileEx` test lets its stack `OVERLAPPED` leave scope, and the later assertion failure unwinds the lazy buffer. Windows requires both the `OVERLAPPED` and data buffer to remain valid until completion ([ReadFileEx](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfileex), [WriteFileEx](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefileex)). I confirmed this from the test paths and API contract; I did not reproduce a delayed completion. A safe timeout path is to request cancellation for that specific `OVERLAPPED` with `CancelIoEx`, then keep the handle, structure and buffer alive and continue alertable waits until the completion routine records completion before asserting the timeout. [Microsoft’s cancellation contract](https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-cancelioex) says cancellation does not itself wait for I/O completion. AI use: Codex (GPT-6.2 Sol) checked the test lifetime paths and drafted this follow-up.
Elytes commented 2026-11-30 08:34:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Elytes on 2026-11-30T08:34:53Z.


merge-check
base: d52ff48caa
head: e5c2bc6e23
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2881 passed, 1 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll, 1 driver cache needs Developer Mode); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which also fails on the base alone (base lib 2733 passed / 1 failed, same as the merge; this PR's tests are in tests/lazy_file_io.rs: 5 passed)
review: no blocking finding after reading the whole diff (3 files, +341/-1). The five hooks follow hk_read_file's pattern (lazy::ensure on the buffer, then the original). With vfs_hooks.rs reverted to the base and the new tests kept, 4 of the 5 tests fail exactly as the description says (ReadFileEx / ReadFileScatter 998, WriteFile / WriteFileEx 1784) and pass with the hooks; the fifth (invalid segment array) passes either way, as expected for a no-crash test. ensure_segments reads each FILE_SEGMENT_ELEMENT through ReadProcessMemory after committing the array's own lazy page, so a bad array pointer is left to the kernel. Note, not blocking: hk_read_file also reports the read to d3d12x::file_reads::returned (unbuffered reads into graphics memory become known writes); the new ReadFileEx / ReadFileScatter hooks do not. Such reads were not tracked before either, so nothing regresses, but now that they are hooked they could be. No duplicate found (open and merged PRs searched for these calls and for lazy pages in file I/O; #2359 and #1191 commit lazy pages on other paths). thehollowedone's note on the OVERLAPPED / buffer lifetime in the ReadFileEx / WriteFileEx tests' timeout path is valid; test-only, and only when a completion takes over 5 s: not blocking, but worth a follow-up.
performance: WriteFile is now hooked process-wide, so every write (XCL's own logs too) takes the lazy set's read lock; ensure returns at once when the set is empty, else a BTreeSet range lookup (reasoned, not measured). No memory cost beyond committing the lazy pages a call reads or writes.
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.1742, wave32), Intel Core i9-14900KS, 192 GB, Windows 11 build 26300.10075, rustc 1.100.1, debug / Claude Code (Claude Opus 5.5) ran the merge, build, suite, the base run and the run without the hooks, searched for duplicates and reviewed the diff.

<!-- greyfinch-sync:ivall/xcl:comment:7273083559 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1355#issuecomment-7273083559). Originally posted by [Elytes](https://github.com/Elytes) on 2026-11-30T08:34:53Z. --- merge-check base: d52ff48caade1f5350d513bfffd370396dadfeb6 head: e5c2bc6e23664e79579fabb31cbbe1cb386c8b44 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2881 passed, 1 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll, 1 driver cache needs Developer Mode); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which also fails on the base alone (base lib 2733 passed / 1 failed, same as the merge; this PR's tests are in tests/lazy_file_io.rs: 5 passed) review: no blocking finding after reading the whole diff (3 files, +341/-1). The five hooks follow hk_read_file's pattern (lazy::ensure on the buffer, then the original). With vfs_hooks.rs reverted to the base and the new tests kept, 4 of the 5 tests fail exactly as the description says (ReadFileEx / ReadFileScatter 998, WriteFile / WriteFileEx 1784) and pass with the hooks; the fifth (invalid segment array) passes either way, as expected for a no-crash test. ensure_segments reads each FILE_SEGMENT_ELEMENT through ReadProcessMemory after committing the array's own lazy page, so a bad array pointer is left to the kernel. Note, not blocking: hk_read_file also reports the read to d3d12x::file_reads::returned (unbuffered reads into graphics memory become known writes); the new ReadFileEx / ReadFileScatter hooks do not. Such reads were not tracked before either, so nothing regresses, but now that they are hooked they could be. No duplicate found (open and merged PRs searched for these calls and for lazy pages in file I/O; #2359 and #1191 commit lazy pages on other paths). thehollowedone's note on the OVERLAPPED / buffer lifetime in the ReadFileEx / WriteFileEx tests' timeout path is valid; test-only, and only when a completion takes over 5 s: not blocking, but worth a follow-up. performance: WriteFile is now hooked process-wide, so every write (XCL's own logs too) takes the lazy set's read lock; ensure returns at once when the set is empty, else a BTreeSet range lookup (reasoned, not measured). No memory cost beyond committing the lazy pages a call reads or writes. verdict: safe to merge hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.1742, wave32), Intel Core i9-14900KS, 192 GB, Windows 11 build 26300.10075, rustc 1.100.1, debug / Claude Code (Claude Opus 5.5) ran the merge, build, suite, the base run and the run without the hooks, searched for duplicates and reviewed the diff.
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!1345
No description provided.