| Index: components/nacl/loader/nonsfi_listener_delegate.cc
|
| diff --git a/components/nacl/loader/nonsfi_listener_delegate.cc b/components/nacl/loader/nonsfi_listener_delegate.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..eecc1a8b9d1e57dcddcce2fb32104d61ae7ad7f6
|
| --- /dev/null
|
| +++ b/components/nacl/loader/nonsfi_listener_delegate.cc
|
| @@ -0,0 +1,117 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/nacl/loader/nonsfi_listener_delegate.h"
|
| +
|
| +#include "base/file_descriptor_posix.h"
|
| +#include "base/logging.h"
|
| +#include "base/rand_util.h"
|
| +#include "components/nacl/common/nacl_messages.h"
|
| +#include "components/nacl/loader/nonsfi/irt_random.h"
|
| +#include "components/nacl/loader/nonsfi/nonsfi_main.h"
|
| +#include "ipc/ipc_channel.h"
|
| +#include "ipc/ipc_platform_file.h"
|
| +#include "ipc/ipc_sender.h"
|
| +#include "ppapi/nacl_irt/plugin_startup.h"
|
| +
|
| +#if !defined(OS_LINUX)
|
| +# error "Non-SFI NaCl is only supported on linux."
|
| +#endif
|
| +
|
| +
|
| +namespace nacl {
|
| +
|
| +NonSfiListenerDelegate::NonSfiListenerDelegate() {
|
| +}
|
| +
|
| +NonSfiListenerDelegate::~NonSfiListenerDelegate() {
|
| +}
|
| +
|
| +void NonSfiListenerDelegate::Start(
|
| + const nacl::NaClStartParams& params,
|
| + scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy,
|
| + IPC::ChannelHandle trusted_channel_handle,
|
| + IPC::Sender* sender) {
|
| + DCHECK(sender != NULL);
|
| +
|
| + // Random number source initialization.
|
| + nacl::nonsfi::SetUrandomFd(base::GetUrandomFD());
|
| +
|
| + IPC::ChannelHandle ppapi_browser_handle;
|
| + IPC::ChannelHandle ppapi_renderer_handle;
|
| + IPC::ChannelHandle manifest_service_handle;
|
| +
|
| + if (params.enable_ipc_proxy) {
|
| + ppapi_browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
|
| + ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");
|
| + manifest_service_handle =
|
| + IPC::Channel::GenerateVerifiedChannelID("nacl");
|
| +
|
| + // In non-SFI mode, we neither intercept nor rewrite the message using
|
| + // NaClIPCAdapter, and the channels are connected between the plugin and
|
| + // the hosts directly. So, the IPC::Channel instances will be created in
|
| + // the plugin side, because the IPC::Listener needs to live on the
|
| + // plugin's main thread. However, on initialization (i.e. before loading
|
| + // the plugin binary), the FD needs to be passed to the hosts. So, here
|
| + // we create raw FD pairs, and pass the client side FDs to the hosts,
|
| + // and the server side FDs to the plugin.
|
| + int browser_server_ppapi_fd;
|
| + int browser_client_ppapi_fd;
|
| + int renderer_server_ppapi_fd;
|
| + int renderer_client_ppapi_fd;
|
| + int manifest_service_server_fd;
|
| + int manifest_service_client_fd;
|
| + if (!IPC::SocketPair(
|
| + &browser_server_ppapi_fd, &browser_client_ppapi_fd) ||
|
| + !IPC::SocketPair(
|
| + &renderer_server_ppapi_fd, &renderer_client_ppapi_fd) ||
|
| + !IPC::SocketPair(
|
| + &manifest_service_server_fd, &manifest_service_client_fd)) {
|
| + LOG(ERROR) << "Failed to create sockets for IPC.";
|
| + return;
|
| + }
|
| +
|
| + // Set the plugin IPC channel FDs.
|
| + ppapi::SetIPCFileDescriptors(browser_server_ppapi_fd,
|
| + renderer_server_ppapi_fd,
|
| + manifest_service_server_fd);
|
| + ppapi::StartUpPlugin();
|
| +
|
| + // Send back to the client side IPC channel FD to the host.
|
| + ppapi_browser_handle.socket =
|
| + base::FileDescriptor(browser_client_ppapi_fd, true);
|
| + ppapi_renderer_handle.socket =
|
| + base::FileDescriptor(renderer_client_ppapi_fd, true);
|
| + manifest_service_handle.socket =
|
| + base::FileDescriptor(manifest_service_client_fd, true);
|
| + }
|
| +
|
| + // TODO(teravest): Do we plan on using this renderer handle for nexe loading
|
| + // for non-SFI? Right now, passing an empty channel handle instead causes
|
| + // hangs, so we'll keep it.
|
| + if (!sender->Send(new NaClProcessHostMsg_PpapiChannelsCreated(
|
| + ppapi_browser_handle, ppapi_renderer_handle,
|
| + trusted_channel_handle, manifest_service_handle)))
|
| + LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost.";
|
| +
|
| + // Ensure that the validation cache key (used as an extra input to the
|
| + // validation cache's hashing) isn't exposed accidentally.
|
| + CHECK(!params.validation_cache_enabled);
|
| + CHECK(params.validation_cache_key.size() == 0);
|
| + CHECK(params.version.size() == 0);
|
| + // Ensure that a debug stub FD isn't passed through accidentally.
|
| + CHECK(!params.enable_debug_stub);
|
| + CHECK(params.debug_stub_server_bound_socket.fd == -1);
|
| +
|
| + CHECK(!params.uses_irt);
|
| + CHECK(params.handles.empty());
|
| +
|
| + CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit());
|
| + CHECK(params.nexe_token_lo == 0);
|
| + CHECK(params.nexe_token_hi == 0);
|
| + nacl::nonsfi::MainStart(
|
| + IPC::PlatformFileForTransitToPlatformFile(params.nexe_file));
|
| +}
|
| +
|
| +} // namespace nacl
|
|
|