Skip to content

kernelx: delegate current-process VirtualAllocEx/FreeEx/ProtectEx - #1564

Open
hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:kernelx/virtual-alloc-ex-current-process
Open

hajduzsolt wants to merge 1 commit into
xcl-dev:mainfrom
hajduzsolt:kernelx/virtual-alloc-ex-current-process

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Delegates VirtualAllocEx, VirtualFreeEx, and VirtualProtectEx to XCL's VirtualAlloc, VirtualFree, and VirtualProtect when targeting GetCurrentProcess(), fixing console/placeholder/graphics flag stripping and missing placeholder cleanup. Part of #1489.

What is in it

  • crates/xcl/src/hle/kernelx.rs: forward current-process VirtualAllocEx, VirtualFreeEx, and VirtualProtectEx calls to VirtualAlloc, VirtualFree, and VirtualProtect so placeholders (placeholders::alloc / placeholders::free), UMA/sparse VRAM windows, coherent heaps, and GRAPHICS_RESERVATIONS are handled identically to non-Ex calls.
  • crates/xcl/src/hle/kernelx.rs: add unit test virtual_alloc_ex_and_protect_ex_current_process_delegation verifying graphics allocation tracking and placeholder reservation/split through VirtualAllocEx and VirtualFreeEx.

Tested

  • Hardware & toolchain: AMD Radeon RX 9070 XT (driver 32.0.32029.2010), AMD Ryzen 7 9800X3D, Windows 11 10.0.26300.9974, rustc 1.98.1 (48a229cea 2026-09-01), debug (cargo test).
  • cargo test -p xcl --lib hle::kernelx::tests -- --test-threads=2: 30 passed, 0 failed, 1 ignored.
  • cargo test --workspace -- --test-threads=2: 777 passed, 0 failed, 41 ignored (xcl --lib: 728 passed, 0 failed, 21 ignored; integration/e2e suites: 49 passed, 0 failed, 20 ignored).
  • SKIPPED runtime tests: SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows.

Regression run

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 49 48 14
device removals: 0
crashes: 0
peak commit: 20195 MB

PR:

xcl-smoke v1
commit: 48e36e8155f17f2ee935422b3bd9e2180581e575
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1679 (PresentX 1679)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14839 MB

Not tested

  • Cross-process (proc_ != GetCurrentProcess()) calls and NVIDIA / Intel Arc adapters.

AI use

  • Antigravity (Gemini 4 Hydrogen, high): implemented current-process VirtualAllocEx/VirtualFreeEx/VirtualProtectEx delegation, wrote the unit test, ran the test suite, and prepared commit and PR description.

VirtualAllocEx unconditionally forwarded to host mem::VirtualAllocEx, stripping console allocation flags and bypassing placeholders::alloc, UMA, sparse VRAM, coherent heaps, and GRAPHICS_RESERVATIONS. VirtualFreeEx only delegated sparse/UMA/graphics-release calls to VirtualFree, bypassing placeholders::free.

Delegate VirtualAllocEx, VirtualFreeEx, and VirtualProtectEx directly to VirtualAlloc, VirtualFree, and VirtualProtect when targeting GetCurrentProcess().

Part of xcl-dev#1489

Assisted-by: Antigravity (Gemini 4 Hydrogen, high)
@hajduzsolt
hajduzsolt force-pushed the kernelx/virtual-alloc-ex-current-process branch from 468c376 to 48e36e8 Compare November 24, 2026 18:54
@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 19:21
@DavidM1911

Copy link
Copy Markdown
Contributor

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

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

Thanks!

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #1564 at head 48e36e8155f17f2ee935422b3bd9e2180581e575 (1 commit; exact parent & merge-base: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted tests & build (48e36e81)

