Skip to content

Commit 3b58541

Browse files
author
Vytautas Astrauskas
committed
Fix MacOS and Windows builds.
1 parent 1355574 commit 3b58541

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/shims/tls.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
253253
}
254254

255255
/// Schedule the MacOS thread destructor of the thread local storage to be
256-
/// executed.
256+
/// executed. Returns `true` if scheduled.
257257
///
258258
/// Note: It is safe to call this function also on other Unixes.
259-
fn schedule_macos_tls_dtor(&mut self) -> InterpResult<'tcx> {
259+
fn schedule_macos_tls_dtor(&mut self) -> InterpResult<'tcx, bool> {
260260
let this = self.eval_context_mut();
261261
let thread_id = this.get_active_thread()?;
262262
if let Some((instance, data)) = this.machine.tls.thread_dtors.remove(&thread_id) {
@@ -275,8 +275,10 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
275275
// guaranteed that we will schedule it again. The `dtors_running`
276276
// flag will prevent the code from adding the destructor again.
277277
this.enable_thread(thread_id)?;
278+
Ok(true)
279+
} else {
280+
Ok(false)
278281
}
279-
Ok(())
280282
}
281283

282284
/// Schedule a pthread TLS destructor. Returns `true` if found
@@ -331,20 +333,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
331333
let this = self.eval_context_mut();
332334
let active_thread = this.get_active_thread()?;
333335

334-
let finished = if this.tcx.sess.target.target.target_os == "windows" {
336+
let scheduled_next = if this.tcx.sess.target.target.target_os == "windows" {
335337
if !this.machine.tls.set_dtors_running_for_thread(active_thread) {
336338
this.schedule_windows_tls_dtors()?;
339+
true
340+
} else {
341+
false
337342
}
338-
true
339343
} else {
340344
this.machine.tls.set_dtors_running_for_thread(active_thread);
341345
// The macOS thread wide destructor runs "before any TLS slots get
342346
// freed", so do that first.
343-
this.schedule_macos_tls_dtor()?;
344-
this.schedule_pthread_tls_dtors()?
347+
if this.schedule_macos_tls_dtor()? {
348+
true
349+
} else {
350+
this.schedule_pthread_tls_dtors()?
351+
}
345352
};
346353

347-
if finished {
354+
if !scheduled_next {
355+
// No dtors scheduled means that we are finished. Delete the
356+
// remaining TLS entries.
348357
this.machine.tls.delete_all_thread_tls(active_thread);
349358
}
350359

tests/run-pass/libc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ fn test_rwlock_libc_static_initializer() {
144144
/// Test whether the `prctl` shim correctly sets the thread name.
145145
///
146146
/// Note: `prctl` exists only on Linux.
147+
#[cfg(target_os = "linux")]
147148
fn test_prctl_thread_name() {
148149
use std::ffi::CString;
149150
unsafe {

0 commit comments

Comments
 (0)