From 5f670bbfdba199a7537124adaa7ef5b0871e352b Mon Sep 17 00:00:00 2001 From: Duff <19514584+Dufftwt@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:39:39 +0100 Subject: [PATCH] Loader: a trapped unimplemented import goes into the crash log An unimplemented import with the default Trap policy printed its name and aborted. abort() is a fast fail: it skips the exception handlers and the panic hook, which are what append to crashes.log, so the most common bring-up crash left nothing there, not even which import it was. The trap now reports through log_crash, which prints the same line, appends it to the crash log and adds the title's last debug output. --- crates/victory-loader/src/thunks.rs | 46 ++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/crates/victory-loader/src/thunks.rs b/crates/victory-loader/src/thunks.rs index 9dd2796..48a7998 100644 --- a/crates/victory-loader/src/thunks.rs +++ b/crates/victory-loader/src/thunks.rs @@ -62,10 +62,11 @@ extern "system" fn unimplemented_import(site: &'static ImportSite) -> u64 { } UnimplementedPolicy::Trap => { tracing::error!(dll = %site.dll, symbol = %site.symbol, "unimplemented import called"); - eprintln!( - "VIctory: unimplemented import {}!{} called", - site.dll, site.symbol - ); + // Into the crash log too: `abort` ends the process without + // running the handlers that write it. + let (dll, symbol) = (&site.dll, &site.symbol); + let text = format!("VIctory: unimplemented import {dll}!{symbol} called"); + crate::log_crash(&text); // SAFETY: plain Win32 calls without preconditions. unsafe { if IsDebuggerPresent() != 0 { @@ -147,3 +148,40 @@ impl ThunkBlock { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + /// In a child process of the next test: calls an unimplemented import + /// that traps, with the crash log where `VICTORY_TRAP_LOG` says. + #[test] + fn trap_child() { + let Some(log) = std::env::var_os("VICTORY_TRAP_LOG") else { + return; + }; + crate::log_crashes_to(log.into()); + let site = Box::leak(Box::new(ImportSite { + dll: "probe.dll".into(), + symbol: "Missing".into(), + policy: UnimplementedPolicy::Trap, + calls: AtomicU64::new(0), + })); + unimplemented_import(site); + } + + #[test] + fn a_trapped_import_is_in_the_crash_log() { + let dir = tempfile::tempdir().unwrap(); + let log = dir.path().join("crashes.log"); + let out = std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact", "thunks::tests::trap_child", "--nocapture"]) + .env("VICTORY_TRAP_LOG", &log) + .output() + .unwrap(); + assert!(!out.status.success(), "the trap ends the process"); + let text = std::fs::read_to_string(&log).unwrap_or_default(); + let named = text.contains("VIctory: unimplemented import probe.dll!Missing called"); + assert!(named, "crash log: {text:?}"); + } +}