forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#2614 - saethlin:stack-inspection-tools, r=Ral…
…fJung Improve miri_print_borrow_stacks Per post-merge review on rust-lang/miri#2322 * `miri_print_stacks` renamed to `miri_print_borrow_stacks` * A bit more details in docs, clarified how unstable these functions are meant to be * Print an `unknown_bottom` if one exists Open question: Currently `miri_get_alloc_id` gets the expected `AllocId` for `Wildcard` pointers, but for pointers with no provenance, the function reports UB and halts the interpreter. That's definitely wrong. But what _should_ we do? Is it reasonable to check if the pointer has `None` provenance and try to get an `AllocId` for its address? That still leaves us with a failure path, which in this case might be best-handled as an ICE? I'm just not sure that changing the return type of `miri_get_alloc_id` to `Option` is a win because it complicates all normal uses of this.
- Loading branch information
Showing
5 changed files
with
47 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
//@compile-flags: -Zmiri-permissive-provenance | ||
#![feature(strict_provenance)] | ||
use std::{ | ||
alloc::{self, Layout}, | ||
mem::ManuallyDrop, | ||
}; | ||
|
||
extern "Rust" { | ||
fn miri_get_alloc_id(ptr: *const u8) -> u64; | ||
fn miri_print_stacks(alloc_id: u64); | ||
fn miri_print_borrow_stacks(alloc_id: u64); | ||
} | ||
|
||
fn get_alloc_id(ptr: *const u8) -> u64 { | ||
unsafe { miri_get_alloc_id(ptr) } | ||
} | ||
|
||
fn print_borrow_stacks(alloc_id: u64) { | ||
unsafe { miri_print_borrow_stacks(alloc_id) } | ||
} | ||
|
||
fn main() { | ||
let ptr = unsafe { alloc::alloc(Layout::new::<u8>()) }; | ||
let alloc_id = unsafe { miri_get_alloc_id(ptr) }; | ||
unsafe { miri_print_stacks(alloc_id) }; | ||
let alloc_id = get_alloc_id(ptr); | ||
print_borrow_stacks(alloc_id); | ||
|
||
assert!(!ptr.is_null()); | ||
unsafe { miri_print_stacks(alloc_id) }; | ||
print_borrow_stacks(alloc_id); | ||
|
||
unsafe { *ptr = 42 }; | ||
unsafe { miri_print_stacks(alloc_id) }; | ||
print_borrow_stacks(alloc_id); | ||
|
||
let _b = unsafe { ManuallyDrop::new(Box::from_raw(ptr)) }; | ||
unsafe { miri_print_stacks(alloc_id) }; | ||
print_borrow_stacks(alloc_id); | ||
|
||
let _ptr = unsafe { &*ptr }; | ||
unsafe { miri_print_stacks(alloc_id) }; | ||
print_borrow_stacks(alloc_id); | ||
|
||
// Create an unknown bottom, and print it | ||
let ptr = ptr as usize as *mut u8; | ||
unsafe { | ||
*ptr = 5; | ||
} | ||
print_borrow_stacks(alloc_id); | ||
|
||
unsafe { alloc::dealloc(ptr, Layout::new::<u8>()) }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters