Skip to content

Commit

Permalink
Session::recreate_shared_mmap fixes
Browse files Browse the repository at this point in the history
While unmapping a Mapping local_addr, take into account
that the Mapping `m` passed in as a method parameter may
come from a Task that differs from the remote.task() so
the Mapping at m.map.start() for remote.task() may be
different to `m`.
  • Loading branch information
sidkshatriya authored and rocallahan committed Nov 3, 2024
1 parent d3b1386 commit 5472a2f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,22 @@ const AddressSpace::Mapping Session::recreate_shared_mmap(
uint32_t flags = m.flags;
size_t size = m.map.size();
void* preserved_data = preserve == PRESERVE_CONTENTS ? m.local_addr : nullptr;
if (preserved_data) {
remote.task()->vm()->detach_local_mapping(m.map.start());
void* remote_task_local_mapping = nullptr;

{
// Note that Mapping `m` may correspond to a Mapping from a different Task
// than the `maybe_detach_mapping`. See replay_syscall.cc prepare_clone()
// for an example.
auto remote_task_mapping = remote.task()->vm()->mapping_of(m.map.start());

// Sanity check
ASSERT(remote.task(), size == remote_task_mapping.map.size());
ASSERT(remote.task(), m.map.start() == remote_task_mapping.map.start());

remote_task_local_mapping =
remote.task()->vm()->detach_local_mapping(m.map.start());
}

remote_ptr<void> new_addr =
create_shared_mmap(remote, m.map.size(), m.map.start(),
extract_name(name, sizeof(name)), m.map.prot(), 0,
Expand All @@ -575,9 +588,11 @@ const AddressSpace::Mapping Session::recreate_shared_mmap(
new_map = remote.task()->vm()->mapping_of(new_addr);
if (preserved_data) {
memcpy(new_map.local_addr, preserved_data, size);
munmap(preserved_data, size);
}
}
if (remote_task_local_mapping) {
munmap(remote_task_local_mapping, size);
}
return new_map;
}

Expand Down

0 comments on commit 5472a2f

Please sign in to comment.