OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <mach/mach_vm.h> | 9 #include <mach/mach_vm.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 const std::string group_name = | 47 const std::string group_name = |
48 base::FieldTrialList::FindFullName(kTrialName); | 48 base::FieldTrialList::FindFullName(kTrialName); |
49 if (group_name == kTrialMach) { | 49 if (group_name == kTrialMach) { |
50 group = SharedMemoryHandle::MACH; | 50 group = SharedMemoryHandle::MACH; |
51 found_group = true; | 51 found_group = true; |
52 } else if (group_name == kTrialPosix) { | 52 } else if (group_name == kTrialPosix) { |
53 group = SharedMemoryHandle::POSIX; | 53 group = SharedMemoryHandle::POSIX; |
54 found_group = true; | 54 found_group = true; |
55 } else { | 55 } else { |
56 group = SharedMemoryHandle::MACH; | 56 group = SharedMemoryHandle::POSIX; |
57 } | 57 } |
58 | 58 |
59 return group; | 59 return group; |
60 } | 60 } |
61 | 61 |
62 // Emits a histogram entry indicating which type of SharedMemory was created. | 62 // Emits a histogram entry indicating which type of SharedMemory was created. |
63 void EmitMechanism(SharedMemoryHandle::Type type) { | 63 void EmitMechanism(SharedMemoryHandle::Type type) { |
64 UMA_HISTOGRAM_ENUMERATION("OSX.SharedMemory.Mechanism", type, | 64 UMA_HISTOGRAM_ENUMERATION("OSX.SharedMemory.Mechanism", type, |
65 SharedMemoryHandle::TypeMax); | 65 SharedMemoryHandle::TypeMax); |
66 } | 66 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return false; | 168 return false; |
169 } | 169 } |
170 } | 170 } |
171 } | 171 } |
172 return true; | 172 return true; |
173 } | 173 } |
174 | 174 |
175 } // namespace | 175 } // namespace |
176 | 176 |
177 SharedMemoryCreateOptions::SharedMemoryCreateOptions() | 177 SharedMemoryCreateOptions::SharedMemoryCreateOptions() |
178 : type(SharedMemoryHandle::MACH), | 178 : type(SharedMemoryHandle::POSIX), |
179 size(0), | 179 size(0), |
180 executable(false), | 180 executable(false), |
181 share_read_only(false) { | 181 share_read_only(false) {} |
182 if (mac::IsOSLionOrLater()) { | |
183 // A/B test the mechanism. Once the experiment is over, this will always be | |
184 // set to SharedMemoryHandle::MACH. | |
185 // http://crbug.com/547261 | |
186 type = GetABTestMechanism(); | |
187 } else { | |
188 // Mach shared memory isn't supported on OSX 10.6 or older. | |
189 type = SharedMemoryHandle::POSIX; | |
190 } | |
191 } | |
192 | 182 |
193 SharedMemory::SharedMemory() | 183 SharedMemory::SharedMemory() |
194 : mapped_memory_mechanism_(SharedMemoryHandle::POSIX), | 184 : mapped_memory_mechanism_(SharedMemoryHandle::POSIX), |
195 readonly_mapped_file_(-1), | 185 readonly_mapped_file_(-1), |
196 mapped_size_(0), | 186 mapped_size_(0), |
197 memory_(NULL), | 187 memory_(NULL), |
198 read_only_(false), | 188 read_only_(false), |
199 requested_size_(0) {} | 189 requested_size_(0) {} |
200 | 190 |
201 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only) | 191 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return CreateAnonymousPosix(size) && Map(size); | 256 return CreateAnonymousPosix(size) && Map(size); |
267 } | 257 } |
268 | 258 |
269 bool SharedMemory::CreateAnonymousPosix(size_t size) { | 259 bool SharedMemory::CreateAnonymousPosix(size_t size) { |
270 SharedMemoryCreateOptions options; | 260 SharedMemoryCreateOptions options; |
271 options.type = SharedMemoryHandle::POSIX; | 261 options.type = SharedMemoryHandle::POSIX; |
272 options.size = size; | 262 options.size = size; |
273 return Create(options); | 263 return Create(options); |
274 } | 264 } |
275 | 265 |
| 266 bool SharedMemory::CreateAndMapAnonymousMach(size_t size) { |
| 267 SharedMemoryCreateOptions options; |
| 268 |
| 269 if (mac::IsOSLionOrLater()) { |
| 270 // A/B test the mechanism. Once the experiment is over, this will always be |
| 271 // set to SharedMemoryHandle::MACH. |
| 272 // http://crbug.com/547261 |
| 273 options.type = GetABTestMechanism(); |
| 274 } else { |
| 275 // Mach shared memory isn't supported on OSX 10.6 or older. |
| 276 options.type = SharedMemoryHandle::POSIX; |
| 277 } |
| 278 options.size = size; |
| 279 return Create(options) && Map(size); |
| 280 } |
| 281 |
276 // static | 282 // static |
277 bool SharedMemory::GetSizeFromSharedMemoryHandle( | 283 bool SharedMemory::GetSizeFromSharedMemoryHandle( |
278 const SharedMemoryHandle& handle, | 284 const SharedMemoryHandle& handle, |
279 size_t* size) { | 285 size_t* size) { |
280 return handle.GetSize(size); | 286 return handle.GetSize(size); |
281 } | 287 } |
282 | 288 |
283 // Chromium mostly only uses the unique/private shmem as specified by | 289 // Chromium mostly only uses the unique/private shmem as specified by |
284 // "name == L"". The exception is in the StatsTable. | 290 // "name == L"". The exception is in the StatsTable. |
285 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { | 291 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 497 |
492 if (close_self) { | 498 if (close_self) { |
493 Unmap(); | 499 Unmap(); |
494 Close(); | 500 Close(); |
495 } | 501 } |
496 | 502 |
497 return true; | 503 return true; |
498 } | 504 } |
499 | 505 |
500 } // namespace base | 506 } // namespace base |
OLD | NEW |