From 8ae2d3aba0b68a74807cc0a94acb3ac95f35be30 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 27 Aug 2022 00:16:38 -0400 Subject: [PATCH] Pass Miri with -Zmiri-strict-provenance --- src/capture.rs | 9 ++++++++- tests/skip_inner_frames.rs | 1 - tests/smoke.rs | 2 -- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/capture.rs b/src/capture.rs index e0dd9c47..465a3ba0 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -2,6 +2,7 @@ use crate::PrintFmt; use crate::{resolve, resolve_frame, trace, BacktraceFmt, Symbol, SymbolName}; use std::ffi::c_void; use std::fmt; +use std::mem; use std::path::{Path, PathBuf}; use std::prelude::v1::*; @@ -334,7 +335,13 @@ impl BacktraceSymbol { /// This function requires the `std` feature of the `backtrace` crate to be /// enabled, and the `std` feature is enabled by default. pub fn addr(&self) -> Option<*mut c_void> { - self.addr.map(|s| s as *mut c_void) + // To be compatible with strict provenance, we can't cast here. + // The most right thing to do is always store addr as a pointer, + // but that runs into problems with !Send + !Sync. + // In any case, we're never going to dereference this pointer, so + // a hand-written version of ptr::invalid_mut suffices. + self.addr + .map(|s| unsafe { mem::transmute::(s) }) } /// Same as `Symbol::filename` diff --git a/tests/skip_inner_frames.rs b/tests/skip_inner_frames.rs index 8b57bef5..f54c5ed2 100644 --- a/tests/skip_inner_frames.rs +++ b/tests/skip_inner_frames.rs @@ -23,7 +23,6 @@ fn backtrace_new_unresolved_should_start_with_call_site_trace() { assert!(!b.frames().is_empty()); let this_ip = backtrace_new_unresolved_should_start_with_call_site_trace as usize; - println!("this_ip: {:?}", this_ip as *const usize); let frame_ip = b.frames().first().unwrap().symbol_address() as usize; assert_eq!(this_ip, frame_ip); } diff --git a/tests/smoke.rs b/tests/smoke.rs index 683a6f0d..e80bca44 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -290,7 +290,6 @@ fn sp_smoke_test() { }); let sp = frame.sp() as usize; - eprintln!("sp = {:p}", sp as *const u8); if sp == 0 { // If the SP is null, then we don't have an implementation for // getting the SP on this target. Just keep walking the stack, @@ -306,7 +305,6 @@ fn sp_smoke_test() { if is_recursive_stack_references { let r = refs.pop().unwrap(); - eprintln!("ref = {:p}", r as *const u8); if sp != 0 { assert!(r > sp); if let Some(child_ref) = child_ref {