Skip to content

Commit

Permalink
skip deallocating main-thread TLS backing memory
Browse files Browse the repository at this point in the history
  • Loading branch information
max-heller committed Jul 8, 2023
1 parent 2fd2ed1 commit 81ea21b
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/concurrency/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,14 +1070,26 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
thread.state = ThreadState::Terminated;

let current_span = this.machine.current_span();
for ptr in
this.machine.threads.thread_terminated(this.machine.data_race.as_mut(), current_span)
{
if let Some(alloc) = ptr.provenance.get_alloc_id() {
trace!("Main thread thread-local static stored as static root: {:?}", alloc);
this.machine.static_roots.push(alloc);
}
this.deallocate_ptr(ptr.into(), None, MiriMemoryKind::Tls.into())?;
let thread_local_allocations =
this.machine.threads.thread_terminated(this.machine.data_race.as_mut(), current_span);
match this.get_active_thread() {
// For main thread, add thread-local statics to static roots and skip deallocating
// backing memory
ThreadId(0) =>
for ptr in thread_local_allocations {
if let Some(alloc) = ptr.provenance.get_alloc_id() {
trace!(
"Main thread thread-local static stored as static root: {:?}",
alloc
);
this.machine.static_roots.push(alloc);
}
},
// Deallocate backing memory of thread-local statics
ThreadId(_) =>
for ptr in thread_local_allocations {
this.deallocate_ptr(ptr.into(), None, MiriMemoryKind::Tls.into())?;
},
}
Ok(())
}
Expand Down

0 comments on commit 81ea21b

Please sign in to comment.