2022-07-10 19:19:41 -05:00
|
|
|
// We want to control preemption here.
|
|
|
|
//@compile-flags: -Zmiri-preemption-rate=0
|
2022-07-17 20:54:10 -05:00
|
|
|
//@ignore-target-windows: Concurrency on Windows is not supported yet.
|
2020-12-07 12:16:06 -06:00
|
|
|
|
|
|
|
use std::thread::spawn;
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct EvilSend<T>(pub T);
|
|
|
|
|
|
|
|
unsafe impl<T> Send for EvilSend<T> {}
|
|
|
|
unsafe impl<T> Sync for EvilSend<T> {}
|
|
|
|
|
|
|
|
extern "Rust" {
|
|
|
|
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
|
|
|
|
}
|
|
|
|
pub fn main() {
|
|
|
|
// Shared atomic pointer
|
|
|
|
let pointer: *mut usize = Box::into_raw(Box::new(0usize));
|
|
|
|
let ptr = EvilSend(pointer);
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let j1 = spawn(move || {
|
2022-06-19 22:33:59 -05:00
|
|
|
__rust_dealloc(
|
|
|
|
ptr.0 as *mut _,
|
|
|
|
std::mem::size_of::<usize>(),
|
|
|
|
std::mem::align_of::<usize>(),
|
|
|
|
);
|
2020-12-07 12:16:06 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
let j2 = spawn(move || {
|
2022-07-01 16:33:17 -05:00
|
|
|
// Also an error of the form: Data race detected between Write on thread `<unnamed>` and Deallocate on thread `<unnamed>`
|
2020-12-09 07:35:42 -06:00
|
|
|
// but the invalid allocation is detected first.
|
2022-07-11 06:44:55 -05:00
|
|
|
*ptr.0 = 2; //~ ERROR: dereferenced after this allocation got freed
|
2020-12-07 12:16:06 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
j1.join().unwrap();
|
|
|
|
j2.join().unwrap();
|
|
|
|
}
|
|
|
|
}
|