about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/windows/thread_local_key.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libstd/sys/windows/thread_local_key.rs b/src/libstd/sys/windows/thread_local_key.rs
index e0bb102b3af..0bd9600b6f2 100644
--- a/src/libstd/sys/windows/thread_local_key.rs
+++ b/src/libstd/sys/windows/thread_local_key.rs
@@ -110,6 +110,16 @@ struct Node {
     next: *mut Node,
 }
 
+#[cfg(miri)]
+extern "Rust" {
+    /// Miri-provided extern function to mark the block `ptr` points to as a "root"
+    /// for some static memory. This memory and everything reachable by it is not
+    /// considered leaking even if it still exists when the program terminates.
+    ///
+    /// `ptr` has to point to the beginning of an allocated block.
+    fn miri_static_root(ptr: *const u8);
+}
+
 unsafe fn register_dtor(key: Key, dtor: Dtor) {
     let mut node = Box::new(Node { key, dtor, next: ptr::null_mut() });
 
@@ -117,7 +127,12 @@ unsafe fn register_dtor(key: Key, dtor: Dtor) {
     loop {
         node.next = head;
         match DTORS.compare_exchange(head, &mut *node, SeqCst, SeqCst) {
-            Ok(_) => return mem::forget(node),
+            Ok(_) => {
+                #[cfg(miri)]
+                miri_static_root(&*node as *const _ as *const u8);
+
+                return mem::forget(node);
+            }
             Err(cur) => head = cur,
         }
     }