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

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

Issue 1867733002: mac: Remove POSIX shared memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp50_base
Patch Set: Comments from amistry. 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 PlatformSharedBuffer::~PlatformSharedBuffer() {} 182 PlatformSharedBuffer::~PlatformSharedBuffer() {}
190 183
191 bool PlatformSharedBuffer::Init() { 184 bool PlatformSharedBuffer::Init() {
192 DCHECK(!shared_memory_); 185 DCHECK(!shared_memory_);
193 DCHECK(!read_only_); 186 DCHECK(!read_only_);
194 187
195 base::SharedMemoryCreateOptions options; 188 base::SharedMemoryCreateOptions options;
196 options.size = num_bytes_; 189 options.size = num_bytes_;
197 // By default, we can share as read-only. 190 // By default, we can share as read-only.
198 options.share_read_only = true; 191 options.share_read_only = true;
199 #if defined(OS_MACOSX) && !defined(OS_IOS)
200 options.type = base::SharedMemoryHandle::MACH;
201 #endif
202 192
203 shared_memory_.reset(new base::SharedMemory); 193 shared_memory_.reset(new base::SharedMemory);
204 return shared_memory_->Create(options); 194 return shared_memory_->Create(options);
205 } 195 }
206 196
207 bool PlatformSharedBuffer::InitFromPlatformHandle( 197 bool PlatformSharedBuffer::InitFromPlatformHandle(
208 ScopedPlatformHandle platform_handle) { 198 ScopedPlatformHandle platform_handle) {
209 DCHECK(!shared_memory_); 199 DCHECK(!shared_memory_);
210 200
211 #if defined(OS_WIN) 201 #if defined(OS_WIN)
212 base::SharedMemoryHandle handle(platform_handle.release().handle, 202 base::SharedMemoryHandle handle(platform_handle.release().handle,
213 base::GetCurrentProcId()); 203 base::GetCurrentProcId());
214 #elif defined(OS_MACOSX) && !defined(OS_IOS) 204 #elif defined(OS_MACOSX) && !defined(OS_IOS)
215 base::SharedMemoryHandle handle; 205 base::SharedMemoryHandle handle;
216 if (platform_handle.get().type == PlatformHandle::Type::MACH) { 206 handle = base::SharedMemoryHandle(platform_handle.release().port, num_bytes_,
217 handle = base::SharedMemoryHandle( 207 base::GetCurrentProcId());
218 platform_handle.release().port, num_bytes_, base::GetCurrentProcId());
219 } else {
220 handle = base::SharedMemoryHandle(platform_handle.release().handle, false);
221 }
222 #else 208 #else
223 base::SharedMemoryHandle handle(platform_handle.release().handle, false); 209 base::SharedMemoryHandle handle(platform_handle.release().handle, false);
224 #endif 210 #endif
225 211
226 shared_memory_.reset(new base::SharedMemory(handle, read_only_)); 212 shared_memory_.reset(new base::SharedMemory(handle, read_only_));
227 return true; 213 return true;
228 } 214 }
229 215
230 void PlatformSharedBuffer::InitFromSharedMemoryHandle( 216 void PlatformSharedBuffer::InitFromSharedMemoryHandle(
231 base::SharedMemoryHandle handle) { 217 base::SharedMemoryHandle handle) {
(...skipping 28 matching lines...) Expand all
260 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding; 246 base_ = static_cast<char*>(shared_memory_.memory()) + offset_rounding;
261 return true; 247 return true;
262 } 248 }
263 249
264 void PlatformSharedBufferMapping::Unmap() { 250 void PlatformSharedBufferMapping::Unmap() {
265 shared_memory_.Unmap(); 251 shared_memory_.Unmap();
266 } 252 }
267 253
268 } // namespace edk 254 } // namespace edk
269 } // namespace mojo 255 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698