diff options
author | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 21:08:01 +0000 |
---|---|---|
committer | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-14 21:08:01 +0000 |
commit | 112eb8dba36a81b7a979130a608ec51befd511b5 (patch) | |
tree | 4b4582a468428cb6c59c189516f6081bb4fe6b23 /ppapi | |
parent | 4d9fa20ea3853153b584aacfd0bd649219a8b8c1 (diff) | |
download | chromium_src-112eb8dba36a81b7a979130a608ec51befd511b5.zip chromium_src-112eb8dba36a81b7a979130a608ec51befd511b5.tar.gz chromium_src-112eb8dba36a81b7a979130a608ec51befd511b5.tar.bz2 |
Pepper: Move GetSandboxISA() to PPB_NaCl_Private.
This is part of a series of changes to move the "trusted plugin" code inside
ppapi/native_client. I was moving the logic for JsonManifest and
PNaClManifest when I noticed that PNaClManifest depends on GetSandboxISA(), and
moving that seemed big enough to justify its own change.
I think that I preserved the architecture logic in arch_x86/sandbox_isa.cc, but
it would merit some careful review.
BUG=239656
Review URL: https://codereview.chromium.org/193313002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257196 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
13 files changed, 49 insertions, 138 deletions
diff --git a/ppapi/api/private/ppb_nacl_private.idl b/ppapi/api/private/ppb_nacl_private.idl index eaa8f92..3ad1637 100644 --- a/ppapi/api/private/ppb_nacl_private.idl +++ b/ppapi/api/private/ppb_nacl_private.idl @@ -277,4 +277,9 @@ interface PPB_NaCl_Private { * will be attached to a debugger. */ PP_Bool NaClDebugStubEnabled(); + + /* Returns the kind of SFI sandbox implemented by NaCl on this + /* platform. + */ + str_t GetSandboxArch(); }; diff --git a/ppapi/c/private/ppb_nacl_private.h b/ppapi/c/private/ppb_nacl_private.h index 53929e4..5e83b98 100644 --- a/ppapi/c/private/ppb_nacl_private.h +++ b/ppapi/c/private/ppb_nacl_private.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From private/ppb_nacl_private.idl modified Fri Mar 7 13:41:05 2014. */ +/* From private/ppb_nacl_private.idl modified Wed Mar 12 14:00:41 2014. */ #ifndef PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ #define PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ @@ -282,6 +282,10 @@ struct PPB_NaCl_Private_1_0 { * will be attached to a debugger. */ PP_Bool (*NaClDebugStubEnabled)(void); + /* Returns the kind of SFI sandbox implemented by NaCl on this + * platform. + */ + const char* (*GetSandboxArch)(void); }; typedef struct PPB_NaCl_Private_1_0 PPB_NaCl_Private; diff --git a/ppapi/native_client/src/trusted/plugin/arch_arm/sandbox_isa.cc b/ppapi/native_client/src/trusted/plugin/arch_arm/sandbox_isa.cc deleted file mode 100644 index 108f49b..0000000 --- a/ppapi/native_client/src/trusted/plugin/arch_arm/sandbox_isa.cc +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2012 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 "ppapi/native_client/src/trusted/plugin/nexe_arch.h" - -namespace { -// The list of supported ISA strings for ARM. See issue: -// http://code.google.com/p/nativeclient/issues/detail?id=1040 for more -// information. Note that these string are to be case-insensitive compared. -const char* const kNexeArchARM = "arm"; -} // namespace - -namespace plugin { -const char* GetSandboxISA() { - return kNexeArchARM; -} -} // namespace plugin diff --git a/ppapi/native_client/src/trusted/plugin/arch_mips/sandbox_isa.cc b/ppapi/native_client/src/trusted/plugin/arch_mips/sandbox_isa.cc deleted file mode 100644 index a3c0eaa..0000000 --- a/ppapi/native_client/src/trusted/plugin/arch_mips/sandbox_isa.cc +++ /dev/null @@ -1,18 +0,0 @@ -// 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 "ppapi/native_client/src/trusted/plugin/nexe_arch.h" - -namespace { -// The list of supported ISA strings for MIPS. See issue: -// http://code.google.com/p/nativeclient/issues/detail?id=1040 for more -// information. Note that these string are to be case-insensitive compared. -const char* const kNexeArchMIPS = "mips32"; -} // namespace - -namespace plugin { -const char* GetSandboxISA() { - return kNexeArchMIPS; -} -} // namespace plugin diff --git a/ppapi/native_client/src/trusted/plugin/arch_x86/sandbox_isa.cc b/ppapi/native_client/src/trusted/plugin/arch_x86/sandbox_isa.cc deleted file mode 100644 index 99e0339..0000000 --- a/ppapi/native_client/src/trusted/plugin/arch_x86/sandbox_isa.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2012 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 "native_client/src/trusted/platform_qualify/nacl_os_qualify.h" -#include "ppapi/native_client/src/trusted/plugin/nexe_arch.h" - -// The list of supported ISA strings for x86. See issue: -// http://code.google.com/p/nativeclient/issues/detail?id=1040 for more -// information. Note that these string are to be case-insensitive compared. -const char kNexeArchX86_64[] = "x86-64"; -#if !((NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64) && \ - (defined(NACL_LINUX) || defined(NACL_OSX))) -const char kNexeArchX86_32[] = "x86-32"; -#endif - -namespace plugin { -const char* GetSandboxISA() { -#if (NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64) && \ - (defined(NACL_LINUX) || defined(NACL_OSX)) - return kNexeArchX86_64; // 64-bit Linux or Mac. -#else - return NaClOsIs64BitWindows() == 1 - ? kNexeArchX86_64 // 64-bit Windows (Chrome, Firefox) - : kNexeArchX86_32; // everything else. -#endif -} -} // namespace plugin diff --git a/ppapi/native_client/src/trusted/plugin/nexe_arch.h b/ppapi/native_client/src/trusted/plugin/nexe_arch.h deleted file mode 100644 index 0f8d246..0000000 --- a/ppapi/native_client/src/trusted/plugin/nexe_arch.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2012 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. - */ - -// Routines for determining the most appropriate NaCl executable for -// the current CPU's architecture. - -#ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NEXE_ARCH_H_ -#define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NEXE_ARCH_H_ - -#include "native_client/src/include/portability.h" - -namespace plugin { -// Returns the kind of SFI sandbox implemented by sel_ldr on this -// platform. See the implementation in nexe_arch.cc for possible values. -// -// This is a function of the current CPU, OS, browser, installed -// sel_ldr(s). It is not sufficient to derive the result only from -// build-time parameters since, for example, an x86-32 plugin is -// capable of launching a 64-bit NaCl sandbox if a 64-bit sel_ldr is -// installed (and indeed, may only be capable of launching a 64-bit -// sandbox). -// -// Note: The platform-sepcific implementations for this are under -// <platform>/nexe_arch.cc -const char* GetSandboxISA(); -} // namespace plugin - -#endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NEXE_ARCH_H_ diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index 526631b..3fbb80e 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -41,7 +41,6 @@ #include "ppapi/native_client/src/trusted/plugin/json_manifest.h" #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" -#include "ppapi/native_client/src/trusted/plugin/nexe_arch.h" #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" #include "ppapi/native_client/src/trusted/plugin/utility.h" @@ -60,8 +59,8 @@ const char* const kSrcManifestAttribute = "src"; // MIME type because the "src" attribute is used to supply us with the resource // of that MIME type that we're supposed to display. const char* const kNaClManifestAttribute = "nacl"; -// The pseudo-ISA used to indicate portable native client. -const char* const kPortableISA = "portable"; +// The pseudo-architecture used to indicate portable native client. +const char* const kPortableArch = "portable"; // This is a pretty arbitrary limit on the byte size of the NaCl manfest file. // Note that the resulting string object has to have at least one byte extra // for the null termination character. @@ -529,7 +528,7 @@ Plugin* Plugin::New(PP_Instance pp_instance) { // failure. Note that module loading functions will log their own errors. bool Plugin::Init(uint32_t argc, const char* argn[], const char* argv[]) { PLUGIN_PRINTF(("Plugin::Init (argc=%" NACL_PRIu32 ")\n", argc)); - HistogramEnumerateOsArch(GetSandboxISA()); + HistogramEnumerateOsArch(nacl_interface_->GetSandboxArch()); init_time_ = NaClGetTimeOfDayMicroseconds(); url_util_ = pp::URLUtil_Dev::Get(); if (url_util_ == NULL) @@ -1149,10 +1148,11 @@ bool Plugin::SetManifestObject(const nacl::string& manifest_json, bool nonsfi_mode_enabled = PP_ToBool(nacl_interface_->IsNonSFIModeEnabled()); bool pnacl_debug = GetNaClInterface()->NaClDebugStubEnabled(); + const char* sandbox_isa = nacl_interface_->GetSandboxArch(); nacl::scoped_ptr<JsonManifest> json_manifest( new JsonManifest(url_util_, manifest_base_url(), - (is_pnacl ? kPortableISA : GetSandboxISA()), + (is_pnacl ? kPortableArch : sandbox_isa), nonsfi_mode_enabled, pnacl_debug)); if (!json_manifest->Init(manifest_json, error_info)) { diff --git a/ppapi/native_client/src/trusted/plugin/plugin.gypi b/ppapi/native_client/src/trusted/plugin/plugin.gypi index 9483ed7..e8eeebf 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.gypi +++ b/ppapi/native_client/src/trusted/plugin/plugin.gypi @@ -24,24 +24,6 @@ 'temporary_file.cc', 'utility.cc', ], - # Append the arch-specific ISA code to common_sources. - 'conditions': [ - ['target_arch=="arm"', { - 'common_sources': [ - 'arch_arm/sandbox_isa.cc', - ], - }], - ['target_arch=="mipsel"', { - 'common_sources': [ - 'arch_mips/sandbox_isa.cc', - ], - }], - ['target_arch=="ia32" or target_arch=="x64"', { - 'common_sources': [ - 'arch_x86/sandbox_isa.cc', - ], - }], - ], }, 'includes': [ '../../../../../native_client/build/common.gypi', diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc index 29ada476..00322ba 100644 --- a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc +++ b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc @@ -37,7 +37,10 @@ namespace plugin { // that are part of Chrome. class PnaclManifest : public Manifest { public: - PnaclManifest() : manifest_base_url_(PnaclUrls::GetBaseUrl()) { } + PnaclManifest(const nacl::string& sandbox_arch) + : manifest_base_url_(PnaclUrls::GetBaseUrl()), + sandbox_arch_(sandbox_arch) { } + virtual ~PnaclManifest() { } virtual bool GetProgramURL(nacl::string* full_url, @@ -89,7 +92,7 @@ class PnaclManifest : public Manifest { // Resolve the full URL to the file. Provide it with a platform-specific // prefix. nacl::string key_basename = key.substr(kFilesPrefix.length()); - return ResolveURL(PnaclUrls::PrependPlatformPrefix(key_basename), + return ResolveURL(sandbox_arch_ + "/" + key_basename, full_url, error_info); } @@ -97,6 +100,7 @@ class PnaclManifest : public Manifest { NACL_DISALLOW_COPY_AND_ASSIGN(PnaclManifest); nacl::string manifest_base_url_; + nacl::string sandbox_arch_; }; ////////////////////////////////////////////////////////////////////// @@ -222,7 +226,7 @@ PnaclCoordinator::PnaclCoordinator( plugin_(plugin), translate_notify_callback_(translate_notify_callback), translation_finished_reported_(false), - manifest_(new PnaclManifest()), + manifest_(new PnaclManifest(plugin->nacl_interface()->GetSandboxArch())), pexe_url_(pexe_url), pnacl_options_(pnacl_options), split_module_count_(1), @@ -508,7 +512,7 @@ void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { parser.GetHeader("last-modified").c_str(), parser.GetHeader("etag").c_str(), PP_FromBool(parser.CacheControlNoStore()), - GetSandboxISA(), + plugin_->nacl_interface()->GetSandboxArch(), "", // No extra compile flags yet. &is_cache_hit_, temp_nexe_file_->existing_handle(), diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_resources.cc b/ppapi/native_client/src/trusted/plugin/pnacl_resources.cc index 6ed8513..d2b3508 100644 --- a/ppapi/native_client/src/trusted/plugin/pnacl_resources.cc +++ b/ppapi/native_client/src/trusted/plugin/pnacl_resources.cc @@ -17,6 +17,14 @@ #include "third_party/jsoncpp/source/include/json/value.h" namespace plugin { +namespace { +const PPB_NaCl_Private* GetNaClInterface() { + pp::Module *module = pp::Module::Get(); + CHECK(module); + return static_cast<const PPB_NaCl_Private*>( + module->GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); +} +} // namespace static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; const char PnaclUrls::kResourceInfoUrl[] = "pnacl.json"; @@ -25,10 +33,6 @@ nacl::string PnaclUrls::GetBaseUrl() { return nacl::string(kPnaclBaseUrl); } -nacl::string PnaclUrls::PrependPlatformPrefix(const nacl::string& url) { - return nacl::string(GetSandboxISA()) + "/" + url; -} - // Determine if a URL is for a pnacl-component file, or if it is some other // type of URL (e.g., http://, https://, chrome-extension://). // The URL could be one of the other variants for shared libraries @@ -188,12 +192,14 @@ bool PnaclResources::ParseResourceInfo(const nacl::string& buf, return true; } -nacl::string PnaclResources::GetFullUrl(const nacl::string& partial_url) const { +nacl::string PnaclResources::GetFullUrl( + const nacl::string& partial_url, const nacl::string& sandbox_arch) const { nacl::string full_url; ErrorInfo error_info; const nacl::string& url_with_platform_prefix = - PnaclUrls::PrependPlatformPrefix(partial_url); - if (!manifest_->ResolveURL(url_with_platform_prefix, &full_url, + sandbox_arch + "/" + partial_url; + if (!manifest_->ResolveURL(url_with_platform_prefix, + &full_url, &error_info)) { PLUGIN_PRINTF(("PnaclResources::GetFullUrl failed: %s.\n", error_info.message().c_str())); @@ -214,7 +220,8 @@ void PnaclResources::StartLoad( // Do a blocking load of each of the resources. int32_t result = PP_OK; for (size_t i = 0; i < resource_urls.size(); ++i) { - nacl::string full_url = GetFullUrl(resource_urls[i]); + nacl::string full_url = GetFullUrl( + resource_urls[i], plugin_->nacl_interface()->GetSandboxArch()); if (full_url == "") { coordinator_->ReportNonPpapiError( PP_NACL_ERROR_PNACL_RESOURCE_FETCH, diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_resources.h b/ppapi/native_client/src/trusted/plugin/pnacl_resources.h index 263dcf6..3363e17 100644 --- a/ppapi/native_client/src/trusted/plugin/pnacl_resources.h +++ b/ppapi/native_client/src/trusted/plugin/pnacl_resources.h @@ -15,7 +15,6 @@ #include "ppapi/c/private/pp_file_handle.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/native_client/src/trusted/plugin/nexe_arch.h" #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" namespace plugin { @@ -30,9 +29,6 @@ class PnaclUrls { // Get the base URL prefix for Pnacl resources (without platform prefix). static nacl::string GetBaseUrl(); - // Return {platform_prefix}/url - static nacl::string PrependPlatformPrefix(const nacl::string& url); - static bool IsPnaclComponent(const nacl::string& full_url); static nacl::string PnaclComponentURLToFilename( const nacl::string& full_url); @@ -78,7 +74,8 @@ class PnaclResources { return ld_tool_name; } - nacl::string GetFullUrl(const nacl::string& partial_url) const; + nacl::string GetFullUrl(const nacl::string& partial_url, + const nacl::string& sandbox_arch) const; // Get file descs by name. Only valid after StartLoad's completion callback // fired. diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.cc b/ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.cc index 01ac5c0..47cb621 100644 --- a/ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.cc +++ b/ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.cc @@ -119,7 +119,8 @@ NaClSubprocess* PnaclTranslateThread::StartSubprocess( // so that NaCl GDB can filter-out the translator processes (and not debug // the translator itself). Must have a full URL with schema, otherwise the // string gets silently dropped by GURL. - nacl::string full_url = resources_->GetFullUrl(url_for_nexe); + nacl::string full_url = resources_->GetFullUrl( + url_for_nexe, plugin_->nacl_interface()->GetSandboxArch()); nacl::scoped_ptr<NaClSubprocess> subprocess( plugin_->LoadHelperNaClModule(full_url, wrapper, manifest, error_info)); if (subprocess.get() == NULL) { diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index cb439da..8423846 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -3176,6 +3176,11 @@ static PP_Bool Pnacl_M25_PPB_NaCl_Private_NaClDebugStubEnabled(void) { return iface->NaClDebugStubEnabled(); } +static const char* Pnacl_M25_PPB_NaCl_Private_GetSandboxArch(void) { + const struct PPB_NaCl_Private_1_0 *iface = Pnacl_WrapperInfo_PPB_NaCl_Private_1_0.real_iface; + return iface->GetSandboxArch(); +} + /* End wrapper methods for PPB_NaCl_Private_1_0 */ /* Begin wrapper methods for PPB_NetAddress_Private_0_1 */ @@ -5063,7 +5068,8 @@ static const struct PPB_NaCl_Private_1_0 Pnacl_Wrappers_PPB_NaCl_Private_1_0 = { .SetReadOnlyProperty = (void (*)(PP_Instance instance, struct PP_Var key, struct PP_Var value))&Pnacl_M25_PPB_NaCl_Private_SetReadOnlyProperty, .ReportLoadError = (void (*)(PP_Instance instance, PP_NaClError error, PP_Bool is_installed))&Pnacl_M25_PPB_NaCl_Private_ReportLoadError, .InstanceDestroyed = (void (*)(PP_Instance instance))&Pnacl_M25_PPB_NaCl_Private_InstanceDestroyed, - .NaClDebugStubEnabled = (PP_Bool (*)(void))&Pnacl_M25_PPB_NaCl_Private_NaClDebugStubEnabled + .NaClDebugStubEnabled = (PP_Bool (*)(void))&Pnacl_M25_PPB_NaCl_Private_NaClDebugStubEnabled, + .GetSandboxArch = (const char* (*)(void))&Pnacl_M25_PPB_NaCl_Private_GetSandboxArch }; static const struct PPB_NetAddress_Private_0_1 Pnacl_Wrappers_PPB_NetAddress_Private_0_1 = { |