actually, reentrant uninitialized mutex acquisition is outright UB
This commit is contained in:
parent
ab3e4a2789
commit
645388583c
7 changed files with 15 additions and 21 deletions
|
|
@ -29,9 +29,8 @@ impl<T: Send + Sync + 'static> Lazy<T> {
|
|||
/// Safety: `init` must not call `get` on the variable that is being
|
||||
/// initialized.
|
||||
pub const unsafe fn new(init: fn() -> Arc<T>) -> Lazy<T> {
|
||||
// `lock` is never initialized fully, so this mutex is reentrant!
|
||||
// Do not use it in a way that might be reentrant, that could lead to
|
||||
// aliasing `&mut`.
|
||||
// `lock` is never initialized fully, so it is UB to attempt to
|
||||
// acquire this mutex reentrantly!
|
||||
Lazy {
|
||||
lock: Mutex::new(),
|
||||
ptr: Cell::new(ptr::null_mut()),
|
||||
|
|
|
|||
|
|
@ -80,9 +80,8 @@ mod imp {
|
|||
|
||||
static mut ARGC: isize = 0;
|
||||
static mut ARGV: *const *const u8 = ptr::null();
|
||||
// `ENV_LOCK` is never initialized fully, so this mutex is reentrant!
|
||||
// Do not use it in a way that might be reentrant, that could lead to
|
||||
// aliasing `&mut`.
|
||||
// `ENV_LOCK` is never initialized fully, so it is UB to attempt to
|
||||
// acquire this mutex reentrantly!
|
||||
static LOCK: Mutex = Mutex::new();
|
||||
|
||||
pub unsafe fn init(argc: isize, argv: *const *const u8) {
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ use sys::fd;
|
|||
use vec;
|
||||
|
||||
const TMPBUF_SZ: usize = 128;
|
||||
// `ENV_LOCK` is never initialized fully, so this mutex is reentrant!
|
||||
// Do not use it in a way that might be reentrant, that could lead to
|
||||
// aliasing `&mut`.
|
||||
// `ENV_LOCK` is never initialized fully, so it is UB to attempt to
|
||||
// acquire this mutex reentrantly!
|
||||
static ENV_LOCK: Mutex = Mutex::new();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ type Queue = Vec<Box<dyn FnBox()>>;
|
|||
// on poisoning and this module needs to operate at a lower level than requiring
|
||||
// the thread infrastructure to be in place (useful on the borders of
|
||||
// initialization/destruction).
|
||||
// `LOCK` is never initialized fully, so this mutex is reentrant!
|
||||
// Do not use it in a way that might be reentrant, that could lead to
|
||||
// aliasing `&mut`.
|
||||
// `LOCK` is never initialized fully, so it is UB to attempt to
|
||||
// acquire this mutex reentrantly!
|
||||
static LOCK: Mutex = Mutex::new();
|
||||
static mut QUEUE: *mut Queue = ptr::null_mut();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ impl Mutex {
|
|||
///
|
||||
/// Behavior is undefined if the mutex is moved after it is
|
||||
/// first used with any of the functions below.
|
||||
/// Also, the mutex might not be fully functional without calling
|
||||
/// `init`! For example, on unix, the mutex is reentrant
|
||||
/// until `init` reconfigures it appropriately.
|
||||
/// Also, until `init` is called, behavior is undefined if this
|
||||
/// mutex is ever used reentrantly, i.e., `raw_lock` or `try_lock`
|
||||
/// are called by the thread currently holding the lock.
|
||||
pub const fn new() -> Mutex { Mutex(imp::Mutex::new()) }
|
||||
|
||||
/// Prepare the mutex for use.
|
||||
|
|
|
|||
|
|
@ -161,9 +161,8 @@ impl StaticKey {
|
|||
// Additionally a 0-index of a tls key hasn't been seen on windows, so
|
||||
// we just simplify the whole branch.
|
||||
if imp::requires_synchronized_create() {
|
||||
// `INIT_LOCK` is never initialized fully, so this mutex is reentrant!
|
||||
// Do not use it in a way that might be reentrant, that could lead to
|
||||
// aliasing `&mut`.
|
||||
// `INIT_LOCK` is never initialized fully, so it is UB to attempt to
|
||||
// acquire this mutex reentrantly!
|
||||
static INIT_LOCK: Mutex = Mutex::new();
|
||||
let _guard = INIT_LOCK.lock();
|
||||
let mut key = self.key.load(Ordering::SeqCst);
|
||||
|
|
|
|||
|
|
@ -940,9 +940,8 @@ pub struct ThreadId(u64);
|
|||
impl ThreadId {
|
||||
// Generate a new unique thread ID.
|
||||
fn new() -> ThreadId {
|
||||
// `GUARD` is never initialized fully, so this mutex is reentrant!
|
||||
// Do not use it in a way that might be reentrant, that could lead to
|
||||
// aliasing `&mut`.
|
||||
// `GUARD` is never initialized fully, so it is UB to attempt to
|
||||
// acquire this mutex reentrantly!
|
||||
static GUARD: mutex::Mutex = mutex::Mutex::new();
|
||||
static mut COUNTER: u64 = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue