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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 | 84 |
85 bool SharedMemory::Map(uint32 bytes) { | 85 bool SharedMemory::Map(uint32 bytes) { |
86 if (mapped_file_ == -1) | 86 if (mapped_file_ == -1) |
87 return false; | 87 return false; |
88 | 88 |
89 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), | 89 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), |
90 MAP_SHARED, mapped_file_, 0); | 90 MAP_SHARED, mapped_file_, 0); |
91 | 91 |
92 bool mmap_succeeded = memory_ != MAP_FAILED && memory_ != NULL; | 92 bool mmap_succeeded = memory_ != MAP_FAILED && memory_ != NULL; |
93 if (mmap_succeeded) | 93 if (mmap_succeeded) { |
94 mapped_size_ = bytes; | 94 mapped_size_ = bytes; |
95 else | 95 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & |
| 96 (SharedMemory::kMapMinimumAlignment - 1)); |
| 97 } else { |
96 memory_ = NULL; | 98 memory_ = NULL; |
| 99 } |
97 | 100 |
98 return mmap_succeeded; | 101 return mmap_succeeded; |
99 } | 102 } |
100 | 103 |
101 bool SharedMemory::Unmap() { | 104 bool SharedMemory::Unmap() { |
102 if (memory_ == NULL) | 105 if (memory_ == NULL) |
103 return false; | 106 return false; |
104 | 107 |
105 if (munmap(memory_, mapped_size_) < 0) | 108 if (munmap(memory_, mapped_size_) < 0) |
106 DPLOG(ERROR) << "munmap"; | 109 DPLOG(ERROR) << "munmap"; |
(...skipping 24 matching lines...) Expand all Loading... |
131 NOTIMPLEMENTED(); | 134 NOTIMPLEMENTED(); |
132 } | 135 } |
133 | 136 |
134 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, | 137 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
135 SharedMemoryHandle *new_handle, | 138 SharedMemoryHandle *new_handle, |
136 bool close_self) { | 139 bool close_self) { |
137 return false; | 140 return false; |
138 } | 141 } |
139 | 142 |
140 } // namespace base | 143 } // namespace base |
OLD | NEW |