about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-08-06 14:39:55 +0200
committerRalf Jung <post@ralfj.de>2018-08-06 14:39:55 +0200
commit645388583ca47357a6a2e5878a9cde84e2e579d3 (patch)
treeb540ad370e3d571608473073de8de219bda2aff9 /src
parentab3e4a27894295ec0fca28b492450f2b22fbad4e (diff)
downloadrust-645388583ca47357a6a2e5878a9cde84e2e579d3.tar.gz
rust-645388583ca47357a6a2e5878a9cde84e2e579d3.zip
actually, reentrant uninitialized mutex acquisition is outright UB
Diffstat (limited to 'src')
-rw-r--r--src/libstd/io/lazy.rs5
-rw-r--r--src/libstd/sys/unix/args.rs5
-rw-r--r--src/libstd/sys/unix/os.rs5
-rw-r--r--src/libstd/sys_common/at_exit_imp.rs5
-rw-r--r--src/libstd/sys_common/mutex.rs6
-rw-r--r--src/libstd/sys_common/thread_local.rs5
-rw-r--r--src/libstd/thread/mod.rs5
7 files changed, 15 insertions, 21 deletions
diff --git a/src/libstd/io/lazy.rs b/src/libstd/io/lazy.rs
index 9513cc7fb2d..5743ea51af3 100644
--- a/src/libstd/io/lazy.rs
+++ b/src/libstd/io/lazy.rs
@@ -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()),
diff --git a/src/libstd/sys/unix/args.rs b/src/libstd/sys/unix/args.rs
index c91bd5b22af..220bd11b1f1 100644
--- a/src/libstd/sys/unix/args.rs
+++ b/src/libstd/sys/unix/args.rs
@@ -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) {
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index 6ef9502ba62..3d98b2efdf1 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -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();
 
 
diff --git a/src/libstd/sys_common/at_exit_imp.rs b/src/libstd/sys_common/at_exit_imp.rs
index 30019088eb6..85679837312 100644
--- a/src/libstd/sys_common/at_exit_imp.rs
+++ b/src/libstd/sys_common/at_exit_imp.rs
@@ -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();
 
diff --git a/src/libstd/sys_common/mutex.rs b/src/libstd/sys_common/mutex.rs
index a4efe4d128e..74e1defd9f4 100644
--- a/src/libstd/sys_common/mutex.rs
+++ b/src/libstd/sys_common/mutex.rs
@@ -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.
diff --git a/src/libstd/sys_common/thread_local.rs b/src/libstd/sys_common/thread_local.rs
index 2cc5372e268..9db7d732698 100644
--- a/src/libstd/sys_common/thread_local.rs
+++ b/src/libstd/sys_common/thread_local.rs
@@ -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);
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index 98b4ca36c26..0078a05e597 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -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;