Skip to content

Commit

Permalink
Connect PPAPI IPC channels for non-SFI mode.
Browse files Browse the repository at this point in the history
By this CL, plugin starts to talk with hosts via IPC.
For that purpose, ppapi_proxy is linked to nacl_helper (temporarily). This increase the size of nacl_helper, but when we split nacl_helper for non-sfi mode, it'll be resolved.

In SFI mode, this CL shouldn't affect the concept of IPC
channel connection between the plugin and the hosts. We
still use NaClIPCAdapter to wrap the IPC channel, and
NaClDesc for the plugin-side IPC file descriptors.

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.

Note: plugin_main_nacl.cc is renamed to plugin_main.cc, because files with _nacl.cc suffix are automatically excluded from the sources of non-untrusted libs.

This increases the size of nacl_helper (temporarily) intentionally.

GYP_DEFINES="target_arch=ia32 remove_webcore_debug_symbols=1 linux_strip_symbols=1" GYP_GENERATORS="ninja" gclient runhooks
Before:
   text	   data	    bss	    dec	    hex	filename
1469882	  15576	 108644	1594102	 1852f6	out/Release/nacl_helper

After:
   text	   data	    bss	    dec	    hex	filename
5641443	 124636	 126980	5893059	 59ebc3	out/Release/nacl_helper

GYP_DEFINES="target_arch=x64 remove_webcore_debug_symbols=1 linux_strip_symbols=1" GYP_GENERATORS="ninja" gclient runhooks
Before:
   text	   data	    bss	    dec	    hex	filename
2063530	  27910	 213872	2305312	 232d20	out/Release/nacl_helper

After:
   text	   data	    bss	    dec	    hex	filename
6304467	 234424	 247984	6786875	 678f3b	out/Release/nacl_helper


BUG=https://code.google.com/p/nativeclient/issues/detail?id=3734
TEST=Ran trybot.

Review URL: https://codereview.chromium.org/140573003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252503 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hidehiko@chromium.org committed Feb 21, 2014
1 parent 183de20 commit 3d41a2a
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 39 deletions.
5 changes: 5 additions & 0 deletions components/nacl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@
'dependencies': [
'nacl',
'nacl_common',
'../components/tracing.gyp:tracing',
'../crypto/crypto.gyp:crypto',
'../sandbox/sandbox.gyp:libc_urandom_override',
'../sandbox/sandbox.gyp:sandbox',
'../ppapi/ppapi_internal.gyp:ppapi_proxy',
],
'defines': [
'<@(nacl_defines)',
Expand All @@ -206,6 +208,7 @@
'nacl/loader/nonsfi/irt_interfaces.cc',
'nacl/loader/nonsfi/irt_interfaces.h',
'nacl/loader/nonsfi/irt_memory.cc',
'nacl/loader/nonsfi/irt_ppapi.cc',
'nacl/loader/nonsfi/irt_thread.cc',
'nacl/loader/nonsfi/irt_util.h',
'nacl/loader/nonsfi/nonsfi_main.cc',
Expand All @@ -216,6 +219,8 @@
'../content/common/sandbox_linux/sandbox_init_linux.cc',
'../content/common/sandbox_linux/sandbox_seccomp_bpf_linux.cc',
'../content/public/common/content_switches.cc',
'../ppapi/proxy/plugin_main_irt.cc',
'../ppapi/proxy/plugin_main_irt.h',
],
'conditions': [
['toolkit_uses_gtk == 1', {
Expand Down
3 changes: 3 additions & 0 deletions components/nacl/loader/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ include_rules = [
"+ppapi/proxy/nacl_message_scanner.h",
"+ppapi/proxy/serialized_handle.h",

# For setting FDs in non-SFI mode.
"+ppapi/proxy/plugin_main_irt.h",

# For sending PpapiHostMsg_ChannelCreated in nacl_ipc_adapter.cc:
"+ppapi/proxy/ppapi_messages.h"
]
52 changes: 44 additions & 8 deletions components/nacl/loader/nacl_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#if defined(OS_LINUX)
#include "components/nacl/loader/nonsfi/nonsfi_main.h"
#include "content/public/common/child_process_sandbox_support_linux.h"
#include "ppapi/proxy/plugin_main_irt.h"
#endif

#if defined(OS_WIN)
Expand Down Expand Up @@ -279,19 +280,54 @@ void NaClListener::OnStart(const nacl::NaClStartParams& params) {
}

if (params.enable_ipc_proxy) {
// Create the PPAPI IPC channels between the NaCl IRT and the hosts
// (browser/renderer) processes. The IRT uses these channels to communicate
// with the host and to initialize the IPC dispatchers.
IPC::ChannelHandle browser_handle =
IPC::Channel::GenerateVerifiedChannelID("nacl");
SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(),
nap, NACL_CHROME_DESC_BASE);

IPC::ChannelHandle renderer_handle =
IPC::Channel::GenerateVerifiedChannelID("nacl");
SetUpIPCAdapter(&renderer_handle, io_thread_.message_loop_proxy(),
nap, NACL_CHROME_DESC_BASE + 1);

#if defined(OS_LINUX)
if (params.enable_nonsfi_mode) {
// 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;
if (!IPC::SocketPair(
&browser_server_ppapi_fd, &browser_client_ppapi_fd) ||
!IPC::SocketPair(
&renderer_server_ppapi_fd, &renderer_client_ppapi_fd)) {
LOG(ERROR) << "Failed to create sockets for IPC.";
return;
}

// Set the plugin IPC channel FDs.
SetIPCFileDescriptors(
browser_server_ppapi_fd, renderer_server_ppapi_fd);

// Send back to the client side IPC channel FD to the host.
browser_handle.socket =
base::FileDescriptor(browser_client_ppapi_fd, true);
renderer_handle.socket =
base::FileDescriptor(renderer_client_ppapi_fd, true);
} else {
#endif
// Create the PPAPI IPC channels between the NaCl IRT and the host
// (browser/renderer) processes. The IRT uses these channels to
// communicate with the host and to initialize the IPC dispatchers.
SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(),
nap, NACL_CHROME_DESC_BASE);
SetUpIPCAdapter(&renderer_handle, io_thread_.message_loop_proxy(),
nap, NACL_CHROME_DESC_BASE + 1);
#if defined(OS_LINUX)
}
#endif
if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
browser_handle, renderer_handle)))
LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost.";
Expand Down
3 changes: 3 additions & 0 deletions components/nacl/loader/nonsfi/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+ppapi/nacl_irt",
]
1 change: 1 addition & 0 deletions components/nacl/loader/nonsfi/irt_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const NaClInterfaceTable kIrtInterfaces[] = {
NACL_INTERFACE_TABLE(NACL_IRT_FUTEX_v0_1, kIrtFutex),
NACL_INTERFACE_TABLE(NACL_IRT_TLS_v0_1, kIrtTls),
NACL_INTERFACE_TABLE(NACL_IRT_CLOCK_v0_1, kIrtClock),
NACL_INTERFACE_TABLE(NACL_IRT_PPAPIHOOK_v0_1, kIrtPpapiHook),
};
#undef NACL_INTERFACE_TABLE

Expand Down
1 change: 1 addition & 0 deletions components/nacl/loader/nonsfi/irt_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern const struct nacl_irt_thread kIrtThread;
extern const struct nacl_irt_futex kIrtFutex;
extern const struct nacl_irt_tls kIrtTls;
extern const struct nacl_irt_clock kIrtClock;
extern const struct nacl_irt_ppapihook kIrtPpapiHook;

} // namespace nonsfi
} // namespace nacl
Expand Down
44 changes: 44 additions & 0 deletions components/nacl/loader/nonsfi/irt_ppapi.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 "base/logging.h"
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "ppapi/c/ppp.h"
#include "ppapi/nacl_irt/irt_ppapi.h"
#include "ppapi/proxy/plugin_main_irt.h"

namespace nacl {
namespace nonsfi {
namespace {

struct PP_StartFunctions g_pp_functions;

int IrtPpapiStart(const struct PP_StartFunctions* funcs) {
g_pp_functions = *funcs;
return PpapiPluginMain();
}

} // namespace

const struct nacl_irt_ppapihook kIrtPpapiHook = {
IrtPpapiStart,
PpapiPluginRegisterThreadCreator,
};

} // namespace nonsfi
} // namespace nacl

int32_t PPP_InitializeModule(PP_Module module_id,
PPB_GetInterface get_browser_interface) {
return nacl::nonsfi::g_pp_functions.PPP_InitializeModule(
module_id, get_browser_interface);
}

void PPP_ShutdownModule(void) {
nacl::nonsfi::g_pp_functions.PPP_ShutdownModule();
}

const void *PPP_GetInterface(const char *interface_name) {
return nacl::nonsfi::g_pp_functions.PPP_GetInterface(interface_name);
}
61 changes: 46 additions & 15 deletions components/nacl/loader/nonsfi/nonsfi_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

#include "components/nacl/loader/nonsfi/nonsfi_main.h"

