Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Side by Side Diff: mojo/edk/embedder/platform_shared_buffer.cc

Issue 2555483002: Add POSIX shared memory support for Mac (Closed)
Patch Set: Check that we never pass POSIX shm over Mojo. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/embedder/platform_shared_buffer.h" 5 #include "mojo/edk/embedder/platform_shared_buffer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 15 matching lines...) Expand all
26 namespace { 26 namespace {
27 27
28 // Takes ownership of |memory_handle|. 28 // Takes ownership of |memory_handle|.
29 ScopedPlatformHandle SharedMemoryToPlatformHandle( 29 ScopedPlatformHandle SharedMemoryToPlatformHandle(
30 base::SharedMemoryHandle memory_handle) { 30 base::SharedMemoryHandle memory_handle) {
31 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) 31 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS))
32 return ScopedPlatformHandle(PlatformHandle(memory_handle.fd)); 32 return ScopedPlatformHandle(PlatformHandle(memory_handle.fd));
33 #elif defined(OS_WIN) 33 #elif defined(OS_WIN)
34 return ScopedPlatformHandle(PlatformHandle(memory_handle.GetHandle())); 34 return ScopedPlatformHandle(PlatformHandle(memory_handle.GetHandle()));
35 #else 35 #else
36 return ScopedPlatformHandle(PlatformHandle(memory_handle.GetMemoryObject())); 36 if (memory_handle.GetType() == base::SharedMemoryHandle::MACH) {
37 return ScopedPlatformHandle(PlatformHandle(
38 memory_handle.GetMemoryObject()));
39 } else {
40 // We should never pass POSIX shared memory over IPC.
41 CHECK(false);
42 return ScopedPlatformHandle();
43 }
37 #endif 44 #endif
38 } 45 }
39 46
40 } // namespace 47 } // namespace
41 48
42 // static 49 // static
43 PlatformSharedBuffer* PlatformSharedBuffer::Create(size_t num_bytes) { 50 PlatformSharedBuffer* PlatformSharedBuffer::Create(size_t num_bytes) {
44 DCHECK_GT(num_bytes, 0u); 51 DCHECK_GT(num_bytes, 0u);
45 52
46 PlatformSharedBuffer* rv = new PlatformSharedBuffer(num_bytes, false); 53 PlatformSharedBuffer* rv = new PlatformSharedBuffer(num_bytes, false);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 PlatformSharedBuffer::~PlatformSharedBuffer() {} 226 PlatformSharedBuffer::~PlatformSharedBuffer() {}
220 227
221 bool PlatformSharedBuffer::Init() { 228 bool PlatformSharedBuffer::Init() {
222 DCHECK(!shared_memory_); 229 DCHECK(!shared_memory_);
223 DCHECK(!read_only_); 230 DCHECK(!read_only_);
224 231
225 base::SharedMemoryCreateOptions options; 232 base::SharedMemoryCreateOptions options;
226 options.size = num_bytes_; 233 options.size = num_bytes_;
227 // By default, we can share as read-only. 234 // By default, we can share as read-only.
228 options.share_read_only = true; 235 options.share_read_only = true;
236 #if defined(OS_MACOSX) && !defined(OS_IOS)
237 options.type = base::SharedMemoryHandle::MACH;
238 #endif
229 239
230 shared_memory_.reset(new base::SharedMemory); 240 shared_memory_.reset(new base::SharedMemory);
231 return shared_memory_->Create(options); 241 return shared_memory_->Create(options);
232 } 242 }
233 243
234 bool PlatformSharedBuffer::InitFromPlatformHandle( 244 bool PlatformSharedBuffer::InitFromPlatformHandle(
235 ScopedPlatformHandle platform_handle) { 245 ScopedPlatformHandle platform_handle) {
236 DCHECK(!shared_memory_); 246 DCHECK(!shared_memory_);
237 247
238 #if defined(OS_WIN) 248 #if defined(OS_WIN)
239 base::SharedMemoryHandle handle(platform_handle.release().handle, 249 base::SharedMemoryHandle handle(platform_handle.release().handle,
240 base::GetCurrentProcId()); 250 base::GetCurrentProcId());
241 #elif defined(OS_MACOSX) && !defined(OS_IOS) 251 #elif defined(OS_MACOSX) && !defined(OS_IOS)
242 base::SharedMemoryHandle handle; 252 base::SharedMemoryHandle handle;
243 handle = base::SharedMemoryHandle(platform_handle.release().port, num_bytes_, 253 if (platform_handle.get().type == PlatformHandle::Type::MACH) {
244 base::GetCurrentProcId()); 254 handle = base::SharedMemoryHandle(
255 platform_handle.release().port, num_bytes_, base::GetCurrentProcId());
256 } else {
257 handle = base::SharedMemoryHandle(platform_handle.release().handle, false);
258 }
245 #else 259 #else
246 base::SharedMemoryHandle handle(platform_handle.release().handle, false); 260 base::SharedMemoryHandle handle(platform_handle.release().handle, false);
247 #endif 261 #endif
248 262
249 shared_memory_.reset(new base::SharedMemory(handle, read_only_)); 263 shared_memory_.reset(new base::SharedMemory(handle, read_only_));
250 return true; 264 return true;
251 } 265 }
252 266
253 bool PlatformSharedBuffer::InitFromPlatformHandlePair( 267 bool PlatformSharedBuffer::InitFromPlatformHandlePair(
254 ScopedPlatformHandle rw_platform_handle, 268 ScopedPlatformHandle rw_platform_handle,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding; 330 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding;
317 return true; 331 return true;
318 } 332 }
319 333
320 void PlatformSharedBufferMapping::Unmap() { 334 void PlatformSharedBufferMapping::Unmap() {
321 shared_memory_.Unmap(); 335 shared_memory_.Unmap();
322 } 336 }
323 337
324 } // namespace edk 338 } // namespace edk
325 } // namespace mojo 339 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698