From 12be9306269772e1e24aa1e44219f2bce684c193 Mon Sep 17 00:00:00 2001 From: mirski <66262518+13hourstilliland@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:37:42 +0000 Subject: [PATCH] Memory: link xcl.exe without high-entropy ASLR so title memory stays under 2^40 A retail title's XboxBvhBuilder refuses an acceleration structure whose GPU address has a bit at or above 40 set (#585: "DestAccelerationStructureData can not have more than 40b of address set", then 0xe06d7363). The failing addresses reported there are about 2.06 TiB, in write-watched title reservations that go through VirtualAlloc(NULL). Root cause: Rust links xcl.exe with high-entropy VA on, and with it Windows puts a process's bottom-up allocations (heaps, stacks, VirtualAlloc(NULL)) around 1-2.5 TiB. Measured on Windows 11 26200 with a small probe linked both ways: twenty 24 GiB reservations landed at 0x1e1cb8a0000 and up (20/20 above 2^40, three runs); with --disable-high-entropy-va they landed from 0x7fff0000 up (0/20 above 2^40). The title's memory follows, since it lives in xcl.exe's process. build.rs passes /HIGHENTROPYVA:NO (MSVC) or --disable-high-entropy-va (GNU) to the xcl binary only; the library and test binaries are unchanged. tests/low_va.rs checks the flag in xcl.exe's PE header. Not covered: allocations the title asks for with MEM_TOP_DOWN still go to the top of the address space. Assisted-by: Claude Code (Claude Opus 5.5) --- crates/xcl/build.rs | 14 ++++++++++++++ crates/xcl/tests/low_va.rs | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 crates/xcl/build.rs create mode 100644 crates/xcl/tests/low_va.rs diff --git a/crates/xcl/build.rs b/crates/xcl/build.rs new file mode 100644 index 0000000000..eff042ad67 --- /dev/null +++ b/crates/xcl/build.rs @@ -0,0 +1,14 @@ +//! xcl.exe is linked without high-entropy ASLR. With it, Windows places a process's bottom-up +//! allocations (heaps, stacks, `VirtualAlloc(NULL)`) around 1–2.5 TiB, above 2^40; the title's +//! memory lands there too, and a retail game's XboxBvhBuilder refuses an acceleration structure +//! there ("DestAccelerationStructureData can not have more than 40b of address set", #585). +//! Without it, the same allocations start near 2 GiB, as console addresses do. + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + match std::env::var("CARGO_CFG_TARGET_ENV").as_deref() { + Ok("msvc") => println!("cargo:rustc-link-arg-bin=xcl=/HIGHENTROPYVA:NO"), + Ok("gnu") => println!("cargo:rustc-link-arg-bin=xcl=-Wl,--disable-high-entropy-va"), + _ => {} + } +} diff --git a/crates/xcl/tests/low_va.rs b/crates/xcl/tests/low_va.rs new file mode 100644 index 0000000000..fffcb54e52 --- /dev/null +++ b/crates/xcl/tests/low_va.rs @@ -0,0 +1,16 @@ +//! xcl.exe opts out of high-entropy ASLR, so the title's memory stays below 2^40 (#585). + +/// IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA +const HIGH_ENTROPY_VA: u16 = 0x20; + +#[test] +fn xcl_exe_is_linked_without_high_entropy_va() { + let image = std::fs::read(env!("CARGO_BIN_EXE_xcl")).unwrap(); + let pe = u32::from_le_bytes(image[0x3c..0x40].try_into().unwrap()) as usize; + assert_eq!(&image[pe..pe + 4], b"PE\0\0"); + let optional = pe + 24; + assert_eq!(u16::from_le_bytes(image[optional..optional + 2].try_into().unwrap()), 0x20b, "PE32+"); + // DllCharacteristics is at +70 of the PE32+ optional header + let flags = u16::from_le_bytes(image[optional + 70..optional + 72].try_into().unwrap()); + assert_eq!(flags & HIGH_ENTROPY_VA, 0, "DllCharacteristics {flags:#x}: high-entropy VA is on"); +}