| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 // static | 85 // static |
| 86 SharedMemoryHandle SharedMemory::NULLHandle() { | 86 SharedMemoryHandle SharedMemory::NULLHandle() { |
| 87 return SharedMemoryHandle(); | 87 return SharedMemoryHandle(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // static | 90 // static |
| 91 void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { | 91 void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { |
| 92 DCHECK_GE(handle.fd, 0); | 92 DCHECK_GE(handle.fd, 0); |
| 93 if (HANDLE_EINTR(close(handle.fd)) < 0) | 93 if (HANDLE_EINTR(close(handle.fd)) < 0) |
| 94 PLOG(ERROR) << "close"; | 94 DPLOG(ERROR) << "close"; |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { | 97 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { |
| 98 return CreateAnonymous(size) && Map(size); | 98 return CreateAnonymous(size) && Map(size); |
| 99 } | 99 } |
| 100 | 100 |
| 101 bool SharedMemory::CreateAnonymous(uint32 size) { | 101 bool SharedMemory::CreateAnonymous(uint32 size) { |
| 102 return CreateNamed("", false, size); | 102 return CreateNamed("", false, size); |
| 103 } | 103 } |
| 104 | 104 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 created_size_ = size; | 168 created_size_ = size; |
| 169 } | 169 } |
| 170 if (fp == NULL) { | 170 if (fp == NULL) { |
| 171 #if !defined(OS_MACOSX) | 171 #if !defined(OS_MACOSX) |
| 172 PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed"; | 172 PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed"; |
| 173 FilePath dir = path.DirName(); | 173 FilePath dir = path.DirName(); |
| 174 if (access(dir.value().c_str(), W_OK | X_OK) < 0) { | 174 if (access(dir.value().c_str(), W_OK | X_OK) < 0) { |
| 175 PLOG(ERROR) << "Unable to access(W_OK|X_OK) " << dir.value(); | 175 PLOG(ERROR) << "Unable to access(W_OK|X_OK) " << dir.value(); |
| 176 if (dir.value() == "/dev/shm") { | 176 if (dir.value() == "/dev/shm") { |
| 177 LOG(FATAL) << "This is frequently caused by incorrect permissions on " | 177 LOG(FATAL) << "This is frequently caused by incorrect permissions on " |
| 178 << "/dev/shm. Try 'sudo chmod 1777 /dev/shm' to fix."; | 178 << "/dev/shm. Try 'sudo chmod 1777 /dev/shm' to fix."; |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 #else | 181 #else |
| 182 PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed"; | 182 PLOG(ERROR) << "Creating shared memory in " << path.value() << " failed"; |
| 183 #endif | 183 #endif |
| 184 return false; | 184 return false; |
| 185 } | 185 } |
| 186 | 186 |
| 187 return PrepareMapFile(fp); | 187 return PrepareMapFile(fp); |
| 188 } | 188 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 new_handle->fd = new_fd; | 365 new_handle->fd = new_fd; |
| 366 new_handle->auto_close = true; | 366 new_handle->auto_close = true; |
| 367 | 367 |
| 368 if (close_self) | 368 if (close_self) |
| 369 Close(); | 369 Close(); |
| 370 | 370 |
| 371 return true; | 371 return true; |
| 372 } | 372 } |
| 373 | 373 |
| 374 } // namespace base | 374 } // namespace base |
| OLD | NEW |