Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Merge "Fix a bug in the implementation of Mach shared memory." to M48.
Browse files Browse the repository at this point in the history
> The bug prevented Mach shared memory from being mapped, after being unmapped.
>
> BUG=466437
>
> Review URL: https://codereview.chromium.org/1452063003
>
> Cr-Commit-Position: refs/heads/master@{#360192}

(cherry picked from commit 8d84ed5)
TBR=mark@chromium.org
BUG=563762

Review URL: https://codereview.chromium.org/1487203002 .

Cr-Commit-Position: refs/branch-heads/2564@{#188}
Cr-Branched-From: 1283eca-refs/heads/master@{#359700}
  • Loading branch information
erikchen committed Dec 2, 2015
1 parent 4e2ea90 commit f364a5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions base/memory/shared_memory_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,17 @@ bool SharedMemory::Unmap() {
switch (mapped_memory_mechanism_) {
case SharedMemoryHandle::POSIX:
munmap(memory_, mapped_size_);
memory_ = NULL;
mapped_size_ = 0;
return true;
break;
case SharedMemoryHandle::MACH:
mach_vm_deallocate(mach_task_self(),
reinterpret_cast<mach_vm_address_t>(memory_),
mapped_size_);
return true;
break;
}

memory_ = NULL;
mapped_size_ = 0;
return true;
}

SharedMemoryHandle SharedMemory::handle() const {
Expand Down
15 changes: 15 additions & 0 deletions base/memory/shared_memory_mac_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@ TEST_F(SharedMemoryMacMultiProcessTest, MachDuplicateAndClose) {
EXPECT_EQ(active_name_count, GetActiveNameCount());
}

// Tests that Mach shared memory can be mapped and unmapped.
TEST_F(SharedMemoryMacMultiProcessTest, MachUnmapMap) {
// Mach-based SharedMemory isn't support on OSX 10.6.
if (mac::IsOSSnowLeopard())
return;

mach_msg_type_number_t active_name_count = GetActiveNameCount();

scoped_ptr<SharedMemory> shared_memory = CreateSharedMemory(s_memory_size);
ASSERT_TRUE(shared_memory->Unmap());
ASSERT_TRUE(shared_memory->Map(s_memory_size));
shared_memory.reset();
EXPECT_EQ(active_name_count, GetActiveNameCount());
}

// Tests that passing a SharedMemoryHandle to a SharedMemory object also passes
// ownership, and that destroying the SharedMemory closes the SharedMemoryHandle
// as well.
Expand Down

0 comments on commit f364a5d

Please sign in to comment.