|
|
@@ -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:?}");
|
|
|
+ }
|
|
|
+}
|