Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/xcl/build.rs
Original file line number Diff line number Diff line change
@@ -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"),
_ => {}
}
}
16 changes: 16 additions & 0 deletions crates/xcl/tests/low_va.rs
Original file line number Diff line number Diff line change
@@ -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");
}
Loading