Prechádzať zdrojové kódy

Report Windows commit-limit failures in crashes.log

BaggyALPHA 3 dní pred
rodič
commit
7e42fefebc
2 zmenil súbory, kde vykonal 68 pridanie a 10 odobranie
  1. 5 0
      README.md
  2. 63 10
      crates/victory-hle/src/modules/xmem.rs

+ 5 - 0
README.md

@@ -50,6 +50,11 @@ Requirements: Windows 10/11 x64, a CPU with AVX2, a Direct3D 12 GPU with
 shader model 6.6 (and mesh shaders for the world), Rust (pinned in
 `rust-toolchain.toml`).
 
+The title also needs several GiB of available Windows commit at startup.
+Check **Committed** under **Task Manager → Performance → Memory**. If
+`crashes.log` reports Windows error 1455, close other applications or increase
+the Windows paging file size, then retry.
+
 ```powershell
 cargo xtask install-hooks                # asset-policy check on every commit
 copy victory.example.toml victory.toml   # then set your paths (outside the repo)

+ 63 - 10
crates/victory-hle/src/modules/xmem.rs

@@ -13,7 +13,9 @@ use std::ffi::c_void;
 use std::sync::atomic::{AtomicUsize, Ordering};
 use std::sync::{Arc, LazyLock, Mutex, MutexGuard};
 
-use windows_sys::Win32::Foundation::{CloseHandle, HANDLE, INVALID_HANDLE_VALUE};
+use windows_sys::Win32::Foundation::{
+    CloseHandle, ERROR_COMMITMENT_LIMIT, HANDLE, INVALID_HANDLE_VALUE,
+};
 use windows_sys::Win32::System::Memory::{
     CreateFileMappingW, MEM_ADDRESS_REQUIREMENTS, MEM_COMMIT, MEM_EXTENDED_PARAMETER,
     MEM_PRESERVE_PLACEHOLDER, MEM_RELEASE, MEM_REPLACE_PLACEHOLDER, MEM_RESERVE,
@@ -21,7 +23,10 @@ use windows_sys::Win32::System::Memory::{
     MemExtendedParameterAddressRequirements, PAGE_NOACCESS, PAGE_READWRITE, SEC_RESERVE,
     UnmapViewOfFile2, VirtualAlloc, VirtualAlloc2, VirtualFree, VirtualQueryEx,
 };
-use windows_sys::Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
+use windows_sys::Win32::System::ProcessStatus::{
+    K32GetPerformanceInfo, K32GetProcessMemoryInfo, PERFORMANCE_INFORMATION,
+    PROCESS_MEMORY_COUNTERS,
+};
 use windows_sys::Win32::System::Threading::GetCurrentProcess;
 use windows_sys::core::BOOL;
 
@@ -636,16 +641,44 @@ fn map(physical: &mut Physical, base: usize, len: usize, slice: Slice) -> bool {
 /// Commits the section pages a view shows (once per page, whichever view).
 fn commit(base: usize, len: usize) -> bool {
     // SAFETY: `[base, base + len)` is a view of a reserved section.
-    let done =
-        !unsafe { VirtualAlloc(base as *const c_void, len, MEM_COMMIT, PAGE_READWRITE) }.is_null();
-    if !done {
-        tracing::warn!(
-            len,
-            error = %std::io::Error::last_os_error(),
-            "committing physical pages failed"
+    if !unsafe { VirtualAlloc(base as *const c_void, len, MEM_COMMIT, PAGE_READWRITE) }.is_null() {
+        return true;
+    }
+    let error = std::io::Error::last_os_error();
+    if error.raw_os_error() == Some(ERROR_COMMITMENT_LIMIT as i32) {
+        let mut info = PERFORMANCE_INFORMATION::default();
+        info.cb = size_of::<PERFORMANCE_INFORMATION>() as u32;
+        // SAFETY: the buffer and size describe a writable PERFORMANCE_INFORMATION.
+        let queried = unsafe { K32GetPerformanceInfo(&mut info, info.cb) } != 0;
+        victory_loader::log_crash(&commit_limit_message(len, &error, queried.then_some(&info)));
+    } else {
+        tracing::warn!(len, %error, "committing physical pages failed");
+    }
+    false
+}
+
+fn commit_limit_message(
+    len: usize,
+    error: &std::io::Error,
+    info: Option<&PERFORMANCE_INFORMATION>,
+) -> String {
+    let mut message = format!(
+        "VIctory: Windows commit limit reached while committing {len} bytes of physical pages: {error}.\n"
+    );
+    if let Some(info) = info {
+        use std::fmt::Write;
+
+        let committed = info.CommitTotal * info.PageSize / MIB;
+        let limit = info.CommitLimit * info.PageSize / MIB;
+        let _ = writeln!(
+            message,
+            "System commit: {committed} MiB of {limit} MiB in use."
         );
     }
-    done
+    message.push_str(
+        "Close other applications or increase the Windows paging file size, then retry.\n",
+    );
+    message
 }
 
 /// Returns `[base, base + len)` to placeholders; views reaching past it
@@ -877,6 +910,26 @@ mod tests {
         assert_eq!(std::mem::offset_of!(WorkingSet, gpu_optimal_limit), 0x28);
     }
 
+    #[test]
+    fn commit_limit_report_includes_request_and_system_commit() {
+        let error = std::io::Error::from_raw_os_error(ERROR_COMMITMENT_LIMIT as i32);
+        let info = PERFORMANCE_INFORMATION {
+            CommitTotal: 512,
+            CommitLimit: 768,
+            PageSize: 4096,
+            ..Default::default()
+        };
+        let report = commit_limit_message(4 * MIB, &error, Some(&info));
+        assert!(report.contains("4194304 bytes"));
+        assert!(report.contains("2 MiB of 3 MiB in use"));
+        let fallback = commit_limit_message(4 * MIB, &error, None);
+        for report in [&report, &fallback] {
+            assert!(report.contains("os error 1455"));
+            assert!(report.contains("Windows paging file size"));
+        }
+        assert!(!fallback.contains("System commit:"));
+    }
+
     #[test]
     fn physical_pages_map_alias_and_unmap() {
         let mut pages = [0usize; 3];