Commit 885da513 authored by erikchen's avatar erikchen Committed by Commit bot

mac: Some consumers of SharedMemory require a POSIX fd.

There are two implementations of SharedMemory on OSX: Mach and POSIX. Some
consumers of SharedMemory currently require the POSIX implementation. The
default is going to become Mach. This CL updates some consumers of SharedMemory
to force the construction of a POSIX fd-backed SharedMemory region.

BUG=466437

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

Cr-Commit-Position: refs/heads/master@{#360502}
parent afeecbf9
...@@ -122,8 +122,15 @@ bool DiscardableSharedMemory::CreateAndMap(size_t size) { ...@@ -122,8 +122,15 @@ bool DiscardableSharedMemory::CreateAndMap(size_t size) {
if (!checked_size.IsValid()) if (!checked_size.IsValid())
return false; return false;
#if defined(OS_MACOSX) && !defined(OS_IOS)
// DiscardableSharedMemory does not yet support a Mach-implementation, so
// force the underlying primitive to be a POSIX fd. https://crbug.com/547239.
if (!shared_memory_.CreateAndMapAnonymousPosix(checked_size.ValueOrDie()))
return false;
#else
if (!shared_memory_.CreateAndMapAnonymous(checked_size.ValueOrDie())) if (!shared_memory_.CreateAndMapAnonymous(checked_size.ValueOrDie()))
return false; return false;
#endif // defined(OS_MACOSX) && !defined(OS_IOS)
mapped_size_ = mapped_size_ =
shared_memory_.mapped_size() - AlignToPageSize(sizeof(SharedState)); shared_memory_.mapped_size() - AlignToPageSize(sizeof(SharedState));
......
...@@ -316,6 +316,10 @@ TEST(SharedMemoryTest, ShareReadOnly) { ...@@ -316,6 +316,10 @@ TEST(SharedMemoryTest, ShareReadOnly) {
SharedMemoryCreateOptions options; SharedMemoryCreateOptions options;
options.size = contents.size(); options.size = contents.size();
options.share_read_only = true; options.share_read_only = true;
#if defined(OS_MACOSX) && !defined(OS_IOS)
// The Mach functionality is tested in shared_memory_mac_unittest.cc.
options.type = SharedMemoryHandle::POSIX;
#endif
ASSERT_TRUE(writable_shmem.Create(options)); ASSERT_TRUE(writable_shmem.Create(options));
ASSERT_TRUE(writable_shmem.Map(options.size)); ASSERT_TRUE(writable_shmem.Map(options.size));
memcpy(writable_shmem.memory(), contents.data(), contents.size()); memcpy(writable_shmem.memory(), contents.data(), contents.size());
...@@ -502,6 +506,10 @@ TEST(SharedMemoryTest, FilePermissionsAnonymous) { ...@@ -502,6 +506,10 @@ TEST(SharedMemoryTest, FilePermissionsAnonymous) {
SharedMemory shared_memory; SharedMemory shared_memory;
SharedMemoryCreateOptions options; SharedMemoryCreateOptions options;
options.size = kTestSize; options.size = kTestSize;
#if defined(OS_MACOSX) && !defined(OS_IOS)
// The Mach functionality is tested in shared_memory_mac_unittest.cc.
options.type = SharedMemoryHandle::POSIX;
#endif
// Set a file mode creation mask that gives all permissions. // Set a file mode creation mask that gives all permissions.
ScopedUmaskSetter permissive_mask(S_IWGRP | S_IWOTH); ScopedUmaskSetter permissive_mask(S_IWGRP | S_IWOTH);
...@@ -524,6 +532,10 @@ TEST(SharedMemoryTest, FilePermissionsNamed) { ...@@ -524,6 +532,10 @@ TEST(SharedMemoryTest, FilePermissionsNamed) {
SharedMemory shared_memory; SharedMemory shared_memory;
SharedMemoryCreateOptions options; SharedMemoryCreateOptions options;
options.size = kTestSize; options.size = kTestSize;
#if defined(OS_MACOSX) && !defined(OS_IOS)
// The Mach functionality is tested in shared_memory_mac_unittest.cc.
options.type = SharedMemoryHandle::POSIX;
#endif
// Set a file mode creation mask that gives all permissions. // Set a file mode creation mask that gives all permissions.
ScopedUmaskSetter permissive_mask(S_IWGRP | S_IWOTH); ScopedUmaskSetter permissive_mask(S_IWGRP | S_IWOTH);
......
...@@ -28,8 +28,17 @@ scoped_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create( ...@@ -28,8 +28,17 @@ scoped_ptr<gfx::GpuMemoryBuffer> MojoGpuMemoryBufferImpl::Create(
gfx::BufferUsage usage) { gfx::BufferUsage usage) {
size_t bytes = gfx::BufferSizeForBufferFormat(size, format); size_t bytes = gfx::BufferSizeForBufferFormat(size, format);
scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory);
#if defined(OS_MACOSX)
// Mojo IPC does not yet support transfer of Mach primitives, so
// force the underlying primitive to be a POSIX fd. https://crbug.com/547243.
if (!shared_memory->CreateAnonymousPosix(bytes))
return nullptr;
#else
if (!shared_memory->CreateAnonymous(bytes)) if (!shared_memory->CreateAnonymous(bytes))
return nullptr; return nullptr;
#endif // defined(OS_MACOSX)
return make_scoped_ptr<gfx::GpuMemoryBuffer>( return make_scoped_ptr<gfx::GpuMemoryBuffer>(
new MojoGpuMemoryBufferImpl(size, format, shared_memory.Pass())); new MojoGpuMemoryBufferImpl(size, format, shared_memory.Pass()));
} }
......
...@@ -944,6 +944,10 @@ bool NaClProcessHost::StartNaClExecution() { ...@@ -944,6 +944,10 @@ bool NaClProcessHost::StartNaClExecution() {
base::SharedMemoryCreateOptions options; base::SharedMemoryCreateOptions options;
options.size = 1; options.size = 1;
options.executable = true; options.executable = true;
// NaCl expects a POSIX fd.
options.type = base::SharedMemoryHandle::POSIX;
if (!memory_buffer.Create(options)) { if (!memory_buffer.Create(options)) {
DLOG(ERROR) << "Failed to allocate memory buffer"; DLOG(ERROR) << "Failed to allocate memory buffer";
return false; return false;
......
...@@ -74,8 +74,16 @@ class DesktopSessionAgent::SharedBuffer : public webrtc::SharedMemory { ...@@ -74,8 +74,16 @@ class DesktopSessionAgent::SharedBuffer : public webrtc::SharedMemory {
size_t size, size_t size,
int id) { int id) {
scoped_ptr<base::SharedMemory> memory(new base::SharedMemory()); scoped_ptr<base::SharedMemory> memory(new base::SharedMemory());
#if defined(OS_MACOSX) && !defined(OS_IOS)
// Remoting does not yet support Mach primitive backed SharedMemory, so
// force the underlying primitive to be a POSIX fd.
// https://crbug.com/547247.
if (!memory->CreateAndMapAnonymousPosix(size))
return nullptr;
#else
if (!memory->CreateAndMapAnonymous(size)) if (!memory->CreateAndMapAnonymous(size))
return nullptr; return nullptr;
#endif // defined(OS_MACOSX) && !defined(OS_IOS)
return make_scoped_ptr(new SharedBuffer(agent, memory.Pass(), size, id)); return make_scoped_ptr(new SharedBuffer(agent, memory.Pass(), size, id));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment