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