]> git.lizzy.rs Git - rust.git/commitdiff
actually, reentrant uninitialized mutex acquisition is outright UB
authorRalf Jung <post@ralfj.de>
Mon, 6 Aug 2018 12:39:55 +0000 (14:39 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 6 Aug 2018 12:39:55 +0000 (14:39 +0200)
src/libstd/io/lazy.rs
src/libstd/sys/unix/args.rs
src/libstd/sys/unix/os.rs
src/libstd/sys_common/at_exit_imp.rs
src/libstd/sys_common/mutex.rs
src/libstd/sys_common/thread_local.rs
src/libstd/thread/mod.rs

index 9513cc7fb2d7ba97f8deb1b036ebd0ed9bd88f83..5743ea51af350eac5eaa8be6f3a45a0d9482ca55 100644 (file)
@@ -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()),
index c91bd5b22afcb2c11b95294bcf230a7a5e4a5e92..220bd11b1f1e50a7f51f131cf1e1ddd71ee70384 100644 (file)
@@ -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) {
index 6ef9502ba624e6f68a8c07c03d536201d44e1c49..3d98b2efdf1f79a44a60d9dbeae75613ad3430ea 100644 (file)
@@ -33,9 +33,8 @@
 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();
 
 
index 30019088eb689dc586ff01d63152373fed8a7eea..856798373128d51cdca8e772e1f48ebb30bc4691 100644 (file)
@@ -23,9 +23,8 @@
 // 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();
 
index a4efe4d128e6954f9ac5ea2327fa1cbe2d4e01fa..74e1defd9f46584aa2cb8e9892e2895f07412c54 100644 (file)
@@ -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.
index 2cc5372e26818ada5025eadc84177a33d0345d45..9db7d732698766d758a0005b789d30c50932c6d9 100644 (file)
@@ -161,9 +161,8 @@ unsafe fn lazy_init(&self) -> usize {
         // 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);
index 98b4ca36c26335fda26f7257bee0017957a1a47c..0078a05e5971a1420edf2a6aaacbe3b61f4b9b51 100644 (file)
@@ -940,9 +940,8 @@ pub fn park_timeout(dur: Duration) {
 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;