Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions litebox_shim_linux/src/syscalls/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,6 @@ fn wake_robust_list(
impl<FS: ShimFS> Task<FS> {
/// Called when the task is exiting.
pub(crate) fn prepare_for_exit(&mut self) {
self.thread.detach_from_process();

if let Some(clear_child_tid) = self.thread.clear_child_tid.take() {
// Clear the child TID if requested
// TODO: if we are the last thread, we don't need to clear it
Expand All @@ -516,6 +514,14 @@ impl<FS: ShimFS> Task<FS> {
if let Some(robust_list) = self.thread.robust_list.take() {
let _ = wake_robust_list(robust_list);
}

// This must run last, after all of this task's remaining accesses to
// guest memory have completed. Otherwise, because this decrements the
// `nr_threads` counter, other tasks may assume that the memory of this
// task isn't referenced any more, and therefore can be de-allocated and
// re-used (e.g., for an `exec`d process). See
// https://github.com/microsoft/litebox/pull/1155.
self.thread.detach_from_process();
}

pub(crate) fn sys_exit(&self, status: i32) {
Expand Down
Loading