OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/loader/nacl_listener.h" | 5 #include "components/nacl/loader/nacl_listener.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 IPC::Channel::GenerateVerifiedChannelID("nacl"), | 330 IPC::Channel::GenerateVerifiedChannelID("nacl"), |
331 io_thread_.message_loop_proxy().get(), | 331 io_thread_.message_loop_proxy().get(), |
332 &shutdown_event_); | 332 &shutdown_event_); |
333 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 333 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
334 browser_handle, | 334 browser_handle, |
335 ppapi_renderer_handle, | 335 ppapi_renderer_handle, |
336 trusted_listener_->TakeClientChannelHandle(), | 336 trusted_listener_->TakeClientChannelHandle(), |
337 manifest_service_handle))) | 337 manifest_service_handle))) |
338 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; | 338 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; |
339 | 339 |
340 std::vector<nacl::FileDescriptor> handles = params.handles; | 340 std::vector<IPC::PlatformFileForTransit> handles = params.handles; |
341 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | 341 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); |
342 if (args == NULL) { | 342 if (args == NULL) { |
343 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; | 343 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; |
344 return; | 344 return; |
345 } | 345 } |
346 | 346 |
347 #if defined(OS_LINUX) || defined(OS_MACOSX) | 347 #if defined(OS_LINUX) || defined(OS_MACOSX) |
348 args->number_of_cores = number_of_cores_; | 348 args->number_of_cores = number_of_cores_; |
349 args->create_memory_object_func = CreateMemoryObject; | 349 args->create_memory_object_func = CreateMemoryObject; |
350 # if defined(OS_MACOSX) | 350 # if defined(OS_MACOSX) |
351 CHECK(handles.size() >= 1); | 351 CHECK(!handles.empty()); |
352 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); | 352 g_shm_fd = IPC::PlatformFileForTransitToPlatformFile(handles.back()); |
353 handles.pop_back(); | 353 handles.pop_back(); |
354 # endif | 354 # endif |
355 #endif | 355 #endif |
356 | 356 |
357 DCHECK(params.process_type != nacl::kUnknownNaClProcessType); | 357 DCHECK(params.process_type != nacl::kUnknownNaClProcessType); |
358 CHECK(handles.size() >= 1); | 358 CHECK(!handles.empty()); |
359 NaClHandle irt_handle = nacl::ToNativeHandle(handles[handles.size() - 1]); | 359 NaClHandle irt_handle = |
| 360 IPC::PlatformFileForTransitToPlatformFile(handles.back()); |
360 handles.pop_back(); | 361 handles.pop_back(); |
361 | 362 |
362 #if defined(OS_WIN) | 363 #if defined(OS_WIN) |
363 args->irt_fd = _open_osfhandle(reinterpret_cast<intptr_t>(irt_handle), | 364 args->irt_fd = _open_osfhandle(reinterpret_cast<intptr_t>(irt_handle), |
364 _O_RDONLY | _O_BINARY); | 365 _O_RDONLY | _O_BINARY); |
365 if (args->irt_fd < 0) { | 366 if (args->irt_fd < 0) { |
366 LOG(ERROR) << "_open_osfhandle() failed"; | 367 LOG(ERROR) << "_open_osfhandle() failed"; |
367 return; | 368 return; |
368 } | 369 } |
369 #else | 370 #else |
370 args->irt_fd = irt_handle; | 371 args->irt_fd = irt_handle; |
371 #endif | 372 #endif |
372 | 373 |
373 if (params.validation_cache_enabled) { | 374 if (params.validation_cache_enabled) { |
374 // SHA256 block size. | 375 // SHA256 block size. |
375 CHECK_EQ(params.validation_cache_key.length(), (size_t) 64); | 376 CHECK_EQ(params.validation_cache_key.length(), (size_t) 64); |
376 // The cache structure is not freed and exists until the NaCl process exits. | 377 // The cache structure is not freed and exists until the NaCl process exits. |
377 args->validation_cache = CreateValidationCache( | 378 args->validation_cache = CreateValidationCache( |
378 new BrowserValidationDBProxy(this), params.validation_cache_key, | 379 new BrowserValidationDBProxy(this), params.validation_cache_key, |
379 params.version); | 380 params.version); |
380 } | 381 } |
381 | 382 |
382 CHECK(handles.size() == 1); | 383 CHECK(handles.size() == 1); |
383 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]); | 384 args->imc_bootstrap_handle = |
| 385 IPC::PlatformFileForTransitToPlatformFile(handles[0]); |
384 args->enable_debug_stub = params.enable_debug_stub; | 386 args->enable_debug_stub = params.enable_debug_stub; |
385 | 387 |
386 // Now configure parts that depend on process type. | 388 // Now configure parts that depend on process type. |
387 // Start with stricter settings. | 389 // Start with stricter settings. |
388 args->enable_exception_handling = 0; | 390 args->enable_exception_handling = 0; |
389 args->enable_dyncode_syscalls = 0; | 391 args->enable_dyncode_syscalls = 0; |
390 // pnacl_mode=1 mostly disables things (IRT interfaces and syscalls). | 392 // pnacl_mode=1 mostly disables things (IRT interfaces and syscalls). |
391 args->pnacl_mode = 1; | 393 args->pnacl_mode = 1; |
392 // Bound the initial nexe's code segment size under PNaCl to reduce the | 394 // Bound the initial nexe's code segment size under PNaCl to reduce the |
393 // chance of a code spraying attack succeeding (see | 395 // chance of a code spraying attack succeeding (see |
(...skipping 10 matching lines...) Expand all Loading... |
404 args->initial_nexe_max_code_bytes = 0; | 406 args->initial_nexe_max_code_bytes = 0; |
405 } else if (params.process_type == nacl::kPNaClTranslatorProcessType) { | 407 } else if (params.process_type == nacl::kPNaClTranslatorProcessType) { |
406 // Transitioning the PNaCl translators to use the IRT again: | 408 // Transitioning the PNaCl translators to use the IRT again: |
407 // https://code.google.com/p/nativeclient/issues/detail?id=3914. | 409 // https://code.google.com/p/nativeclient/issues/detail?id=3914. |
408 // Once done, this can be removed. | 410 // Once done, this can be removed. |
409 args->irt_load_optional = 1; | 411 args->irt_load_optional = 1; |
410 args->pnacl_mode = 0; | 412 args->pnacl_mode = 0; |
411 } | 413 } |
412 | 414 |
413 #if defined(OS_LINUX) || defined(OS_MACOSX) | 415 #if defined(OS_LINUX) || defined(OS_MACOSX) |
414 args->debug_stub_server_bound_socket_fd = nacl::ToNativeHandle( | 416 args->debug_stub_server_bound_socket_fd = |
415 params.debug_stub_server_bound_socket); | 417 IPC::PlatformFileForTransitToPlatformFile( |
| 418 params.debug_stub_server_bound_socket); |
416 #endif | 419 #endif |
417 #if defined(OS_WIN) | 420 #if defined(OS_WIN) |
418 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 421 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
419 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 422 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
420 args->debug_stub_server_port_selected_handler_func = | 423 args->debug_stub_server_port_selected_handler_func = |
421 DebugStubPortSelectedHandler; | 424 DebugStubPortSelectedHandler; |
422 #endif | 425 #endif |
423 #if defined(OS_LINUX) | 426 #if defined(OS_LINUX) |
424 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 427 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
425 #endif | 428 #endif |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 467 } |
465 | 468 |
466 void NaClListener::OnFileTokenResolved( | 469 void NaClListener::OnFileTokenResolved( |
467 uint64_t token_lo, | 470 uint64_t token_lo, |
468 uint64_t token_hi, | 471 uint64_t token_hi, |
469 IPC::PlatformFileForTransit ipc_fd, | 472 IPC::PlatformFileForTransit ipc_fd, |
470 base::FilePath file_path) { | 473 base::FilePath file_path) { |
471 resolved_cb_.Run(ipc_fd, file_path); | 474 resolved_cb_.Run(ipc_fd, file_path); |
472 resolved_cb_.Reset(); | 475 resolved_cb_.Reset(); |
473 } | 476 } |
OLD | NEW |