@@ -253,10 +253,10 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
253
253
}
254
254
255
255
/// Schedule the MacOS thread destructor of the thread local storage to be
256
- /// executed.
256
+ /// executed. Returns `true` if scheduled.
257
257
///
258
258
/// 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 > {
260
260
let this = self . eval_context_mut ( ) ;
261
261
let thread_id = this. get_active_thread ( ) ?;
262
262
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
275
275
// guaranteed that we will schedule it again. The `dtors_running`
276
276
// flag will prevent the code from adding the destructor again.
277
277
this. enable_thread ( thread_id) ?;
278
+ Ok ( true )
279
+ } else {
280
+ Ok ( false )
278
281
}
279
- Ok ( ( ) )
280
282
}
281
283
282
284
/// Schedule a pthread TLS destructor. Returns `true` if found
@@ -331,20 +333,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
331
333
let this = self . eval_context_mut ( ) ;
332
334
let active_thread = this. get_active_thread ( ) ?;
333
335
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" {
335
337
if !this. machine . tls . set_dtors_running_for_thread ( active_thread) {
336
338
this. schedule_windows_tls_dtors ( ) ?;
339
+ true
340
+ } else {
341
+ false
337
342
}
338
- true
339
343
} else {
340
344
this. machine . tls . set_dtors_running_for_thread ( active_thread) ;
341
345
// The macOS thread wide destructor runs "before any TLS slots get
342
346
// 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
+ }
345
352
} ;
346
353
347
- if finished {
354
+ if !scheduled_next {
355
+ // No dtors scheduled means that we are finished. Delete the
356
+ // remaining TLS entries.
348
357
this. machine . tls . delete_all_thread_tls ( active_thread) ;
349
358
}
350
359
0 commit comments