Skip to content

Commit

Permalink
Support non-SFI mode in NaCl manifest file.
Browse files Browse the repository at this point in the history
Currently, the flag to enable non-SFI mode is checked just before launching the plugin in the browser process. However, even if the flag is set, we may need to run the plugin in SFI mode.
For example, trivially, if the plugin provides only SFI-mode binary.
To handle such a case, this CL adds entries to NaCl manifest file so that a plugin developer can declare if their plugin provides SFI-mode/non-SFI mode binaries.
In summary, NaCl works in non-SFI mode if;
1) --enable-nacl-nonsfi-mode is set to true, and
2) the plugin provides the binary for non-SFI mode.
So, some checks are moved from the browser to the renderer.

We need similar, but slightly different, a flag for non-SFI mode. Here is the naming rule:
1) enable_nonsfi_mode -> If non-SFI mode is enabled on the browser.
  (In more precise, if it is running on supported platform, and --enable-nacl-nonsfi-mode is set)
2) uses_nonsfi_mode -> If the specified plugin should run on non-SFI mode.
  This happens when the plugin provides the binary for non-SFI mode, and --enable-nacl-nonsfi-mode
  is set.

Note that, in later CLs, we split non-SFI mode nacl_helper from the current nacl_helper with linking it to the newlib.
Then, the uses_nonsfi_mode will become a flag to decide which helper the host should talk to.

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255623 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hidehiko@chromium.org committed Mar 7, 2014
1 parent 6a7b2a0 commit b2c73f4
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 51 deletions.
1 change: 1 addition & 0 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
switches::kEnableBenchmarking,
switches::kEnableNaCl,
switches::kEnableNaClDebug,
switches::kEnableNaClNonSfiMode,
switches::kEnableNetBenchmarking,
switches::kEnableStreamlinedHostedApps,
switches::kEnableWatchdog,
Expand Down
3 changes: 2 additions & 1 deletion components/nacl/browser/nacl_host_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void NaClHostMessageFilter::OnLaunchNaCl(
launch_params.render_view_id,
launch_params.permission_bits,
launch_params.uses_irt,
launch_params.uses_nonsfi_mode,
launch_params.enable_dyncode_syscalls,
launch_params.enable_exception_handling,
launch_params.enable_crash_throttling,
Expand Down Expand Up @@ -138,7 +139,7 @@ void NaClHostMessageFilter::AsyncReturnTemporaryFile(
IPC::GetFileHandleForProcess(fd, PeerHandle(), false)));
}

