| 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 <sys/mman.h> | 9 #include <sys/mman.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return base::SharedMemory::NULLHandle(); | 198 return base::SharedMemory::NULLHandle(); |
| 199 return base::FileDescriptor(duped_handle, clean_up_resources_on_destruction); | 199 return base::FileDescriptor(duped_handle, clean_up_resources_on_destruction); |
| 200 } | 200 } |
| 201 #endif | 201 #endif |
| 202 | 202 |
| 203 bool SharedMemory::CreateAndMapAnonymous(size_t size) { | 203 bool SharedMemory::CreateAndMapAnonymous(size_t size) { |
| 204 return CreateAnonymous(size) && Map(size); | 204 return CreateAnonymous(size) && Map(size); |
| 205 } | 205 } |
| 206 | 206 |
| 207 #if !defined(OS_ANDROID) | 207 #if !defined(OS_ANDROID) |
| 208 // static |
| 209 int SharedMemory::GetSizeFromSharedMemoryHandle( |
| 210 const SharedMemoryHandle& handle) { |
| 211 struct stat st; |
| 212 if (fstat(handle.fd, &st) != 0) |
| 213 return st.st_size; |
| 214 return -1; |
| 215 } |
| 216 |
| 208 // Chromium mostly only uses the unique/private shmem as specified by | 217 // Chromium mostly only uses the unique/private shmem as specified by |
| 209 // "name == L"". The exception is in the StatsTable. | 218 // "name == L"". The exception is in the StatsTable. |
| 210 // TODO(jrg): there is no way to "clean up" all unused named shmem if | 219 // TODO(jrg): there is no way to "clean up" all unused named shmem if |
| 211 // we restart from a crash. (That isn't a new problem, but it is a problem.) | 220 // we restart from a crash. (That isn't a new problem, but it is a problem.) |
| 212 // In case we want to delete it later, it may be useful to save the value | 221 // In case we want to delete it later, it may be useful to save the value |
| 213 // of mem_filename after FilePathForMemoryName(). | 222 // of mem_filename after FilePathForMemoryName(). |
| 214 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { | 223 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { |
| 215 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466437 | 224 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466437 |
| 216 // is fixed. | 225 // is fixed. |
| 217 tracked_objects::ScopedTracker tracking_profile1( | 226 tracked_objects::ScopedTracker tracking_profile1( |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 557 |
| 549 if (close_self) { | 558 if (close_self) { |
| 550 Unmap(); | 559 Unmap(); |
| 551 Close(); | 560 Close(); |
| 552 } | 561 } |
| 553 | 562 |
| 554 return true; | 563 return true; |
| 555 } | 564 } |
| 556 | 565 |
| 557 } // namespace base | 566 } // namespace base |
| OLD | NEW |