Command Result
cargo test --release -p xcl --lib virtual_alloc_ex_and_protect_ex_current_process_delegation -- --nocapture (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 831 filtered out × 3 (0.02s, 0.02s, 0.02s, 0 skipped)
cargo test --release -p xcl --lib hle::kernelx:: -- --nocapture (3 consecutive runs) 32 passed; 0 failed; 1 ignored; 799 filtered out × 3 (0.21s, 0.22s, 0.23s, 0 runtime skips; 1 pre-existing #[ignore] timing test scatter_timing)
cargo build --release -p xcl Clean build (1m 22s, exit 0, 0 new warnings in kernelx.rs)

Paired quiet 60 s retail smoke (title: 29640639)

(Note: scripts/smoke.ps1 at c160d86e predates 9683e7a6 and printed the local folder basename on title:; replaced below with the standard 9683e7a6 title hash 29640639, with all measured fields verbatim.)

Exact parent & merge-base (c160d86ef2efe3a07e4dfb473e4fa72eafb413c0):

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1533 (PresentX 1533)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14721 MB

PR #1564 (48e36e8155f17f2ee935422b3bd9e2180581e575):

xcl-smoke v1
commit: 48e36e8155f17f2ee935422b3bd9e2180581e575
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1571 (PresentX 1571)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14715 MB

Limits of coverage

  • virtual_alloc_ex_and_protect_ex_current_process_delegation and the full hle::kernelx:: suite (32/32 active tests, 0 runtime skips) passed 3/3 on Windows 11, directly covering current-process VirtualAllocEx / VirtualFreeEx / VirtualProtectEx delegation.
  • The 60 s retail smoke confirms steady 60 Hz runtime non-regression (0 device removals, 0 crashes); single-run frame/commit delta vs. parent reflects normal startup variance.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

@futurepro62

Copy link
Copy Markdown

NVIDIA and AMD full-suite run, to go with the reports above by Decodere, since none of them covers AMD. Tested exact head 48e36e81 (on its base c160d86).

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 --no-fail-fast -- --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: 858 passed, 0 failed, 42 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: virtual_alloc_ex_and_protect_ex_current_process_delegation.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace --no-fail-fast -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 859 passed, 0 failed, 42 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 6089122a too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #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.

@ClosetPie107

Copy link
Copy Markdown

Tested on AMD / Linux: 48e36e81 (RX 9070 16 GB, RDNA4, Mesa 26.3.1 RADV; Ryzen 5 9600X, 32 GB; CachyOS; Proton Experimental experimental-11.0-20261112 with vkd3d-proton master ec207194 plus a local patch dropping the lpVtbl checks of command allocators and lists; DXC 1.9.2609.5; Rust 1.96.0, x86_64-pc-windows-gnu debug build, tests run under Wine)

The head as it is (not merged onto current main), with its base c160d86e the same session as the baseline.

Tests (XCL_REQUIRE_GPU=wave64)

  • cargo test -p xcl --lib -- hle::kernelx:: --test-threads=1: 32 passed, 0 failed, 1 ignored (includes virtual_alloc_ex_and_protect_ex_current_process_delegation).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 with --skip compositor_blends_ui_plane_over_scene_plane --skip failed_restore_stops_before_importing_an_unbacked_window --skip grooming_leaves_a_window_under_1_gib_only_its_hole (the first loses the RADV device here, the other two run out of memory under Wine): lib 796 passed, 14 failed, 22 ignored; base c160d86e lib (same flags): 795 passed, 14 failed, 22 ignored, the same 14. The other binaries fail the same 3 tests as on main here (e2e, pls_quota, predication_e2e).

Not tested

  • A retail title
  • Native Windows, NVIDIA / Intel

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the builds and tests on my machine and wrote this report.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head 48e36e8

Most of this is on main already: commit a078094 makes VirtualAllocEx for the own process call VirtualAlloc (own_process, which also matches handles by process ID), and VirtualProtectEx for the own process does what VirtualProtect does. #1796 (D91, closed) made only the VirtualAllocEx part.
What is still not on main is the unconditional VirtualFreeEx -> VirtualFree for the own process. Main still sends non-UMA, non-sparse addresses to mem::VirtualFreeEx, which skips placeholders::free.
On rebase, keep only the VirtualFreeEx change, use own_process instead of == GetCurrentProcess(), and keep the placeholder part of the test.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants