| 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/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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool SharedMemory::Delete(const std::string& name) { | 79 bool SharedMemory::Delete(const std::string& name) { |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool SharedMemory::Open(const std::string& name, bool read_only) { | 83 bool SharedMemory::Open(const std::string& name, bool read_only) { |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool SharedMemory::Map(size_t bytes) { | 87 bool SharedMemory::MapAt(off_t offset, size_t bytes) { |
| 88 if (mapped_file_ == -1) | 88 if (mapped_file_ == -1) |
| 89 return false; | 89 return false; |
| 90 | 90 |
| 91 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) | 91 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) |
| 92 return false; | 92 return false; |
| 93 | 93 |
| 94 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), | 94 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), |
| 95 MAP_SHARED, mapped_file_, 0); | 95 MAP_SHARED, mapped_file_, offset); |
| 96 | 96 |
| 97 bool mmap_succeeded = memory_ != MAP_FAILED && memory_ != NULL; | 97 bool mmap_succeeded = memory_ != MAP_FAILED && memory_ != NULL; |
| 98 if (mmap_succeeded) { | 98 if (mmap_succeeded) { |
| 99 mapped_size_ = bytes; | 99 mapped_size_ = bytes; |
| 100 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & | 100 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & |
| 101 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); | 101 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); |
| 102 } else { | 102 } else { |
| 103 memory_ = NULL; | 103 memory_ = NULL; |
| 104 } | 104 } |
| 105 | 105 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 new_handle->fd = new_fd; | 151 new_handle->fd = new_fd; |
| 152 new_handle->auto_close = true; | 152 new_handle->auto_close = true; |
| 153 | 153 |
| 154 if (close_self) | 154 if (close_self) |
| 155 Close(); | 155 Close(); |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| 158 | 158 |
| 159 } // namespace base | 159 } // namespace base |
| OLD | NEW |