void NaClHostMessageFilter::OnNaClGetNumProcessors(int *num_processors) {
void NaClHostMessageFilter::OnNaClGetNumProcessors(int* num_processors) {
*num_processors = base::SysInfo::NumberOfProcessors();
}

Expand Down
18 changes: 16 additions & 2 deletions components/nacl/browser/nacl_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ NaClProcessHost::NaClProcessHost(const GURL& manifest_url,
int render_view_id,
uint32 permission_bits,
bool uses_irt,
bool uses_nonsfi_mode,
bool enable_dyncode_syscalls,
bool enable_exception_handling,
bool enable_crash_throttling,
Expand All @@ -254,6 +255,7 @@ NaClProcessHost::NaClProcessHost(const GURL& manifest_url,
internal_(new NaClInternal()),
weak_factory_(this),
uses_irt_(uses_irt),
uses_nonsfi_mode_(uses_nonsfi_mode),
enable_debug_stub_(false),
enable_dyncode_syscalls_(enable_dyncode_syscalls),
enable_exception_handling_(enable_exception_handling),
Expand Down Expand Up @@ -762,8 +764,7 @@ bool NaClProcessHost::StartNaClExecution() {
params.enable_ipc_proxy = enable_ppapi_proxy();
params.uses_irt = uses_irt_;
params.enable_dyncode_syscalls = enable_dyncode_syscalls_;
params.enable_nonsfi_mode = CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableNaClNonSfiMode);
params.uses_nonsfi_mode = uses_nonsfi_mode_;

const ChildProcessData& data = process_->GetData();
if (!ShareHandleToSelLdr(data.handle,
Expand Down Expand Up @@ -813,6 +814,19 @@ bool NaClProcessHost::StartNaClExecution() {
}
#endif

if (params.uses_nonsfi_mode) {
#if defined(OS_LINUX)
const bool kNonSFIModeSupported = true;
#else
const bool kNonSFIModeSupported = false;
#endif
if (!kNonSFIModeSupported ||
!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableNaClNonSfiMode)) {
return false;
}
}

process_->Send(new NaClProcessMsg_Start(params));

internal_->socket_for_sel_ldr = NACL_INVALID_HANDLE;
Expand Down
3 changes: 3 additions & 0 deletions components/nacl/browser/nacl_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class NaClProcessHost : public content::BrowserChildProcessHostDelegate {
// render_view_id: RenderView routing id, to control access to private APIs.
// permission_bits: controls which interfaces the NaCl plugin can use.
// uses_irt: whether the launched process should use the IRT.
// uses_nonsfi_mode: whether the program should be loaded under non-SFI mode.
// enable_dyncode_syscalls: whether the launched process should allow dyncode
// and mmap with PROT_EXEC.
// enable_exception_handling: whether the launched process should allow
Expand All @@ -64,6 +65,7 @@ class NaClProcessHost : public content::BrowserChildProcessHostDelegate {
int render_view_id,
uint32 permission_bits,
bool uses_irt,
bool uses_nonsfi_mode,
bool enable_dyncode_syscalls,
bool enable_exception_handling,
bool enable_crash_throttling,
Expand Down Expand Up @@ -200,6 +202,7 @@ class NaClProcessHost : public content::BrowserChildProcessHostDelegate {
scoped_ptr<content::BrowserChildProcessHost> process_;

bool uses_irt_;
bool uses_nonsfi_mode_;

bool enable_debug_stub_;
bool enable_dyncode_syscalls_;
Expand Down
1 change: 1 addition & 0 deletions components/nacl/common/nacl_host_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ IPC_STRUCT_TRAITS_BEGIN(nacl::NaClLaunchParams)
IPC_STRUCT_TRAITS_MEMBER(render_view_id)
IPC_STRUCT_TRAITS_MEMBER(permission_bits)
IPC_STRUCT_TRAITS_MEMBER(uses_irt)
IPC_STRUCT_TRAITS_MEMBER(uses_nonsfi_mode)
IPC_STRUCT_TRAITS_MEMBER(enable_dyncode_syscalls)
IPC_STRUCT_TRAITS_MEMBER(enable_exception_handling)
IPC_STRUCT_TRAITS_MEMBER(enable_crash_throttling)
Expand Down
2 changes: 1 addition & 1 deletion components/nacl/common/nacl_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ IPC_STRUCT_TRAITS_BEGIN(nacl::NaClStartParams)
IPC_STRUCT_TRAITS_MEMBER(enable_ipc_proxy)
IPC_STRUCT_TRAITS_MEMBER(uses_irt)
IPC_STRUCT_TRAITS_MEMBER(enable_dyncode_syscalls)
IPC_STRUCT_TRAITS_MEMBER(enable_nonsfi_mode)
IPC_STRUCT_TRAITS_MEMBER(uses_nonsfi_mode)
IPC_STRUCT_TRAITS_END()

//-----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion components/nacl/common/nacl_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NaClStartParams::NaClStartParams()
enable_ipc_proxy(false),
uses_irt(false),
enable_dyncode_syscalls(false),
enable_nonsfi_mode(false) {
uses_nonsfi_mode(false) {
}

NaClStartParams::~NaClStartParams() {
Expand All @@ -33,13 +33,15 @@ NaClLaunchParams::NaClLaunchParams(const std::string& manifest_url,
int render_view_id,
uint32 permission_bits,
bool uses_irt,
bool uses_nonsfi_mode,
bool enable_dyncode_syscalls,
bool enable_exception_handling,
bool enable_crash_throttling)
: manifest_url(manifest_url),
render_view_id(render_view_id),
permission_bits(permission_bits),
uses_irt(uses_irt),
uses_nonsfi_mode(uses_nonsfi_mode),
enable_dyncode_syscalls(enable_dyncode_syscalls),
enable_exception_handling(enable_exception_handling),
enable_crash_throttling(enable_crash_throttling) {
Expand Down
7 changes: 5 additions & 2 deletions components/nacl/common/nacl_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct NaClStartParams {
bool enable_ipc_proxy;
bool uses_irt;
bool enable_dyncode_syscalls;
bool enable_nonsfi_mode;
bool uses_nonsfi_mode;
};

// Parameters sent to the browser process to have it launch a NaCl process.
Expand All @@ -69,7 +69,9 @@ struct NaClStartParams {
// nacl_host_messages.h.
struct NaClLaunchParams {
NaClLaunchParams();
NaClLaunchParams(const std::string& u, int r, uint32 p, bool uses_irt,
NaClLaunchParams(const std::string& u, int r, uint32 p,
bool uses_irt,
bool uses_nonsfi_mode,
bool enable_dyncode_syscalls,
bool enable_exception_handling,
bool enable_crash_throttling);
Expand All @@ -80,6 +82,7 @@ struct NaClLaunchParams {
int render_view_id;
uint32 permission_bits;
bool uses_irt;
bool uses_nonsfi_mode;
bool enable_dyncode_syscalls;
bool enable_exception_handling;
bool enable_crash_throttling;
Expand Down
4 changes: 2 additions & 2 deletions components/nacl/loader/nacl_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void NaClListener::OnStart(const nacl::NaClStartParams& params) {
ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl");

#if defined(OS_LINUX)
if (params.enable_nonsfi_mode) {
if (params.uses_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
Expand Down Expand Up @@ -416,7 +416,7 @@ void NaClListener::OnStart(const nacl::NaClStartParams& params) {
#endif

#if defined(OS_LINUX)
if (params.enable_nonsfi_mode) {
if (params.uses_nonsfi_mode) {
nacl::nonsfi::MainStart(args->imc_bootstrap_handle);
NOTREACHED();
return;
Expand Down
12 changes: 12 additions & 0 deletions components/nacl/renderer/ppb_nacl_private_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void LaunchSelLdr(PP_Instance instance,
const char* alleged_url,
PP_Bool uses_irt,
PP_Bool uses_ppapi,
PP_Bool uses_nonsfi_mode,
PP_Bool enable_ppapi_dev,
PP_Bool enable_dyncode_syscalls,
PP_Bool enable_exception_handling,
Expand Down Expand Up @@ -155,6 +156,7 @@ void LaunchSelLdr(PP_Instance instance,
routing_id,
perm_bits,
PP_ToBool(uses_irt),
PP_ToBool(uses_nonsfi_mode),
PP_ToBool(enable_dyncode_syscalls),
PP_ToBool(enable_exception_handling),
PP_ToBool(enable_crash_throttling)),
Expand Down Expand Up @@ -300,6 +302,15 @@ int32_t GetNumberOfProcessors() {
return num_processors;
}

PP_Bool IsNonSFIModeEnabled() {
#if defined(OS_LINUX)
return PP_FromBool(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableNaClNonSfiMode));
#else
return PP_FALSE;
#endif
}

int32_t GetNexeFd(PP_Instance instance,
const char* pexe_url,
uint32_t abi_version,
Expand Down Expand Up @@ -552,6 +563,7 @@ const PPB_NaCl_Private nacl_interface = {
&GetReadonlyPnaclFD,
&CreateTemporaryFile,
&GetNumberOfProcessors,
&IsNonSFIModeEnabled,
&GetNexeFd,
&ReportTranslationFinished,
&OpenNaClExecutable,
Expand Down
6 changes: 6 additions & 0 deletions ppapi/api/private/ppb_nacl_private.idl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ interface PPB_NaCl_Private {
* does not need PPAPI, then it can run off the main thread.
* The |uses_irt| flag indicates whether the IRT should be loaded in this
* NaCl process. This is true for ABI stable nexes.
* The |uses_nonsfi_mode| flag indicates whether or not nonsfi-mode should
* be used with the binary pointed by the url.
* The |enable_dyncode_syscalls| flag indicates whether or not the nexe
* will be able to use dynamic code system calls (e.g., mmap with PROT_EXEC).
* The |enable_exception_handling| flag indicates whether or not the nexe
Expand All @@ -138,6 +140,7 @@ interface PPB_NaCl_Private {
[in] str_t alleged_url,
[in] PP_Bool uses_irt,
[in] PP_Bool uses_ppapi,
[in] PP_Bool uses_nonsfi_mode,
[in] PP_Bool enable_ppapi_dev,
[in] PP_Bool enable_dyncode_syscalls,
[in] PP_Bool enable_exception_handling,
Expand Down Expand Up @@ -193,6 +196,9 @@ interface PPB_NaCl_Private {
/* Return the number of processors in the system as reported by the OS */
int32_t GetNumberOfProcessors();

/* Return whether the non-SFI mode is enabled. */
PP_Bool IsNonSFIModeEnabled();

/* Create a temporary file, which will be deleted by the time the
* last handle is closed (or earlier on POSIX systems), to use for
* the nexe with the cache information given by |pexe_url|,
Expand Down
7 changes: 6 additions & 1 deletion ppapi/c/private/ppb_nacl_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* found in the LICENSE file.
*/

/* From private/ppb_nacl_private.idl modified Thu Feb 27 14:06:31 2014. */
/* From private/ppb_nacl_private.idl modified Fri Mar 7 13:41:05 2014. */

#ifndef PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_
#define PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_
Expand Down Expand Up @@ -149,6 +149,8 @@ struct PPB_NaCl_Private_1_0 {
* does not need PPAPI, then it can run off the main thread.
* The |uses_irt| flag indicates whether the IRT should be loaded in this
* NaCl process. This is true for ABI stable nexes.
* The |uses_nonsfi_mode| flag indicates whether or not nonsfi-mode should
* be used with the binary pointed by the url.
* The |enable_dyncode_syscalls| flag indicates whether or not the nexe
* will be able to use dynamic code system calls (e.g., mmap with PROT_EXEC).
* The |enable_exception_handling| flag indicates whether or not the nexe
Expand All @@ -161,6 +163,7 @@ struct PPB_NaCl_Private_1_0 {
const char* alleged_url,
PP_Bool uses_irt,
PP_Bool uses_ppapi,
PP_Bool uses_nonsfi_mode,
PP_Bool enable_ppapi_dev,
PP_Bool enable_dyncode_syscalls,
PP_Bool enable_exception_handling,
Expand Down Expand Up @@ -208,6 +211,8 @@ struct PPB_NaCl_Private_1_0 {
PP_FileHandle (*CreateTemporaryFile)(PP_Instance instance);
/* Return the number of processors in the system as reported by the OS */
int32_t (*GetNumberOfProcessors)(void);
/* Return whether the non-SFI mode is enabled. */
PP_Bool (*IsNonSFIModeEnabled)(void);
/* Create a temporary file, which will be deleted by the time the
* last handle is closed (or earlier on POSIX systems), to use for
* the nexe with the cache information given by |pexe_url|,
Expand Down
Loading

0 comments on commit b2c73f4

Please sign in to comment.