| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/shared_memory.h" | 5 #include "base/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> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 | 12 |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/platform_thread.h" | 15 #include "base/platform_thread.h" |
| 16 #include "base/safe_strerror_posix.h" | 16 #include "base/safe_strerror_posix.h" |
| 17 #include "base/thread_restrictions.h" | |
| 18 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 19 | 18 |
| 20 namespace base { | 19 namespace base { |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 // Paranoia. Semaphores and shared memory segments should live in different | 22 // Paranoia. Semaphores and shared memory segments should live in different |
| 24 // namespaces, but who knows what's out there. | 23 // namespaces, but who knows what's out there. |
| 25 const char kSemaphoreSuffix[] = "-sem"; | 24 const char kSemaphoreSuffix[] = "-sem"; |
| 26 } | 25 } |
| 27 | 26 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // Chromium mostly only use the unique/private shmem as specified by | 139 // Chromium mostly only use the unique/private shmem as specified by |
| 141 // "name == L"". The exception is in the StatsTable. | 140 // "name == L"". The exception is in the StatsTable. |
| 142 // TODO(jrg): there is no way to "clean up" all unused named shmem if | 141 // TODO(jrg): there is no way to "clean up" all unused named shmem if |
| 143 // we restart from a crash. (That isn't a new problem, but it is a problem.) | 142 // we restart from a crash. (That isn't a new problem, but it is a problem.) |
| 144 // In case we want to delete it later, it may be useful to save the value | 143 // In case we want to delete it later, it may be useful to save the value |
| 145 // of mem_filename after FilePathForMemoryName(). | 144 // of mem_filename after FilePathForMemoryName(). |
| 146 bool SharedMemory::CreateOrOpen(const std::string& name, | 145 bool SharedMemory::CreateOrOpen(const std::string& name, |
| 147 int posix_flags, uint32 size) { | 146 int posix_flags, uint32 size) { |
| 148 DCHECK(mapped_file_ == -1); | 147 DCHECK(mapped_file_ == -1); |
| 149 | 148 |
| 150 // This function theoretically can block on the disk, but realistically | |
| 151 // the temporary files we create will just go into the buffer cache | |
| 152 // and be deleted before they ever make it out to disk. | |
| 153 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 154 | |
| 155 file_util::ScopedFILE file_closer; | 149 file_util::ScopedFILE file_closer; |
| 156 FILE *fp; | 150 FILE *fp; |
| 157 | 151 |
| 158 FilePath path; | 152 FilePath path; |
| 159 if (name.empty()) { | 153 if (name.empty()) { |
| 160 // It doesn't make sense to have a read-only private piece of shmem | 154 // It doesn't make sense to have a read-only private piece of shmem |
| 161 DCHECK(posix_flags & (O_RDWR | O_WRONLY)); | 155 DCHECK(posix_flags & (O_RDWR | O_WRONLY)); |
| 162 | 156 |
| 163 // Q: Why not use the shm_open() etc. APIs? | 157 // Q: Why not use the shm_open() etc. APIs? |
| 164 // A: Because they're limited to 4mb on OS X. FFFFFFFUUUUUUUUUUU | 158 // A: Because they're limited to 4mb on OS X. FFFFFFFUUUUUUUUUUU |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 315 |
| 322 void SharedMemory::Unlock() { | 316 void SharedMemory::Unlock() { |
| 323 LockOrUnlockCommon(F_ULOCK); | 317 LockOrUnlockCommon(F_ULOCK); |
| 324 } | 318 } |
| 325 | 319 |
| 326 SharedMemoryHandle SharedMemory::handle() const { | 320 SharedMemoryHandle SharedMemory::handle() const { |
| 327 return FileDescriptor(mapped_file_, false); | 321 return FileDescriptor(mapped_file_, false); |
| 328 } | 322 } |
| 329 | 323 |
| 330 } // namespace base | 324 } // namespace base |
| OLD | NEW |