Skip to content

Commit 81ea21b

Browse files
committed
skip deallocating main-thread TLS backing memory
1 parent 2fd2ed1 commit 81ea21b

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/concurrency/thread.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,14 +1070,26 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10701070
thread.state = ThreadState::Terminated;
10711071

10721072
let current_span = this.machine.current_span();
1073-
for ptr in
1074-
this.machine.threads.thread_terminated(this.machine.data_race.as_mut(), current_span)
1075-
{
1076-
if let Some(alloc) = ptr.provenance.get_alloc_id() {
1077-
trace!("Main thread thread-local static stored as static root: {:?}", alloc);
1078-
this.machine.static_roots.push(alloc);
1079-
}
1080-
this.deallocate_ptr(ptr.into(), None, MiriMemoryKind::Tls.into())?;
1073+
let thread_local_allocations =
1074+
this.machine.threads.thread_terminated(this.machine.data_race.as_mut(), current_span);
1075+
match this.get_active_thread() {
1076+
// For main thread, add thread-local statics to static roots and skip deallocating
1077+
// backing memory
1078+
ThreadId(0) =>
1079+
for ptr in thread_local_allocations {
1080+
if let Some(alloc) = ptr.provenance.get_alloc_id() {
1081+
trace!(
1082+
"Main thread thread-local static stored as static root: {:?}",
1083+
alloc
1084+
);
1085+
this.machine.static_roots.push(alloc);
1086+
}
1087+
},
1088+
// Deallocate backing memory of thread-local statics
1089+
ThreadId(_) =>
1090+
for ptr in thread_local_allocations {
1091+
this.deallocate_ptr(ptr.into(), None, MiriMemoryKind::Tls.into())?;
1092+
},
10811093
}
10821094
Ok(())
10831095
}

0 commit comments

Comments
 (0)