Skip to content

Commit

Permalink
Update functions for Miri changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Sep 24, 2020
1 parent 085ee70 commit fa5b936
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/backtrace/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::vec::Vec;
use std::boxed::Box;

extern "Rust" {
fn miri_get_backtrace() -> Box<[*mut ()]>;
fn miri_resolve_frame(version: u8, ptr: *mut ()) -> MiriFrame;
fn miri_get_backtrace(flags: u64) -> Box<[*mut ()]>;
fn miri_resolve_frame(ptr: *mut (), flags: u64) -> MiriFrame;
}

#[derive(Debug)]
Expand All @@ -27,9 +27,8 @@ pub struct Frame {
pub inner: MiriFrame
}

// Miri is single threaded, and the raw
// pointer isn't really a pointer (it's a magic value
// returned by Miri)
// SAFETY: Miri guarantees that the returned pointer
// can be used from any thread.
unsafe impl Send for Frame {}
unsafe impl Sync for Frame {}

Expand All @@ -52,21 +51,22 @@ impl Frame {
}

pub fn trace<F: FnMut(&super::Frame) -> bool>(cb: F) {
// Miri is single threaded
// SAFETY: Miri guarnatees that the backtrace API functions
// can be called from any thread.
unsafe { trace_unsynchronized(cb) };
}


pub fn resolve_addr(ptr: *mut c_void) -> Frame {
let frame: MiriFrame = unsafe { miri_resolve_frame(0, ptr as *mut ()) };
let frame: MiriFrame = unsafe { miri_resolve_frame(ptr as *mut (), 0) };
Frame {
addr: ptr,
inner: frame
}
}

pub unsafe fn trace_unsynchronized<F: FnMut(&super::Frame) -> bool>(mut cb: F) {
let frames = miri_get_backtrace();
let frames = miri_get_backtrace(0);
for ptr in frames.iter() {
let frame = resolve_addr(*ptr as *mut c_void);
cb(&super::Frame {
Expand Down

0 comments on commit fa5b936

Please sign in to comment.