| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 if (access(dir.value().c_str(), W_OK | X_OK) < 0) { | 304 if (access(dir.value().c_str(), W_OK | X_OK) < 0) { |
| 305 PLOG(ERROR) << "Unable to access(W_OK|X_OK) " << dir.value(); | 305 PLOG(ERROR) << "Unable to access(W_OK|X_OK) " << dir.value(); |
| 306 if (dir.value() == "/dev/shm") { | 306 if (dir.value() == "/dev/shm") { |
| 307 LOG(FATAL) << "This is frequently caused by incorrect permissions on " | 307 LOG(FATAL) << "This is frequently caused by incorrect permissions on " |
| 308 << "/dev/shm. Try 'sudo chmod 1777 /dev/shm' to fix."; | 308 << "/dev/shm. Try 'sudo chmod 1777 /dev/shm' to fix."; |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 return false; | 311 return false; |
| 312 } | 312 } |
| 313 | 313 |
| 314 return PrepareMapFile(fp.Pass(), readonly_fd.Pass()); | 314 return PrepareMapFile(std::move(fp), std::move(readonly_fd)); |
| 315 } | 315 } |
| 316 | 316 |
| 317 // Our current implementation of shmem is with mmap()ing of files. | 317 // Our current implementation of shmem is with mmap()ing of files. |
| 318 // These files need to be deleted explicitly. | 318 // These files need to be deleted explicitly. |
| 319 // In practice this call is only needed for unit tests. | 319 // In practice this call is only needed for unit tests. |
| 320 bool SharedMemory::Delete(const std::string& name) { | 320 bool SharedMemory::Delete(const std::string& name) { |
| 321 FilePath path; | 321 FilePath path; |
| 322 if (!FilePathForMemoryName(name, &path)) | 322 if (!FilePathForMemoryName(name, &path)) |
| 323 return false; | 323 return false; |
| 324 | 324 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 336 | 336 |
| 337 read_only_ = read_only; | 337 read_only_ = read_only; |
| 338 | 338 |
| 339 const char *mode = read_only ? "r" : "r+"; | 339 const char *mode = read_only ? "r" : "r+"; |
| 340 ScopedFILE fp(base::OpenFile(path, mode)); | 340 ScopedFILE fp(base::OpenFile(path, mode)); |
| 341 ScopedFD readonly_fd(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY))); | 341 ScopedFD readonly_fd(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY))); |
| 342 if (!readonly_fd.is_valid()) { | 342 if (!readonly_fd.is_valid()) { |
| 343 DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed"; | 343 DPLOG(ERROR) << "open(\"" << path.value() << "\", O_RDONLY) failed"; |
| 344 return false; | 344 return false; |
| 345 } | 345 } |
| 346 return PrepareMapFile(fp.Pass(), readonly_fd.Pass()); | 346 return PrepareMapFile(std::move(fp), std::move(readonly_fd)); |
| 347 } | 347 } |
| 348 #endif // !defined(OS_ANDROID) | 348 #endif // !defined(OS_ANDROID) |
| 349 | 349 |
| 350 bool SharedMemory::MapAt(off_t offset, size_t bytes) { | 350 bool SharedMemory::MapAt(off_t offset, size_t bytes) { |
| 351 if (mapped_file_ == -1) | 351 if (mapped_file_ == -1) |
| 352 return false; | 352 return false; |
| 353 | 353 |
| 354 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) | 354 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) |
| 355 return false; | 355 return false; |
| 356 | 356 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 506 |
| 507 if (close_self) { | 507 if (close_self) { |
| 508 Unmap(); | 508 Unmap(); |
| 509 Close(); | 509 Close(); |
| 510 } | 510 } |
| 511 | 511 |
| 512 return true; | 512 return true; |
| 513 } | 513 } |
| 514 | 514 |
| 515 } // namespace base | 515 } // namespace base |
| OLD | NEW |