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