Skip to content

Commit 3179a47

Browse files
committed
Auto merge of rust-lang#157417 - RalfJung:windows-tls-miri, r=ChrisDenton
Windows TLS: avoid atexit call in Miri This was added in rust-lang#148799. I did not realize that we're actually falsely pretending that `atexit` worked, I thought we'd always return an error. Having it pretend to work when really it did nothing seems like a bad idea so let's just skip that call under `cfg(miri)`. r? @ChrisDenton Cc @ohadravid
2 parents e7815e5 + d0b0910 commit 3179a47

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

library/std/src/sys/thread_local/guard/windows.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,13 @@ pub fn enable() {
155155
//
156156
// If a main non-Rust binary is exiting, it must not be trigger the `enable` guard
157157
// for the first time during process shutdown.
158-
let res = unsafe { c::atexit(free_fls_key_at_exit) };
159-
if res != 0 {
160-
rtabort!("failed to register fls atexit hook");
158+
//
159+
// Miri has no DLL unloading so we can skip this step here.
160+
if !cfg!(miri) {
161+
let res = unsafe { c::atexit(free_fls_key_at_exit) };
162+
if res != 0 {
163+
rtabort!("failed to register fls atexit hook");
164+
}
161165
}
162166

163167
new_key

src/tools/miri/src/shims/windows/foreign_items.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,18 +1400,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
14001400
// FIXME: this should return a nonzero value if this call does result in switching to another thread.
14011401
this.write_null(dest)?;
14021402
}
1403-
"atexit" if this.frame_in_std() => {
1404-
let [_value] = this.check_shim_sig(
1405-
shim_sig!(extern "C" fn(*const _) -> winapi::c_int),
1406-
link_name,
1407-
abi,
1408-
args,
1409-
)?;
1410-
1411-
// We do not support registering atexit handlers, which is used by the thread-local destructor implementation in std.
1412-
// But we also do not support manually unloading DLLs, so this has no visible effect.
1413-
this.write_int(0, dest)?;
1414-
}
14151403

14161404
_ => return interp_ok(EmulateItemResult::NotSupported),
14171405
}

0 commit comments

Comments
 (0)