From 608a79b2fae74f9f49c33163e4790f98227a71bc Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 17:42:56 +0000 Subject: [PATCH 1/6] kernelx: memory in use from PagefileUsage where PrivateUsage is 0 Wine's GetProcessMemoryInfo fills PROCESS_MEMORY_COUNTERS only, PrivateUsage of the _EX form stays 0: TitleMemoryStatus reported the whole budget as available and XMemGetWorkingSetStatistics a use of 0 (the test title's check wants more than 0). PagefileUsage is the same number on Windows, where PrivateUsage is never 0: no change there. Co-Authored-By: Claude Mythos 5.2 Claude-Session: https://claude.ai/code/session_019twRmXSjLgBbFAokwc63ad --- crates/xcl/src/hle/kernelx.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/kernelx.rs b/crates/xcl/src/hle/kernelx.rs index 0b8f2a3f..aac17bcf 100644 --- a/crates/xcl/src/hle/kernelx.rs +++ b/crates/xcl/src/hle/kernelx.rs @@ -643,7 +643,9 @@ fn process_private_bytes() -> u64 { let mut c: PROCESS_MEMORY_COUNTERS_EX = std::mem::zeroed(); c.cb = std::mem::size_of::() as u32; if K32GetProcessMemoryInfo(thr::GetCurrentProcess(), &mut c as *mut _ as *mut _, c.cb) != 0 { - c.PrivateUsage as u64 + // Wine fills the fields before PrivateUsage only; PagefileUsage is the same number + // on Windows (the commit charge) + if c.PrivateUsage != 0 { c.PrivateUsage as u64 } else { c.PagefileUsage as u64 } } else { 0 } @@ -1871,6 +1873,8 @@ mod tests { assert_eq!(unsafe { TitleMemoryStatus(&mut s) }, 1); assert_eq!(s.total, 13_824 * 1024 * 1024); assert!(s.avail <= s.total); + // the process's own memory counts as used (Wine leaves PrivateUsage 0) + assert!(process_private_bytes() > 0 && s.avail < s.total); s.dw_length = 8; assert_eq!(unsafe { TitleMemoryStatus(&mut s) }, 0); } From c858190dde5bbf1ba8559c5d4deecb26347f72b8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 17:43:10 +0000 Subject: [PATCH 2/6] testgame-mw: no unit-test harness The crate has no tests, and with the GNU toolchain (x86_64-pc-windows-gnu) the empty harness keeps the raw-dylib import of kernelx.dll: the exe cannot start and `cargo test --workspace` fails on it (the MSVC linker drops the unused import). The DLL itself is built by `cargo build --workspace` as before. Co-Authored-By: Claude Mythos 5.2 Claude-Session: https://claude.ai/code/session_019twRmXSjLgBbFAokwc63ad --- tests/testgamedll/Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/testgamedll/Cargo.toml b/tests/testgamedll/Cargo.toml index 6264862c..379c3fa0 100644 --- a/tests/testgamedll/Cargo.toml +++ b/tests/testgamedll/Cargo.toml @@ -10,3 +10,6 @@ publish = false name = "testgame_mw" crate-type = ["cdylib"] path = "src/lib.rs" +# no unit tests: the GNU linker keeps the kernelx.dll import in the test harness's exe, +# which then does not start (kernelx.dll exists only inside XCL) +test = false From 1775ebb3856a4369338632102fced7744d5e8f73 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 19:13:02 +0000 Subject: [PATCH 3/6] d3d12x null device: descriptor heap start handles in rax Console code calls descriptor heap #9 / #10 (GetCPU / GetGPUDescriptorHandleForHeapStart) with only `this` and takes the handle in rax, as the real backend already answers it (real.rs heap_cpu_start_x). The null device used the PC form and wrote the handle through rdx, whatever the caller had left there. Under Wine 11.22 with no D3D12 device (no GPU), the test title runs its GPU checks on the null device: its rdx pointed into its read-only .rdata and the title ended with 0xC0000005 in Heap_GetHandleStart (where rdx happens to be writable, the stray write goes unnoticed). The handle now comes back in rax and rdx is not touched. Windows: the same for the null device (no D3D12 device or graphics = "null"); the real backend is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019twRmXSjLgBbFAokwc63ad --- crates/xcl/src/hle/d3d12x/null.rs | 34 ++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/null.rs b/crates/xcl/src/hle/d3d12x/null.rs index bfaeb604..818a22a5 100644 --- a/crates/xcl/src/hle/d3d12x/null.rs +++ b/crates/xcl/src/hle/d3d12x/null.rs @@ -616,11 +616,11 @@ unsafe extern "system" fn Heap_GetDesc16(this: *mut NullObj, ret: *mut u8) -> *m } ret } -unsafe extern "system" fn Heap_GetHandleStart(this: *mut NullObj, ret: *mut u64) -> *mut u64 { - if !ret.is_null() { - *ret = (*this).value.load(Ordering::Relaxed); - } - ret +/// #9 / #10 GetCPU / GetGPUDescriptorHandleForHeapStart: console code takes the handle in rax +/// and passes only `this` (as `real::heap_cpu_start_x`); rdx holds whatever the caller left +/// there, so it must not be written through as the PC's hidden return pointer. +unsafe extern "system" fn Heap_GetHandleStart(this: *mut NullObj) -> u64 { + (*this).value.load(Ordering::Relaxed) } unsafe extern "system" fn Resource_Map(this: *mut NullObj, _sub: u32, _range: *const c_void, data: *mut *mut c_void) -> HRESULT { let mut g = (*this).mem.lock().unwrap(); @@ -792,4 +792,28 @@ mod tests { assert!(crate::stubs::all_stubs().iter().any(|s| s.name == "ID3D12Device::#200" && s.calls.load(Ordering::Relaxed) > 0)); } } + + /// Console code calls descriptor heap #9 / #10 with only `this` and takes the start in rax; + /// rdx is left over from the caller and must not be written (the test title's rdx pointed + /// into its read-only .rdata: an access violation under Wine on the null device). + #[test] + fn heap_start_handles_come_back_in_rax() { + unsafe { + let mut dev = std::ptr::null_mut(); + assert_eq!(D3D12CreateDevice(std::ptr::null_mut(), 0xC100, std::ptr::null(), &mut dev), S_OK); + let desc = [0u32, 16, 1, 0]; // CBV_SRV_UAV, 16 slots, shader visible + let create_heap: Fn4 = std::mem::transmute(slot(dev, 14)); + let mut h = std::ptr::null_mut(); + assert_eq!(create_heap(dev, desc.as_ptr() as *const c_void, std::ptr::null(), &mut h), S_OK); + for i in [9, 10] { + // a caller that passes only `this`, with a stray pointer left in rdx + let start: unsafe extern "system" fn(*mut c_void, *mut u64) -> u64 = std::mem::transmute(slot(h, i)); + let mut stray = 0x5A5A_5A5Au64; + let p = start(h, &mut stray); + assert_eq!(stray, 0x5A5A_5A5A, "slot {i} wrote through rdx"); + assert_ne!(p, 0, "slot {i}"); + assert_ne!(p, &mut stray as *mut u64 as u64, "slot {i} returned rdx"); + } + } + } } From 8adb9ddd37aac7c0c837dea563967851d9e29412 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 21:45:54 +0000 Subject: [PATCH 4/6] xgameruntime: say what is missing without System32\xgameruntime.dll The preflight warning said task queues and networking are missing without the PC's XGameRuntime, and the runtime log line said XTaskQueue/XAsync are unavailable. XCL uses its own XAsync / XTaskQueue / XThread then (QueryApiImpl fallback), and XNetworking is always XCL's. What is missing is what goes to the PC runtime: the XGameUi dialogs and text entry, game invites, game streaming and the other classes XCL does not implement. The module doc said XNetworking goes to the PC runtime and did not say what happens without it; it now says both. Seen under Wine, which has no xgameruntime.dll: the warning is printed on every run. Wording and comments only, the levels are unchanged. Windows: the same text where Gaming Services is not installed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019twRmXSjLgBbFAokwc63ad --- crates/xcl/src/hle/xgameruntime/api.rs | 9 +++++---- crates/xcl/src/preflight.rs | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/xcl/src/hle/xgameruntime/api.rs b/crates/xcl/src/hle/xgameruntime/api.rs index 87d8719f..13406406 100644 --- a/crates/xcl/src/hle/xgameruntime/api.rs +++ b/crates/xcl/src/hle/xgameruntime/api.rs @@ -11,9 +11,10 @@ //! dropped), the XGameUi dialogs that do not take a user –, refuses XStore, app broadcast and //! app capture (the thunk then returns its "API not available" error), and passes everything //! else to the PC's own XGameRuntime (`System32\xgameruntime.dll`: the same classes under the -//! same GUIDs) – XTaskQueue / XAsync, XThread, XNetworking, XGameInvite… Once the PC runtime is -//! in use, the queues and async blocks are its own, so XCL's async APIs run on its XAsync -//! (`xasync::use_pc`). Nothing that takes an XCL user handle goes to the PC runtime: it does not +//! same GUIDs) – XTaskQueue / XAsync, XThread, XGameInvite… (XNetworking is always XCL's). Once +//! the PC runtime is in use, the queues and async blocks are its own, so XCL's async APIs run on +//! its XAsync (`xasync::use_pc`); without `System32\xgameruntime.dll`, XAsync / XTaskQueue / +//! XThread fall back to XCL's own. Nothing that takes an XCL user handle goes to the PC runtime: it does not //! validate foreign handles. //! //! Layout: `gdk_table` (extracted from the public PC GDK's thunk library) gives every @@ -138,7 +139,7 @@ fn pc() -> Option<&'static Pc> { use windows_sys::Win32::System::LibraryLoader::{GetProcAddress, LoadLibraryExW, LOAD_LIBRARY_SEARCH_SYSTEM32}; let h = LoadLibraryExW(crate::util::wide("xgameruntime.dll").as_ptr(), std::ptr::null_mut(), LOAD_LIBRARY_SEARCH_SYSTEM32); if h.is_null() { - crate::xlog_warn!("XGameRuntime: no System32\\xgameruntime.dll (Gaming Services) – XTaskQueue/XAsync and the other APIs XCL does not implement are unavailable"); + crate::xlog_warn!("XGameRuntime: no System32\\xgameruntime.dll (Gaming Services) – XCL's own XTaskQueue/XAsync are used; dialogs, text entry, game invites, game streaming and the other APIs XCL does not implement are unavailable"); return None; } let f = |n: &str| GetProcAddress(h, format!("{n}\0").as_ptr()).map(|p| p as usize); diff --git a/crates/xcl/src/preflight.rs b/crates/xcl/src/preflight.rs index d394d8f1..230a29bf 100644 --- a/crates/xcl/src/preflight.rs +++ b/crates/xcl/src/preflight.rs @@ -91,7 +91,7 @@ pub fn checks(f: &Found) -> Vec { Err(_) => v.push(check(Level::Error, "no DXC (dxcompiler.dll + dxil.dll): no shader can be compiled, the game draws nothing", Some("install the Windows SDK, or put dxcompiler.dll and dxil.dll next to xcl.exe (or in %XCL_DXC_DIR%)"))), } if !f.xgameruntime { - v.push(check(Level::Warning, "no System32\\xgameruntime.dll: XCL's own XGameRuntime parts work, the rest (task queues, networking, dialogs) is missing", Some("install Gaming Services (Microsoft Store)"))); + v.push(check(Level::Warning, "no System32\\xgameruntime.dll: dialogs, text entry, game invites and game streaming are missing (XCL's own task queues, async and networking are used)", Some("install Gaming Services (Microsoft Store)"))); } v } @@ -215,6 +215,9 @@ mod tests { let c = checks(&f); assert_eq!(c.iter().map(|c| c.level).collect::>(), [Level::Ok, Level::Error, Level::Warning, Level::Error, Level::Warning]); assert!(c[1].what.contains("has 6.5"), "{:?}", c[1]); + // XCL's own task queues and networking stand in for the PC runtime's: not missing + let missing = c[4].what.split(" missing").next().unwrap(); + assert!(missing.contains("dialogs") && !missing.contains("task queues") && !missing.contains("networking"), "{:?}", c[4]); assert!(c.iter().filter(|c| c.level != Level::Ok).all(|c| c.fix.is_some()), "{c:?}"); } From d54597ac7d1a4b9ae36cc240bec48ec33cc37a65 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 19:17:02 +0000 Subject: [PATCH 5/6] e2e: stage the test title under CARGO_TARGET_TMPDIR The e2e test staged the game and data folders in /target/e2e whatever the target directory was, so with CARGO_TARGET_DIR set elsewhere it still wrote into the repository: seen under Wine 11.22, where a target/e2e folder appeared in the repository after an e2e run with CARGO_TARGET_DIR pointing to another folder. Cargo hands integration tests a scratch folder inside the target directory, CARGO_TARGET_TMPDIR; the staging is now there (target\tmp\e2e, target\\tmp\e2e with --target). Windows: the same test, the folder moves from target\e2e to target\tmp\e2e. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019twRmXSjLgBbFAokwc63ad --- crates/xcl/tests/e2e.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/xcl/tests/e2e.rs b/crates/xcl/tests/e2e.rs index f3082d27..57301087 100644 --- a/crates/xcl/tests/e2e.rs +++ b/crates/xcl/tests/e2e.rs @@ -97,7 +97,7 @@ fn test_title_runs_and_game_folder_is_untouched() { dll.display() ); let manifest = Path::new(env!("CARGO_MANIFEST_DIR")); - let root = manifest.join("..").join("..").join("target").join("e2e"); + let root = Path::new(env!("CARGO_TARGET_TMPDIR")).join("e2e"); let _ = std::fs::remove_dir_all(&root); let game = root.join("game"); let data = root.join("data"); From 7bdc97f9d2ba7fa6cc791e73e4b246d45bb00626 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 22:47:58 +0000 Subject: [PATCH 6/6] d3d12x null device: heap start test calls #9 / #10 with their real signature The test for descriptor heap #9 / #10 called them through a two-argument fn pointer (`this` plus a stray pointer) although they take only `this`: a Rust call through a fn pointer of another signature is undefined behaviour, even where Win64 lets it pass. Its checks were also weak: a start that is not 0 and not the stray pointer, so #9 / #10 returning the constant 1 still passed. The test now creates two heaps and reads each heap's start from the object (CreateDescriptorHeap's handle range: not 0, a different one per heap), then calls #9 and #10 as `fn(this) -> u64` and wants exactly that start. On x86_64 Windows it also calls them through a small asm shim that passes `this` in rcx and leaves a writable sentinel pointer in rdx, as console code can: the sentinel must be unchanged and rax the exact start. Checked under Wine: #9 / #10 returning 1 fails the test, and so does the old PC form that wrote the handle through rdx. Test only, the null device is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019twRmZMiGWQ8zSxFiGaz6b --- crates/xcl/src/hle/d3d12x/null.rs | 48 ++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/null.rs b/crates/xcl/src/hle/d3d12x/null.rs index 818a22a5..c846a7f6 100644 --- a/crates/xcl/src/hle/d3d12x/null.rs +++ b/crates/xcl/src/hle/d3d12x/null.rs @@ -803,17 +803,45 @@ mod tests { assert_eq!(D3D12CreateDevice(std::ptr::null_mut(), 0xC100, std::ptr::null(), &mut dev), S_OK); let desc = [0u32, 16, 1, 0]; // CBV_SRV_UAV, 16 slots, shader visible let create_heap: Fn4 = std::mem::transmute(slot(dev, 14)); - let mut h = std::ptr::null_mut(); - assert_eq!(create_heap(dev, desc.as_ptr() as *const c_void, std::ptr::null(), &mut h), S_OK); - for i in [9, 10] { - // a caller that passes only `this`, with a stray pointer left in rdx - let start: unsafe extern "system" fn(*mut c_void, *mut u64) -> u64 = std::mem::transmute(slot(h, i)); - let mut stray = 0x5A5A_5A5Au64; - let p = start(h, &mut stray); - assert_eq!(stray, 0x5A5A_5A5A, "slot {i} wrote through rdx"); - assert_ne!(p, 0, "slot {i}"); - assert_ne!(p, &mut stray as *mut u64 as u64, "slot {i} returned rdx"); + let mut heaps = [std::ptr::null_mut(); 2]; + for h in &mut heaps { + assert_eq!(create_heap(dev, desc.as_ptr() as *const c_void, std::ptr::null(), h), S_OK); + } + // the start is the heap's own handle range (CreateDescriptorHeap): not 0, one per heap + let base = heaps.map(|h| (*(h as *mut NullObj)).value.load(Ordering::Relaxed)); + assert_ne!(base[0], 0); + assert_ne!(base[0], base[1]); + for (h, base) in heaps.into_iter().zip(base) { + for i in [9, 10] { + #[cfg(all(target_arch = "x86_64", windows))] + { + let mut sentinel = 0x5A5A_5A5A_5A5A_5A5Au64; + let p = call_with_rdx(slot(h, i), h, &mut sentinel); + assert_eq!(sentinel, 0x5A5A_5A5A_5A5A_5A5A, "slot {i} wrote through rdx"); + assert_eq!(p, base, "slot {i} with rdx set"); + } + let start: unsafe extern "system" fn(*mut c_void) -> u64 = std::mem::transmute(slot(h, i)); + assert_eq!(start(h), base, "slot {i}"); + } } } } + + /// Calls `f(this)` (Win64) the way console code does, with a writable pointer left in rdx. + #[cfg(all(target_arch = "x86_64", windows))] + unsafe fn call_with_rdx(f: usize, this: *mut c_void, rdx: *mut u64) -> u64 { + let ret: u64; + // rsp is 16-aligned on entry to the asm block: 32 B of shadow space keep it so at the call + core::arch::asm!( + "sub rsp, 32", + "call {f}", + "add rsp, 32", + f = in(reg) f, + in("rcx") this, + in("rdx") rdx, + lateout("rax") ret, + clobber_abi("system"), + ); + ret + } }