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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 } | 132 } |
133 | 133 |
134 void SharedMemory::Close() { | 134 void SharedMemory::Close() { |
135 if (mapped_file_ > 0) { | 135 if (mapped_file_ > 0) { |
136 if (close(mapped_file_) < 0) | 136 if (close(mapped_file_) < 0) |
137 DPLOG(ERROR) << "close"; | 137 DPLOG(ERROR) << "close"; |
138 mapped_file_ = -1; | 138 mapped_file_ = -1; |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 void SharedMemory::LockDeprecated() { | |
143 NOTIMPLEMENTED(); | |
144 } | |
145 | |
146 void SharedMemory::UnlockDeprecated() { | |
147 NOTIMPLEMENTED(); | |
148 } | |
149 | |
150 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, | 142 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
151 SharedMemoryHandle *new_handle, | 143 SharedMemoryHandle *new_handle, |
152 bool close_self, | 144 bool close_self, |
153 ShareMode share_mode) { | 145 ShareMode share_mode) { |
154 if (share_mode == SHARE_READONLY) { | 146 if (share_mode == SHARE_READONLY) { |
155 // Untrusted code can't create descriptors or handles, which is needed to | 147 // Untrusted code can't create descriptors or handles, which is needed to |
156 // drop permissions. | 148 // drop permissions. |
157 return false; | 149 return false; |
158 } | 150 } |
159 const int new_fd = dup(mapped_file_); | 151 const int new_fd = dup(mapped_file_); |
160 if (new_fd < 0) { | 152 if (new_fd < 0) { |
161 DPLOG(ERROR) << "dup() failed."; | 153 DPLOG(ERROR) << "dup() failed."; |
162 return false; | 154 return false; |
163 } | 155 } |
164 | 156 |
165 new_handle->fd = new_fd; | 157 new_handle->fd = new_fd; |
166 new_handle->auto_close = true; | 158 new_handle->auto_close = true; |
167 | 159 |
168 if (close_self) { | 160 if (close_self) { |
169 Unmap(); | 161 Unmap(); |
170 Close(); | 162 Close(); |
171 } | 163 } |
172 return true; | 164 return true; |
173 } | 165 } |
174 | 166 |
175 } // namespace base | 167 } // namespace base |
OLD | NEW |