#include "base/debug/leak_annotations.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/threading/platform_thread.h"
#include "components/nacl/loader/nonsfi/elf_loader.h"
#include "components/nacl/loader/nonsfi/irt_interfaces.h"
#include "native_client/src/include/elf_auxv.h"
Expand All @@ -22,6 +24,41 @@ namespace nacl {
namespace nonsfi {
namespace {

typedef void (*EntryPointType)(uintptr_t*);

class PluginMainDelegate : public base::PlatformThread::Delegate {
public:
explicit PluginMainDelegate(EntryPointType entry_point)
: entry_point_(entry_point) {
}

virtual ~PluginMainDelegate() {
}

virtual void ThreadMain() OVERRIDE {
base::PlatformThread::SetName("NaClMainThread");

uintptr_t info[] = {
0, // Do not use fini.
0, // envc.
0, // argc.
0, // Null terminate for argv.
0, // Null terminate for envv.
AT_SYSINFO,
reinterpret_cast<uintptr_t>(&NaClIrtInterface),
AT_NULL,
0, // Null terminate for auxv.
};
entry_point_(info);
}

private:
EntryPointType entry_point_;
};

// Default stack size of the plugin main thread. We heuristically chose 16M.
const size_t kStackSize = (16 << 20);

struct NaClDescUnrefer {
void operator()(struct NaClDesc* desc) const {
NaClDescUnref(desc);
Expand All @@ -46,22 +83,16 @@ void LoadModuleRpc(struct NaClSrpcRpc* rpc,
return;
}

uintptr_t entry_point = image.entry_point();
rpc->result = NACL_SRPC_RESULT_OK;
EntryPointType entry_point =
reinterpret_cast<EntryPointType>(image.entry_point());
if (!base::PlatformThread::CreateNonJoinable(
kStackSize, new PluginMainDelegate(entry_point))) {
LOG(ERROR) << "LoadModuleRpc: Failed to create plugin main thread.";
return;
}

// Run for testing. TODO(hidehiko): Remove this.
uintptr_t info[] = {
0, // Do not use fini.
0, // envc.
0, // argc.
0, // Null terminate for argv.
0, // Null terminate for envv.
AT_SYSINFO,
reinterpret_cast<uintptr_t>(&NaClIrtInterface),
AT_NULL,
0, // Null terminate for auxv.
};
reinterpret_cast<void (*)(uintptr_t*)>(entry_point)(info);
rpc->result = NACL_SRPC_RESULT_OK;
(*done_cls->Run)(done_cls);
}

const static struct NaClSrpcHandlerDesc kNonSfiServiceHandlers[] = {
Expand Down
6 changes: 6 additions & 0 deletions ipc/ipc_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ class IPC_EXPORT Channel : public Sender {
ChannelImpl *channel_impl_;
};

#if defined(OS_POSIX)
// SocketPair() creates a pair of socket FDs suitable for using with
// IPC::Channel.
IPC_EXPORT bool SocketPair(int* fd1, int* fd2);
#endif

} // namespace IPC

#endif // IPC_IPC_CHANNEL_H_
3 changes: 0 additions & 3 deletions ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ EXTERN_C_BEGIN
// The entry point for the main thread of the PPAPI plugin process.
int PpapiPluginMain(void);

void PpapiPluginRegisterThreadCreator(
const struct PP_ThreadFunctions* new_funcs);

EXTERN_C_END

#endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PPRUNTIME_H_
3 changes: 2 additions & 1 deletion ppapi/ppapi_proxy.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
'proxy/plugin_dispatcher.h',
'proxy/plugin_globals.cc',
'proxy/plugin_globals.h',
'proxy/plugin_main_nacl.cc',
'proxy/plugin_message_filter.cc',
'proxy/plugin_message_filter.h',
'proxy/plugin_resource.cc',
Expand Down Expand Up @@ -244,6 +243,8 @@
['>(nacl_untrusted_build)==1', {
'sources': [
'proxy/irt_ppapi.c',
'proxy/plugin_main_irt.cc',
'proxy/plugin_main_irt.h',
],
'sources!': [
'proxy/audio_input_resource.cc',
Expand Down
2 changes: 1 addition & 1 deletion ppapi/proxy/irt_ppapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "native_client/src/untrusted/irt/irt.h"
#include "native_client/src/untrusted/irt/irt_private.h"
#include "ppapi/nacl_irt/irt_ppapi.h"
#include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h"
#include "ppapi/proxy/plugin_main_irt.h"

struct PP_StartFunctions g_pp_functions;

Expand Down
Loading

0 comments on commit 3d41a2a

Please sign in to comment.