| 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 <stdlib.h> | 9 #include <stdlib.h> |
| 9 | 10 |
| 10 #if defined(OS_POSIX) | 11 #if defined(OS_POSIX) |
| 11 #include <unistd.h> | 12 #include <unistd.h> |
| 12 #endif | 13 #endif |
| 13 | 14 |
| 14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 18 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
| 19 #include "components/nacl/common/nacl_messages.h" | 20 #include "components/nacl/common/nacl_messages.h" |
| 20 #include "components/nacl/loader/nacl_ipc_adapter.h" | 21 #include "components/nacl/loader/nacl_ipc_adapter.h" |
| 21 #include "components/nacl/loader/nacl_validation_db.h" | 22 #include "components/nacl/loader/nacl_validation_db.h" |
| 22 #include "components/nacl/loader/nacl_validation_query.h" | 23 #include "components/nacl/loader/nacl_validation_query.h" |
| 23 #include "ipc/ipc_channel_handle.h" | 24 #include "ipc/ipc_channel_handle.h" |
| 24 #include "ipc/ipc_switches.h" | 25 #include "ipc/ipc_switches.h" |
| 25 #include "ipc/ipc_sync_channel.h" | 26 #include "ipc/ipc_sync_channel.h" |
| 26 #include "ipc/ipc_sync_message_filter.h" | 27 #include "ipc/ipc_sync_message_filter.h" |
| 27 #include "native_client/src/public/chrome_main.h" | 28 #include "native_client/src/public/chrome_main.h" |
| 28 #include "native_client/src/public/nacl_app.h" | 29 #include "native_client/src/public/nacl_app.h" |
| 29 #include "native_client/src/public/nacl_file_info.h" | 30 #include "native_client/src/public/nacl_file_info.h" |
| 31 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| 30 | 32 |
| 31 #if defined(OS_POSIX) | 33 #if defined(OS_POSIX) |
| 32 #include "base/file_descriptor_posix.h" | 34 #include "base/file_descriptor_posix.h" |
| 33 #endif | 35 #endif |
| 34 | 36 |
| 35 #if defined(OS_LINUX) | 37 #if defined(OS_LINUX) |
| 36 #include "components/nacl/loader/nonsfi/irt_random.h" | 38 #include "components/nacl/loader/nonsfi/irt_random.h" |
| 37 #include "components/nacl/loader/nonsfi/nonsfi_main.h" | 39 #include "components/nacl/loader/nonsfi/nonsfi_main.h" |
| 38 #include "content/public/common/child_process_sandbox_support_linux.h" | 40 #include "content/public/common/child_process_sandbox_support_linux.h" |
| 39 #include "native_client/src/trusted/desc/nacl_desc_io.h" | 41 #include "native_client/src/trusted/desc/nacl_desc_io.h" |
| 40 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | |
| 41 #include "ppapi/nacl_irt/plugin_startup.h" | 42 #include "ppapi/nacl_irt/plugin_startup.h" |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
| 45 #include <fcntl.h> | 46 #include <fcntl.h> |
| 46 #include <io.h> | 47 #include <io.h> |
| 47 | 48 |
| 48 #include "content/public/common/sandbox_init.h" | 49 #include "content/public/common/sandbox_init.h" |
| 49 #endif | 50 #endif |
| 50 | 51 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 #if defined(OS_WIN) | 384 #if defined(OS_WIN) |
| 384 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 385 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
| 385 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 386 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
| 386 args->debug_stub_server_port_selected_handler_func = | 387 args->debug_stub_server_port_selected_handler_func = |
| 387 DebugStubPortSelectedHandler; | 388 DebugStubPortSelectedHandler; |
| 388 #endif | 389 #endif |
| 389 #if defined(OS_LINUX) | 390 #if defined(OS_LINUX) |
| 390 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 391 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
| 391 #endif | 392 #endif |
| 392 | 393 |
| 394 NaClFileInfo nexe_file_info; |
| 395 base::PlatformFile nexe_file = IPC::PlatformFileForTransitToPlatformFile( |
| 396 params.nexe_file); |
| 397 #if defined(OS_WIN) |
| 398 nexe_file_info.desc = |
| 399 _open_osfhandle(reinterpret_cast<intptr_t>(nexe_file), |
| 400 _O_RDONLY | _O_BINARY); |
| 401 #elif defined(OS_POSIX) |
| 402 nexe_file_info.desc = nexe_file; |
| 403 #else |
| 404 #error Unsupported target platform. |
| 405 #endif |
| 406 nexe_file_info.file_token.lo = params.nexe_token_lo; |
| 407 nexe_file_info.file_token.hi = params.nexe_token_hi; |
| 408 args->nexe_desc = NaClDescIoFromFileInfo(nexe_file_info, NACL_ABI_O_RDONLY); |
| 409 |
| 393 NaClChromeMainStartApp(nap, args); | 410 NaClChromeMainStartApp(nap, args); |
| 394 NOTREACHED(); | 411 NOTREACHED(); |
| 395 } | 412 } |
| 396 | 413 |
| 397 void NaClListener::StartNonSfi(const nacl::NaClStartParams& params) { | 414 void NaClListener::StartNonSfi(const nacl::NaClStartParams& params) { |
| 398 #if !defined(OS_LINUX) | 415 #if !defined(OS_LINUX) |
| 399 NOTREACHED() << "Non-SFI NaCl is only supported on Linux"; | 416 NOTREACHED() << "Non-SFI NaCl is only supported on Linux"; |
| 400 #else | 417 #else |
| 401 // Random number source initialization. | 418 // Random number source initialization. |
| 402 nacl::nonsfi::SetUrandomFd(base::GetUrandomFD()); | 419 nacl::nonsfi::SetUrandomFd(base::GetUrandomFD()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 CHECK(params.validation_cache_key.size() == 0); | 483 CHECK(params.validation_cache_key.size() == 0); |
| 467 CHECK(params.version.size() == 0); | 484 CHECK(params.version.size() == 0); |
| 468 // Ensure that a debug stub FD isn't passed through accidentally. | 485 // Ensure that a debug stub FD isn't passed through accidentally. |
| 469 CHECK(!params.enable_debug_stub); | 486 CHECK(!params.enable_debug_stub); |
| 470 CHECK(params.debug_stub_server_bound_socket.fd == -1); | 487 CHECK(params.debug_stub_server_bound_socket.fd == -1); |
| 471 | 488 |
| 472 CHECK(!params.uses_irt); | 489 CHECK(!params.uses_irt); |
| 473 CHECK(params.handles.empty()); | 490 CHECK(params.handles.empty()); |
| 474 | 491 |
| 475 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit()); | 492 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit()); |
| 493 CHECK(params.nexe_token_lo == 0); |
| 494 CHECK(params.nexe_token_hi == 0); |
| 476 nacl::nonsfi::MainStart( | 495 nacl::nonsfi::MainStart( |
| 477 NaClDescIoDescFromDescAllocCtor( | 496 NaClDescIoDescFromDescAllocCtor( |
| 478 IPC::PlatformFileForTransitToPlatformFile(params.nexe_file), | 497 IPC::PlatformFileForTransitToPlatformFile(params.nexe_file), |
| 479 NACL_ABI_O_RDONLY)); | 498 NACL_ABI_O_RDONLY)); |
| 480 #endif // defined(OS_LINUX) | 499 #endif // defined(OS_LINUX) |
| 481 } | 500 } |
| 482 | 501 |
| 483 IPC::ChannelHandle NaClListener::CreateTrustedListener( | 502 IPC::ChannelHandle NaClListener::CreateTrustedListener( |
| 484 base::MessageLoopProxy* message_loop_proxy, | 503 base::MessageLoopProxy* message_loop_proxy, |
| 485 base::WaitableEvent* shutdown_event) { | 504 base::WaitableEvent* shutdown_event) { |
| 486 // The argument passed to GenerateVerifiedChannelID() here MUST be "nacl". | 505 // The argument passed to GenerateVerifiedChannelID() here MUST be "nacl". |
| 487 // Using an alternate channel name prevents the pipe from being created on | 506 // Using an alternate channel name prevents the pipe from being created on |
| 488 // Windows when the sandbox is enabled. | 507 // Windows when the sandbox is enabled. |
| 489 IPC::ChannelHandle trusted_renderer_handle = | 508 IPC::ChannelHandle trusted_renderer_handle = |
| 490 IPC::Channel::GenerateVerifiedChannelID("nacl"); | 509 IPC::Channel::GenerateVerifiedChannelID("nacl"); |
| 491 trusted_listener_ = new NaClTrustedListener( | 510 trusted_listener_ = new NaClTrustedListener( |
| 492 trusted_renderer_handle, io_thread_.message_loop_proxy().get()); | 511 trusted_renderer_handle, io_thread_.message_loop_proxy().get()); |
| 493 #if defined(OS_POSIX) | 512 #if defined(OS_POSIX) |
| 494 trusted_renderer_handle.socket = base::FileDescriptor( | 513 trusted_renderer_handle.socket = base::FileDescriptor( |
| 495 trusted_listener_->TakeClientFileDescriptor(), true); | 514 trusted_listener_->TakeClientFileDescriptor(), true); |
| 496 #endif | 515 #endif |
| 497 return trusted_renderer_handle; | 516 return trusted_renderer_handle; |
| 498 } | 517 } |
| OLD | NEW |