forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the variable does not need a destructor, `std` uses racy initialization for creating TLS keys on Windows. With just the right timing, this can lead to `TlsFree` being called. Unfortunately, with rust-lang#132654 this is hit quite often, so miri should definitely support `TlsFree` ([documentation](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-tlsfree)). I'm filing this here instead of in the miri repo so that rust-lang#132654 isn't blocked for so long.
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//@only-target: windows # this directly tests windows-only functions | ||
|
||
use std::ffi::c_void; | ||
use std::ptr; | ||
|
||
extern "system" { | ||
fn TlsAlloc() -> u32; | ||
fn TlsSetValue(key: u32, val: *mut c_void) -> bool; | ||
fn TlsGetValue(key: u32) -> *mut c_void; | ||
fn TlsFree(key: u32) -> bool; | ||
} | ||
|
||
fn main() { | ||
let key = unsafe { TlsAlloc() }; | ||
assert!(unsafe { TlsSetValue(key, ptr::without_provenance_mut(1)) }); | ||
assert_eq!(unsafe { TlsGetValue(key).addr() }, 1); | ||
assert!(unsafe { TlsFree(key) }); | ||
} |