| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 DCHECK_GE(handle.fd, 0); | 169 DCHECK_GE(handle.fd, 0); |
| 170 if (close(handle.fd) < 0) | 170 if (close(handle.fd) < 0) |
| 171 DPLOG(ERROR) << "close"; | 171 DPLOG(ERROR) << "close"; |
| 172 } | 172 } |
| 173 | 173 |
| 174 // static | 174 // static |
| 175 size_t SharedMemory::GetHandleLimit() { | 175 size_t SharedMemory::GetHandleLimit() { |
| 176 return base::GetMaxFds(); | 176 return base::GetMaxFds(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 // static |
| 180 SharedMemoryHandle SharedMemory::ShallowCopyHandle( |
| 181 const SharedMemoryHandle& handle) { |
| 182 SharedMemoryHandle new_handle = handle; |
| 183 new_handle.auto_close = false; |
| 184 return new_handle; |
| 185 } |
| 186 |
| 187 // static |
| 188 SharedMemoryHandle SharedMemory::DeepCopyHandle( |
| 189 const SharedMemoryHandle& handle, |
| 190 bool clean_up_resources_on_destruction) { |
| 191 int duped_handle = HANDLE_EINTR(dup(handle.fd)); |
| 192 if (duped_handle < 0) |
| 193 return base::SharedMemory::NULLHandle(); |
| 194 return base::FileDescriptor(duped_handle, clean_up_resources_on_destruction); |
| 195 } |
| 196 |
| 179 bool SharedMemory::CreateAndMapAnonymous(size_t size) { | 197 bool SharedMemory::CreateAndMapAnonymous(size_t size) { |
| 180 return CreateAnonymous(size) && Map(size); | 198 return CreateAnonymous(size) && Map(size); |
| 181 } | 199 } |
| 182 | 200 |
| 183 #if !defined(OS_ANDROID) | 201 #if !defined(OS_ANDROID) |
| 184 // Chromium mostly only uses the unique/private shmem as specified by | 202 // Chromium mostly only uses the unique/private shmem as specified by |
| 185 // "name == L"". The exception is in the StatsTable. | 203 // "name == L"". The exception is in the StatsTable. |
| 186 // TODO(jrg): there is no way to "clean up" all unused named shmem if | 204 // TODO(jrg): there is no way to "clean up" all unused named shmem if |
| 187 // we restart from a crash. (That isn't a new problem, but it is a problem.) | 205 // we restart from a crash. (That isn't a new problem, but it is a problem.) |
| 188 // In case we want to delete it later, it may be useful to save the value | 206 // In case we want to delete it later, it may be useful to save the value |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 542 |
| 525 if (close_self) { | 543 if (close_self) { |
| 526 Unmap(); | 544 Unmap(); |
| 527 Close(); | 545 Close(); |
| 528 } | 546 } |
| 529 | 547 |
| 530 return true; | 548 return true; |
| 531 } | 549 } |
| 532 | 550 |
| 533 } // namespace base | 551 } // namespace base |
| OLD | NEW |