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