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

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

Issue 1897623002: Remove POSIX shared memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase against https://codereview.chromium.org/1890043002/. Created 4 years, 8 months 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
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/shared_memory.h" 12 #include "base/memory/shared_memory.h"
13 #include "base/process/process_handle.h" 13 #include "base/process/process_handle.h"
14 #include "base/sys_info.h" 14 #include "base/sys_info.h"
15 #include "mojo/edk/embedder/platform_handle_utils.h" 15 #include "mojo/edk/embedder/platform_handle_utils.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 namespace edk { 18 namespace edk {
19 19
20 namespace { 20 namespace {
21 21
22 // Takes ownership of |memory_handle|. 22 // Takes ownership of |memory_handle|.
23 ScopedPlatformHandle SharedMemoryToPlatformHandle( 23 ScopedPlatformHandle SharedMemoryToPlatformHandle(
24 base::SharedMemoryHandle memory_handle) { 24 base::SharedMemoryHandle memory_handle) {
25 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) 25 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS))
26 return ScopedPlatformHandle(PlatformHandle(memory_handle.fd)); 26 return ScopedPlatformHandle(PlatformHandle(memory_handle.fd));
27 #elif defined(OS_WIN) 27 #elif defined(OS_WIN)
28 return ScopedPlatformHandle(PlatformHandle(memory_handle.GetHandle())); 28 return ScopedPlatformHandle(PlatformHandle(memory_handle.GetHandle()));
29 #else 29 #else
30 if (memory_handle.GetType() == base::SharedMemoryHandle::MACH) { 30 return ScopedPlatformHandle(PlatformHandle(memory_handle.GetMemoryObject()));
31 return ScopedPlatformHandle(PlatformHandle(
32 memory_handle.GetMemoryObject()));
33 } else {
34 DCHECK(memory_handle.GetType() == base::SharedMemoryHandle::POSIX);
35 return ScopedPlatformHandle(PlatformHandle(
36 memory_handle.GetFileDescriptor().fd));
37 }
38 #endif 31 #endif
39 } 32 }
40 33
41 } // namespace 34 } // namespace
42 35
43 // static 36 // static
44 PlatformSharedBuffer* PlatformSharedBuffer::Create(size_t num_bytes) { 37 PlatformSharedBuffer* PlatformSharedBuffer::Create(size_t num_bytes) {
45 DCHECK_GT(num_bytes, 0u); 38 DCHECK_GT(num_bytes, 0u);
46 39
47 PlatformSharedBuffer* rv = new PlatformSharedBuffer(num_bytes, false); 40 PlatformSharedBuffer* rv = new PlatformSharedBuffer(num_bytes, false);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 PlatformSharedBuffer::~PlatformSharedBuffer() {} 213 PlatformSharedBuffer::~PlatformSharedBuffer() {}
221 214
222 bool PlatformSharedBuffer::Init() { 215 bool PlatformSharedBuffer::Init() {
223 DCHECK(!shared_memory_); 216 DCHECK(!shared_memory_);
224 DCHECK(!read_only_); 217 DCHECK(!read_only_);
225 218
226 base::SharedMemoryCreateOptions options; 219 base::SharedMemoryCreateOptions options;
227 options.size = num_bytes_; 220 options.size = num_bytes_;
228 // By default, we can share as read-only. 221 // By default, we can share as read-only.
229 options.share_read_only = true; 222 options.share_read_only = true;
230 #if defined(OS_MACOSX) && !defined(OS_IOS)
231 options.type = base::SharedMemoryHandle::MACH;
232 #endif
233 223
234 shared_memory_.reset(new base::SharedMemory); 224 shared_memory_.reset(new base::SharedMemory);
235 return shared_memory_->Create(options); 225 return shared_memory_->Create(options);
236 } 226 }
237 227
238 bool PlatformSharedBuffer::InitFromPlatformHandle( 228 bool PlatformSharedBuffer::InitFromPlatformHandle(
239 ScopedPlatformHandle platform_handle) { 229 ScopedPlatformHandle platform_handle) {
240 DCHECK(!shared_memory_); 230 DCHECK(!shared_memory_);
241 231
242 #if defined(OS_WIN) 232 #if defined(OS_WIN)
243 base::SharedMemoryHandle handle(platform_handle.release().handle, 233 base::SharedMemoryHandle handle(platform_handle.release().handle,
244 base::GetCurrentProcId()); 234 base::GetCurrentProcId());
245 #elif defined(OS_MACOSX) && !defined(OS_IOS) 235 #elif defined(OS_MACOSX) && !defined(OS_IOS)
246 base::SharedMemoryHandle handle; 236 base::SharedMemoryHandle handle;
247 if (platform_handle.get().type == PlatformHandle::Type::MACH) { 237 handle = base::SharedMemoryHandle(platform_handle.release().port, num_bytes_,
248 handle = base::SharedMemoryHandle( 238 base::GetCurrentProcId());
249 platform_handle.release().port, num_bytes_, base::GetCurrentProcId());
250 } else {
251 handle = base::SharedMemoryHandle(platform_handle.release().handle, false);
252 }
253 #else 239 #else
254 base::SharedMemoryHandle handle(platform_handle.release().handle, false); 240 base::SharedMemoryHandle handle(platform_handle.release().handle, false);
255 #endif 241 #endif
256 242
257 shared_memory_.reset(new base::SharedMemory(handle, read_only_)); 243 shared_memory_.reset(new base::SharedMemory(handle, read_only_));
258 return true; 244 return true;
259 } 245 }
260 246
261 bool PlatformSharedBuffer::InitFromPlatformHandlePair( 247 bool PlatformSharedBuffer::InitFromPlatformHandlePair(
262 ScopedPlatformHandle rw_platform_handle, 248 ScopedPlatformHandle rw_platform_handle,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding; 297 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding;
312 return true; 298 return true;
313 } 299 }
314 300
315 void PlatformSharedBufferMapping::Unmap() { 301 void PlatformSharedBufferMapping::Unmap() {
316 shared_memory_.Unmap(); 302 shared_memory_.Unmap();
317 } 303 }
318 304
319 } // namespace edk 305 } // namespace edk
320 } // namespace mojo 306 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698