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 } | 411 } |
395 | 412 |
396 void NaClListener::StartNonSfi(const nacl::NaClStartParams& params) { | 413 void NaClListener::StartNonSfi(const nacl::NaClStartParams& params) { |
397 #if !defined(OS_LINUX) | 414 #if !defined(OS_LINUX) |
398 NOTREACHED() << "Non-SFI NaCl is only supported on Linux"; | 415 NOTREACHED() << "Non-SFI NaCl is only supported on Linux"; |
399 #else | 416 #else |
400 // Random number source initialization. | 417 // Random number source initialization. |
401 nacl::nonsfi::SetUrandomFd(base::GetUrandomFD()); | 418 nacl::nonsfi::SetUrandomFd(base::GetUrandomFD()); |
402 | 419 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 CHECK(params.validation_cache_key.size() == 0); | 482 CHECK(params.validation_cache_key.size() == 0); |
466 CHECK(params.version.size() == 0); | 483 CHECK(params.version.size() == 0); |
467 // Ensure that a debug stub FD isn't passed through accidentally. | 484 // Ensure that a debug stub FD isn't passed through accidentally. |
468 CHECK(!params.enable_debug_stub); | 485 CHECK(!params.enable_debug_stub); |
469 CHECK(params.debug_stub_server_bound_socket.fd == -1); | 486 CHECK(params.debug_stub_server_bound_socket.fd == -1); |
470 | 487 |
471 CHECK(!params.uses_irt); | 488 CHECK(!params.uses_irt); |
472 CHECK(params.handles.empty()); | 489 CHECK(params.handles.empty()); |
473 | 490 |
474 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit()); | 491 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit()); |
| 492 CHECK(params.nexe_token_lo == 0); |
| 493 CHECK(params.nexe_token_hi == 0); |
475 nacl::nonsfi::MainStart( | 494 nacl::nonsfi::MainStart( |
476 NaClDescIoDescFromDescAllocCtor( | 495 NaClDescIoDescFromDescAllocCtor( |
477 IPC::PlatformFileForTransitToPlatformFile(params.nexe_file), | 496 IPC::PlatformFileForTransitToPlatformFile(params.nexe_file), |
478 NACL_ABI_O_RDONLY)); | 497 NACL_ABI_O_RDONLY)); |
479 #endif // defined(OS_LINUX) | 498 #endif // defined(OS_LINUX) |
480 } | 499 } |
481 | 500 |
482 IPC::ChannelHandle NaClListener::CreateTrustedListener( | 501 IPC::ChannelHandle NaClListener::CreateTrustedListener( |
483 base::MessageLoopProxy* message_loop_proxy, | 502 base::MessageLoopProxy* message_loop_proxy, |
484 base::WaitableEvent* shutdown_event) { | 503 base::WaitableEvent* shutdown_event) { |
485 // The argument passed to GenerateVerifiedChannelID() here MUST be "nacl". | 504 // The argument passed to GenerateVerifiedChannelID() here MUST be "nacl". |
486 // Using an alternate channel name prevents the pipe from being created on | 505 // Using an alternate channel name prevents the pipe from being created on |
487 // Windows when the sandbox is enabled. | 506 // Windows when the sandbox is enabled. |
488 IPC::ChannelHandle trusted_renderer_handle = | 507 IPC::ChannelHandle trusted_renderer_handle = |
489 IPC::Channel::GenerateVerifiedChannelID("nacl"); | 508 IPC::Channel::GenerateVerifiedChannelID("nacl"); |
490 trusted_listener_ = new NaClTrustedListener( | 509 trusted_listener_ = new NaClTrustedListener( |
491 trusted_renderer_handle, io_thread_.message_loop_proxy().get()); | 510 trusted_renderer_handle, io_thread_.message_loop_proxy().get()); |
492 #if defined(OS_POSIX) | 511 #if defined(OS_POSIX) |
493 trusted_renderer_handle.socket = base::FileDescriptor( | 512 trusted_renderer_handle.socket = base::FileDescriptor( |
494 trusted_listener_->TakeClientFileDescriptor(), true); | 513 trusted_listener_->TakeClientFileDescriptor(), true); |
495 #endif | 514 #endif |
496 return trusted_renderer_handle; | 515 return trusted_renderer_handle; |
497 } | 516 } |
OLD | NEW |