| 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::POSIX; | 56 group = SharedMemoryHandle::MACH; |
| 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::POSIX), | 178 : type(SharedMemoryHandle::MACH), |
| 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 } |
| 182 | 192 |
| 183 SharedMemory::SharedMemory() | 193 SharedMemory::SharedMemory() |
| 184 : mapped_memory_mechanism_(SharedMemoryHandle::POSIX), | 194 : mapped_memory_mechanism_(SharedMemoryHandle::POSIX), |
| 185 readonly_mapped_file_(-1), | 195 readonly_mapped_file_(-1), |
| 186 mapped_size_(0), | 196 mapped_size_(0), |
| 187 memory_(NULL), | 197 memory_(NULL), |
| 188 read_only_(false), | 198 read_only_(false), |
| 189 requested_size_(0) {} | 199 requested_size_(0) {} |
| 190 | 200 |
| 191 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only) | 201 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 return CreateAnonymousPosix(size) && Map(size); | 266 return CreateAnonymousPosix(size) && Map(size); |
| 257 } | 267 } |
| 258 | 268 |
| 259 bool SharedMemory::CreateAnonymousPosix(size_t size) { | 269 bool SharedMemory::CreateAnonymousPosix(size_t size) { |
| 260 SharedMemoryCreateOptions options; | 270 SharedMemoryCreateOptions options; |
| 261 options.type = SharedMemoryHandle::POSIX; | 271 options.type = SharedMemoryHandle::POSIX; |
| 262 options.size = size; | 272 options.size = size; |
| 263 return Create(options); | 273 return Create(options); |
| 264 } | 274 } |
| 265 | 275 |
| 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 | |
| 282 // static | 276 // static |
| 283 bool SharedMemory::GetSizeFromSharedMemoryHandle( | 277 bool SharedMemory::GetSizeFromSharedMemoryHandle( |
| 284 const SharedMemoryHandle& handle, | 278 const SharedMemoryHandle& handle, |
| 285 size_t* size) { | 279 size_t* size) { |
| 286 return handle.GetSize(size); | 280 return handle.GetSize(size); |
| 287 } | 281 } |
| 288 | 282 |
| 289 // Chromium mostly only uses the unique/private shmem as specified by | 283 // Chromium mostly only uses the unique/private shmem as specified by |
| 290 // "name == L"". The exception is in the StatsTable. | 284 // "name == L"". The exception is in the StatsTable. |
| 291 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { | 285 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 491 |
| 498 if (close_self) { | 492 if (close_self) { |
| 499 Unmap(); | 493 Unmap(); |
| 500 Close(); | 494 Close(); |
| 501 } | 495 } |
| 502 | 496 |
| 503 return true; | 497 return true; |
| 504 } | 498 } |
| 505 | 499 |
| 506 } // namespace base | 500 } // namespace base |
| OLD | NEW |