OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/browser_io_surface_manager_mac.h" | 5 #include "content/browser/browser_io_surface_manager_mac.h" |
6 | 6 |
7 #include <servers/bootstrap.h> | 7 #include <servers/bootstrap.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 | 193 |
194 union { | 194 union { |
195 mach_msg_header_t header; | 195 mach_msg_header_t header; |
196 IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface; | 196 IOSurfaceManagerMsg_RegisterIOSurfaceReply register_io_surface; |
197 IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface; | 197 IOSurfaceManagerMsg_AcquireIOSurfaceReply acquire_io_surface; |
198 } reply = {{0}}; | 198 } reply = {{0}}; |
199 | 199 |
200 switch (request.msg.header.msgh_id) { | 200 switch (request.msg.header.msgh_id) { |
201 case IOSurfaceManagerHostMsg_RegisterIOSurface::ID: | 201 case IOSurfaceManagerHostMsg_RegisterIOSurface::ID: |
202 if (!HandleRegisterIOSurfaceRequest(request.msg.register_io_surface, | 202 HandleRegisterIOSurfaceRequest(request.msg.register_io_surface, |
203 &reply.register_io_surface)) { | 203 &reply.register_io_surface); |
204 return; | |
205 } | |
206 break; | 204 break; |
207 case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID: | 205 case IOSurfaceManagerHostMsg_UnregisterIOSurface::ID: |
208 HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface); | 206 HandleUnregisterIOSurfaceRequest(request.msg.unregister_io_surface); |
209 // Unregister requests are asynchronous and do not require a reply as | 207 // Unregister requests are asynchronous and do not require a reply as |
210 // there is no guarantee for how quickly an IO surface is removed from | 208 // there is no guarantee for how quickly an IO surface is removed from |
211 // the IOSurfaceManager instance after it has been deleted by a child | 209 // the IOSurfaceManager instance after it has been deleted by a child |
212 // process. | 210 // process. |
213 return; | 211 return; |
214 case IOSurfaceManagerHostMsg_AcquireIOSurface::ID: | 212 case IOSurfaceManagerHostMsg_AcquireIOSurface::ID: |
215 if (!HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface, | 213 HandleAcquireIOSurfaceRequest(request.msg.acquire_io_surface, |
216 &reply.acquire_io_surface)) { | 214 &reply.acquire_io_surface); |
217 return; | |
218 } | |
219 break; | 215 break; |
220 default: | 216 default: |
221 LOG(ERROR) << "Unknown message received!"; | 217 LOG(ERROR) << "Unknown message received!"; |
222 return; | 218 return; |
223 } | 219 } |
224 | 220 |
225 kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, | 221 kr = mach_msg(&reply.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, |
226 reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs, | 222 reply.header.msgh_size, 0, MACH_PORT_NULL, kSendReplyTimeoutMs, |
227 MACH_PORT_NULL); | 223 MACH_PORT_NULL); |
228 if (kr != KERN_SUCCESS) { | 224 if (kr != KERN_SUCCESS) { |
229 MACH_LOG(ERROR, kr) << "mach_msg"; | 225 MACH_LOG(ERROR, kr) << "mach_msg"; |
230 } | 226 } |
231 } | 227 } |
232 | 228 |
233 bool BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest( | 229 void BrowserIOSurfaceManager::HandleRegisterIOSurfaceRequest( |
234 const IOSurfaceManagerHostMsg_RegisterIOSurface& request, | 230 const IOSurfaceManagerHostMsg_RegisterIOSurface& request, |
235 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { | 231 IOSurfaceManagerMsg_RegisterIOSurfaceReply* reply) { |
236 base::AutoLock lock(lock_); | 232 base::AutoLock lock(lock_); |
237 | 233 |
| 234 reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits); |
| 235 reply->header.msgh_remote_port = request.header.msgh_remote_port; |
| 236 reply->header.msgh_size = sizeof(*reply); |
| 237 reply->body.msgh_descriptor_count = 0; |
| 238 reply->result = false; |
| 239 |
238 IOSurfaceManagerToken token; | 240 IOSurfaceManagerToken token; |
239 static_assert(sizeof(request.token_name) == sizeof(token.name), | 241 static_assert(sizeof(request.token_name) == sizeof(token.name), |
240 "Mach message token size doesn't match expectation."); | 242 "Mach message token size doesn't match expectation."); |
241 token.SetName(request.token_name); | 243 token.SetName(request.token_name); |
242 if (token.IsZero() || token != gpu_process_token_) { | 244 if (token.IsZero() || token != gpu_process_token_) { |
243 LOG(ERROR) << "Illegal message from non-GPU process!"; | 245 LOG(ERROR) << "Illegal message from non-GPU process!"; |
244 return false; | 246 return; |
245 } | 247 } |
246 | 248 |
247 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); | 249 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); |
248 io_surfaces_.add(key, make_scoped_ptr(new base::mac::ScopedMachSendRight( | 250 io_surfaces_.add(key, make_scoped_ptr(new base::mac::ScopedMachSendRight( |
249 request.io_surface_port.name))); | 251 request.io_surface_port.name))); |
250 | |
251 reply->header.msgh_bits = MACH_MSGH_BITS_REMOTE(request.header.msgh_bits); | |
252 reply->header.msgh_remote_port = request.header.msgh_remote_port; | |
253 reply->header.msgh_size = sizeof(*reply); | |
254 reply->result = true; | 252 reply->result = true; |
255 return true; | |
256 } | 253 } |
257 | 254 |
258 bool BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest( | 255 bool BrowserIOSurfaceManager::HandleUnregisterIOSurfaceRequest( |
259 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) { | 256 const IOSurfaceManagerHostMsg_UnregisterIOSurface& request) { |
260 base::AutoLock lock(lock_); | 257 base::AutoLock lock(lock_); |
261 | 258 |
262 IOSurfaceManagerToken token; | 259 IOSurfaceManagerToken token; |
263 static_assert(sizeof(request.token_name) == sizeof(token.name), | 260 static_assert(sizeof(request.token_name) == sizeof(token.name), |
264 "Mach message token size doesn't match expectation."); | 261 "Mach message token size doesn't match expectation."); |
265 token.SetName(request.token_name); | 262 token.SetName(request.token_name); |
266 if (token.IsZero() || token != gpu_process_token_) { | 263 if (token.IsZero() || token != gpu_process_token_) { |
267 LOG(ERROR) << "Illegal message from non-GPU process!"; | 264 LOG(ERROR) << "Illegal message from non-GPU process!"; |
268 return false; | 265 return false; |
269 } | 266 } |
270 | 267 |
271 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); | 268 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), request.client_id); |
272 io_surfaces_.erase(key); | 269 io_surfaces_.erase(key); |
273 return true; | 270 return true; |
274 } | 271 } |
275 | 272 |
276 bool BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest( | 273 void BrowserIOSurfaceManager::HandleAcquireIOSurfaceRequest( |
277 const IOSurfaceManagerHostMsg_AcquireIOSurface& request, | 274 const IOSurfaceManagerHostMsg_AcquireIOSurface& request, |
278 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { | 275 IOSurfaceManagerMsg_AcquireIOSurfaceReply* reply) { |
279 base::AutoLock lock(lock_); | 276 base::AutoLock lock(lock_); |
280 | 277 |
| 278 reply->header.msgh_bits = |
| 279 MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX; |
| 280 reply->header.msgh_remote_port = request.header.msgh_remote_port; |
| 281 reply->header.msgh_size = sizeof(*reply); |
| 282 reply->body.msgh_descriptor_count = 0; |
| 283 reply->result = false; |
| 284 reply->io_surface_port.name = MACH_PORT_NULL; |
| 285 reply->io_surface_port.disposition = 0; |
| 286 reply->io_surface_port.type = 0; |
| 287 |
281 IOSurfaceManagerToken token; | 288 IOSurfaceManagerToken token; |
282 static_assert(sizeof(request.token_name) == sizeof(token.name), | 289 static_assert(sizeof(request.token_name) == sizeof(token.name), |
283 "Mach message token size doesn't match expectation."); | 290 "Mach message token size doesn't match expectation."); |
284 token.SetName(request.token_name); | 291 token.SetName(request.token_name); |
285 auto child_process_id_it = child_process_ids_.find(token); | 292 auto child_process_id_it = child_process_ids_.find(token); |
286 if (child_process_id_it == child_process_ids_.end()) { | 293 if (child_process_id_it == child_process_ids_.end()) { |
287 LOG(ERROR) << "Illegal message from non-child process!"; | 294 LOG(ERROR) << "Illegal message from non-child process!"; |
288 return false; | 295 return; |
289 } | 296 } |
290 | 297 |
291 reply->header.msgh_bits = | 298 reply->result = true; |
292 MACH_MSGH_BITS_REMOTE(request.header.msgh_bits) | MACH_MSGH_BITS_COMPLEX; | |
293 reply->header.msgh_remote_port = request.header.msgh_remote_port; | |
294 reply->header.msgh_size = sizeof(*reply); | |
295 | |
296 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), | 299 IOSurfaceMapKey key(IOSurfaceId(request.io_surface_id), |
297 child_process_id_it->second); | 300 child_process_id_it->second); |
298 auto it = io_surfaces_.find(key); | 301 auto it = io_surfaces_.find(key); |
299 if (it == io_surfaces_.end()) { | 302 if (it == io_surfaces_.end()) { |
300 LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id; | 303 LOG(ERROR) << "Invalid Id for IOSurface " << request.io_surface_id; |
301 return true; | 304 return; |
302 } | 305 } |
303 | 306 |
304 reply->body.msgh_descriptor_count = 1; | 307 reply->body.msgh_descriptor_count = 1; |
305 reply->io_surface_port.name = it->second->get(); | 308 reply->io_surface_port.name = it->second->get(); |
306 reply->io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; | 309 reply->io_surface_port.disposition = MACH_MSG_TYPE_COPY_SEND; |
307 reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; | 310 reply->io_surface_port.type = MACH_MSG_PORT_DESCRIPTOR; |
308 return true; | |
309 } | 311 } |
310 | 312 |
311 } // namespace content | 313 } // namespace content |
OLD | NEW |