Skip to content

Commit 3cec209

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

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/concurrency/thread.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,14 +1070,23 @@ 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);
1073+
let thread_local_allocations = this.machine.threads.thread_terminated(
1074+
this.machine.data_race.as_mut(),
1075+
current_span,
1076+
);
1077+
match this.get_active_thread_id() {
1078+
// For main thread, add thread-local statics to static roots and skip deallocating
1079+
// backing memory
1080+
ThreadId(0) => for ptr in thread_local_allocations {
1081+
if let Some(alloc) = ptr.provenance.get_alloc_id() {
1082+
trace!("Main thread thread-local static stored as static root: {:?}", alloc);
1083+
this.machine.static_roots.push(alloc);
1084+
}
1085+
}
1086+
// Deallocate backing memory of thread-local statics
1087+
ThreadId(_) => for ptr in thread_local_allocations {
1088+
this.deallocate_ptr(ptr.into(), None, MiriMemoryKind::Tls.into())?;
10791089
}
1080-
this.deallocate_ptr(ptr.into(), None, MiriMemoryKind::Tls.into())?;
10811090
}
10821091
Ok(())
10831092
}

0 commit comments

Comments
 (0)