-
Notifications
You must be signed in to change notification settings - Fork 356
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 #1644 - JCTyblaidd:detect_race_with_alloc, r=RalfJung
More tests, fix issue 1643 and detect races with allocation. Fixes #1643 by disabling race detection for V-Table memory, adds race detection between r/w & memory allocation, and adds more tests. ~~There is one unusual result in dealloc_read_race_stack_drop.rs, where the stack variable is read by thread 0 & thread 2 and so reports a race with thread 0, any ideas for the cause of the read on thread 0?~~ Fixed, bug with reporting the index a read race occured in correctly.
- Loading branch information
Showing
34 changed files
with
731 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
a2e29d67c26bdf8f278c98ee02d6cc77a279ed2e | ||
12813159a985d87a98578e05cc39200e4e8c2102 |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ignore-windows: Concurrency on Windows is not supported yet. | ||
|
||
use std::thread::spawn; | ||
use std::ptr::null_mut; | ||
use std::sync::atomic::{Ordering, AtomicPtr}; | ||
use std::mem::MaybeUninit; | ||
|
||
#[derive(Copy, Clone)] | ||
struct EvilSend<T>(pub T); | ||
|
||
unsafe impl<T> Send for EvilSend<T> {} | ||
unsafe impl<T> Sync for EvilSend<T> {} | ||
|
||
pub fn main() { | ||
// Shared atomic pointer | ||
let pointer = AtomicPtr::new(null_mut::<MaybeUninit<usize>>()); | ||
let ptr = EvilSend(&pointer as *const AtomicPtr<MaybeUninit<usize>>); | ||
|
||
// Note: this is scheduler-dependent | ||
// the operations need to occur in | ||
// order, otherwise the allocation is | ||
// not visible to the other-thread to | ||
// detect the race: | ||
// 1. alloc | ||
// 2. write | ||
unsafe { | ||
let j1 = spawn(move || { | ||
// Concurrent allocate the memory. | ||
// Uses relaxed semantics to not generate | ||
// a release sequence. | ||
let pointer = &*ptr.0; | ||
pointer.store(Box::into_raw(Box::new(MaybeUninit::uninit())), Ordering::Relaxed); | ||
}); | ||
|
||
let j2 = spawn(move || { | ||
let pointer = &*ptr.0; | ||
|
||
// Note: could also error due to reading uninitialized memory, but the data-race detector triggers first. | ||
*pointer.load(Ordering::Relaxed) //~ ERROR Data race detected between Read on Thread(id = 2) and Allocate on Thread(id = 1) | ||
}); | ||
|
||
j1.join().unwrap(); | ||
j2.join().unwrap(); | ||
|
||
// Clean up memory, will never be executed | ||
drop(Box::from_raw(pointer.load(Ordering::Relaxed))); | ||
} | ||
} |
Oops, something went wrong.