diff options
| author | Ralf Jung <post@ralfj.de> | 2020-07-23 15:49:39 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-07-23 17:12:31 +0200 |
| commit | c8229cdfc1a570b73d826cb92dd2d43db5257e4a (patch) | |
| tree | 99f54cb1dead1a7041b31eae2ba01b94a1364e78 /src/libstd | |
| parent | 1b446cdbf03d26f31f6113a4ccb2e011f3a9abf1 (diff) | |
| download | rust-c8229cdfc1a570b73d826cb92dd2d43db5257e4a.tar.gz rust-c8229cdfc1a570b73d826cb92dd2d43db5257e4a.zip | |
on Windows, use miri_static_root for TLS dtors
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sys/windows/thread_local_key.rs | 17 |
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, } } |
