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 // FIXME: Fix this on windows so that we turn this handle into an int. | |
bbudge
2014/06/30 18:28:53
FIXME->TODO (or remove, it seems like you address
teravest
2014/06/30 22:04:56
Done.
| |
396 base::PlatformFile nexe_file = IPC::PlatformFileForTransitToPlatformFile( | |
397 params.nexe_file); | |
398 #if defined(OS_WIN) | |
399 nexe_file_info.desc = | |
400 _open_osfhandle(reinterpret_cast<intptr_t>(nexe_file), | |
401 _O_RDONLY | _O_BINARY); | |
402 #else | |
bbudge
2014/06/30 18:28:53
nit: #elif defined(OS_POSIX)
teravest
2014/06/30 22:04:56
Done.
| |
403 nexe_file_info.desc = nexe_file; | |
404 #endif | |
405 nexe_file_info.file_token.lo = params.nexe_token_lo; | |
Mark Seaborn
2014/06/30 20:01:03
FYI, having the browser pass the token through to
teravest
2014/06/30 22:04:56
I see what you mean. I've added a TODO here to add
| |
406 nexe_file_info.file_token.hi = params.nexe_token_hi; | |
407 args->nexe_desc = NaClDescIoFromFileInfo(nexe_file_info, NACL_ABI_O_RDONLY); | |
408 | |
393 NaClChromeMainStartApp(nap, args); | 409 NaClChromeMainStartApp(nap, args); |
394 NOTREACHED(); | 410 NOTREACHED(); |
395 } | 411 } |
396 | 412 |
397 void NaClListener::StartNonSfi(const nacl::NaClStartParams& params) { | 413 void NaClListener::StartNonSfi(const nacl::NaClStartParams& params) { |
398 #if !defined(OS_LINUX) | 414 #if !defined(OS_LINUX) |
399 NOTREACHED() << "Non-SFI NaCl is only supported on Linux"; | 415 NOTREACHED() << "Non-SFI NaCl is only supported on Linux"; |
400 #else | 416 #else |
401 // Random number source initialization. | 417 // Random number source initialization. |
402 nacl::nonsfi::SetUrandomFd(base::GetUrandomFD()); | 418 nacl::nonsfi::SetUrandomFd(base::GetUrandomFD()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 io_thread_.message_loop_proxy(), &shutdown_event_); | 473 io_thread_.message_loop_proxy(), &shutdown_event_); |
458 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 474 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
459 browser_handle, ppapi_renderer_handle, | 475 browser_handle, ppapi_renderer_handle, |
460 trusted_renderer_handle, manifest_service_handle))) | 476 trusted_renderer_handle, manifest_service_handle))) |
461 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; | 477 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; |
462 | 478 |
463 // Ensure that the validation cache key (used as an extra input to the | 479 // Ensure that the validation cache key (used as an extra input to the |
464 // validation cache's hashing) isn't exposed accidentally. | 480 // validation cache's hashing) isn't exposed accidentally. |
465 CHECK(!params.validation_cache_enabled); | 481 CHECK(!params.validation_cache_enabled); |
466 CHECK(params.validation_cache_key.size() == 0); | 482 CHECK(params.validation_cache_key.size() == 0); |
467 CHECK(params.version.size() == 0); | 483 CHECK(params.version.size() == 0); |
Mark Seaborn
2014/06/30 20:01:03
You could also check that the token is zero, to en
teravest
2014/06/30 22:04:56
Done.
| |
468 // Ensure that a debug stub FD isn't passed through accidentally. | 484 // Ensure that a debug stub FD isn't passed through accidentally. |
469 CHECK(!params.enable_debug_stub); | 485 CHECK(!params.enable_debug_stub); |
470 CHECK(params.debug_stub_server_bound_socket.fd == -1); | 486 CHECK(params.debug_stub_server_bound_socket.fd == -1); |
471 | 487 |
472 CHECK(!params.uses_irt); | 488 CHECK(!params.uses_irt); |
473 CHECK(params.handles.empty()); | 489 CHECK(params.handles.empty()); |
474 | 490 |
475 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit()); | 491 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit()); |
476 nacl::nonsfi::MainStart( | 492 nacl::nonsfi::MainStart( |
477 NaClDescIoDescFromDescAllocCtor( | 493 NaClDescIoDescFromDescAllocCtor( |
(...skipping 11 matching lines...) Expand all Loading... | |
489 IPC::ChannelHandle trusted_renderer_handle = | 505 IPC::ChannelHandle trusted_renderer_handle = |
490 IPC::Channel::GenerateVerifiedChannelID("nacl"); | 506 IPC::Channel::GenerateVerifiedChannelID("nacl"); |
491 trusted_listener_ = new NaClTrustedListener( | 507 trusted_listener_ = new NaClTrustedListener( |
492 trusted_renderer_handle, io_thread_.message_loop_proxy().get()); | 508 trusted_renderer_handle, io_thread_.message_loop_proxy().get()); |
493 #if defined(OS_POSIX) | 509 #if defined(OS_POSIX) |
494 trusted_renderer_handle.socket = base::FileDescriptor( | 510 trusted_renderer_handle.socket = base::FileDescriptor( |
495 trusted_listener_->TakeClientFileDescriptor(), true); | 511 trusted_listener_->TakeClientFileDescriptor(), true); |
496 #endif | 512 #endif |
497 return trusted_renderer_handle; | 513 return trusted_renderer_handle; |
498 } | 514 } |
OLD | NEW |