diff options
author | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-17 20:40:12 +0000 |
---|---|---|
committer | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-17 20:40:12 +0000 |
commit | b7eea2ff50bb227aeeb4717677945497e8091f3e (patch) | |
tree | b2a10cdc6367123f21554c0efcd39eff11d9c369 /components/nacl | |
parent | 5dd3ad3ecb9c7c83c2b8811096eb081e7987e32c (diff) | |
download | chromium_src-b7eea2ff50bb227aeeb4717677945497e8091f3e.zip chromium_src-b7eea2ff50bb227aeeb4717677945497e8091f3e.tar.gz chromium_src-b7eea2ff50bb227aeeb4717677945497e8091f3e.tar.bz2 |
Pepper: Refactor cpu feature attributes.
We'll want to break up ppb_nacl_private_impl.cc instead of lumping things into
one large file. This change makes the method for getting CPU feature attributes
easier to reuse, and renames the sandbox_arch.{cc,h} files in the process.
This is split off from a larger change to remove FileDownloader in the trusted
plugin.
BUG=370556
R=bbudge@chromium.org
Review URL: https://codereview.chromium.org/399983002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283861 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/nacl')
-rw-r--r-- | components/nacl/renderer/nexe_load_manager.cc | 2 | ||||
-rw-r--r-- | components/nacl/renderer/platform_info.cc | 81 | ||||
-rw-r--r-- | components/nacl/renderer/platform_info.h | 18 | ||||
-rw-r--r-- | components/nacl/renderer/ppb_nacl_private_impl.cc | 50 | ||||
-rw-r--r-- | components/nacl/renderer/sandbox_arch.cc | 38 | ||||
-rw-r--r-- | components/nacl/renderer/sandbox_arch.h | 18 |
6 files changed, 102 insertions, 105 deletions
diff --git a/components/nacl/renderer/nexe_load_manager.cc b/components/nacl/renderer/nexe_load_manager.cc index 713c7f2..adbc4c9 100644 --- a/components/nacl/renderer/nexe_load_manager.cc +++ b/components/nacl/renderer/nexe_load_manager.cc @@ -13,9 +13,9 @@ #include "components/nacl/common/nacl_types.h" #include "components/nacl/renderer/histogram.h" #include "components/nacl/renderer/manifest_service_channel.h" +#include "components/nacl/renderer/platform_info.h" #include "components/nacl/renderer/pnacl_translation_resource_host.h" #include "components/nacl/renderer/progress_event.h" -#include "components/nacl/renderer/sandbox_arch.h" #include "components/nacl/renderer/trusted_plugin_channel.h" #include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" diff --git a/components/nacl/renderer/platform_info.cc b/components/nacl/renderer/platform_info.cc new file mode 100644 index 0000000..712526c --- /dev/null +++ b/components/nacl/renderer/platform_info.cc @@ -0,0 +1,81 @@ +// 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/cpu.h" +#include "base/logging.h" +#include "base/strings/string_util.h" +#if defined(OS_WIN) +#include "base/win/windows_version.h" +#endif + +namespace nacl { + +const char* GetSandboxArch() { +#if defined(ARCH_CPU_ARM_FAMILY) + return "arm"; +#elif defined(ARCH_CPU_MIPS_FAMILY) + return "mips32"; +#elif defined(ARCH_CPU_X86_FAMILY) + +#if defined(OS_WIN) + // We have to check the host architecture on Windows. + // See sandbox_isa.h for an explanation why. + if (base::win::OSInfo::GetInstance()->architecture() == + base::win::OSInfo::X64_ARCHITECTURE) + return "x86-64"; + else + return "x86-32"; +#elif ARCH_CPU_64_BITS + return "x86-64"; +#else + return "x86-32"; +#endif // defined(OS_WIN) + +#else +#error Architecture not supported. +#endif +} + +std::string GetCpuFeatures() { + // PNaCl's translator from pexe to nexe can be told exactly what + // capabilities the user's machine has because the pexe to nexe + // translation is specific to the machine, and CPU information goes + // into the translation cache. This allows the translator to generate + // faster code. + // + // Care must be taken to avoid instructions which aren't supported by + // the NaCl sandbox. Ideally the translator would do this, but there's + // no point in not doing the whitelist here. + // + // TODO(jfb) Some features are missing, either because the NaCl + // sandbox doesn't support them, because base::CPU doesn't + // detect them, or because they don't help vector shuffles + // (and we omit them because it simplifies testing). Add the + // other features. + // + // TODO(jfb) The following is x86-specific. The base::CPU class + // doesn't handle other architectures very well, and we + // should at least detect the presence of ARM's integer + // divide. + std::vector<std::string> features; + base::CPU cpu; + + // On x86, SSE features are ordered: the most recent one implies the + // others. Care is taken here to only specify the latest SSE version, + // whereas non-SSE features don't follow this model: POPCNT is + // effectively always implied by SSE4.2 but has to be specified + // separately. + // + // TODO: AVX2, AVX, SSE 4.2. + if (cpu.has_sse41()) features.push_back("+sse4.1"); + // TODO: SSE 4A, SSE 4. + else if (cpu.has_ssse3()) features.push_back("+ssse3"); + // TODO: SSE 3 + else if (cpu.has_sse2()) features.push_back("+sse2"); + + // TODO: AES, POPCNT, LZCNT, ... + return JoinString(features, ','); +} + +} // namespace nacl diff --git a/components/nacl/renderer/platform_info.h b/components/nacl/renderer/platform_info.h new file mode 100644 index 0000000..719b060 --- /dev/null +++ b/components/nacl/renderer/platform_info.h @@ -0,0 +1,18 @@ +// 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. + +#ifndef COMPONENTS_NACL_RENDERER_PLATFORM_INFO_H +#define COMPONENTS_NACL_RENDERER_PLATFORM_INFO_H + +namespace nacl { +// Returns the kind of SFI sandbox implemented by NaCl on this +// platform. See the implementation in platform_info.cc for possible +// values. +const char* GetSandboxArch(); + +// Returns the features for the system's processor. Used for PNaCl translation. +std::string GetCpuFeatures(); +} // namespace nacl + +#endif // COMPONENTS_NACL_RENDERER_PLATFORM_INFO_H diff --git a/components/nacl/renderer/ppb_nacl_private_impl.cc b/components/nacl/renderer/ppb_nacl_private_impl.cc index 79cbf9c..aa66f08 100644 --- a/components/nacl/renderer/ppb_nacl_private_impl.cc +++ b/components/nacl/renderer/ppb_nacl_private_impl.cc @@ -28,9 +28,9 @@ #include "components/nacl/renderer/manifest_downloader.h" #include "components/nacl/renderer/manifest_service_channel.h" #include "components/nacl/renderer/nexe_load_manager.h" +#include "components/nacl/renderer/platform_info.h" #include "components/nacl/renderer/pnacl_translation_resource_host.h" #include "components/nacl/renderer/progress_event.h" -#include "components/nacl/renderer/sandbox_arch.h" #include "components/nacl/renderer/trusted_plugin_channel.h" #include "content/public/common/content_client.h" #include "content/public/common/content_switches.h" @@ -1219,54 +1219,8 @@ PP_Bool GetPNaClResourceInfo(PP_Instance instance, return PP_TRUE; } -// Helper to std::accumulate that creates a comma-separated list from the input. -std::string CommaAccumulator(const std::string &lhs, const std::string &rhs) { - if (lhs.empty()) - return rhs; - return lhs + "," + rhs; -} - PP_Var GetCpuFeatureAttrs() { - // PNaCl's translator from pexe to nexe can be told exactly what - // capabilities the user's machine has because the pexe to nexe - // translation is specific to the machine, and CPU information goes - // into the translation cache. This allows the translator to generate - // faster code. - // - // Care must be taken to avoid instructions which aren't supported by - // the NaCl sandbox. Ideally the translator would do this, but there's - // no point in not doing the whitelist here. - // - // TODO(jfb) Some features are missing, either because the NaCl - // sandbox doesn't support them, because base::CPU doesn't - // detect them, or because they don't help vector shuffles - // (and we omit them because it simplifies testing). Add the - // other features. - // - // TODO(jfb) The following is x86-specific. The base::CPU class - // doesn't handle other architectures very well, and we - // should at least detect the presence of ARM's integer - // divide. - std::vector<std::string> attrs; - base::CPU cpu; - - // On x86, SSE features are ordered: the most recent one implies the - // others. Care is taken here to only specify the latest SSE version, - // whereas non-SSE features don't follow this model: POPCNT is - // effectively always implied by SSE4.2 but has to be specified - // separately. - // - // TODO: AVX2, AVX, SSE 4.2. - if (cpu.has_sse41()) attrs.push_back("+sse4.1"); - // TODO: SSE 4A, SSE 4. - else if (cpu.has_ssse3()) attrs.push_back("+ssse3"); - // TODO: SSE 3 - else if (cpu.has_sse2()) attrs.push_back("+sse2"); - - // TODO: AES, POPCNT, LZCNT, ... - - return ppapi::StringVar::StringToPPVar(std::accumulate( - attrs.begin(), attrs.end(), std::string(), CommaAccumulator)); + return ppapi::StringVar::StringToPPVar(GetCpuFeatures()); } void PostMessageToJavaScriptMainThread(PP_Instance instance, diff --git a/components/nacl/renderer/sandbox_arch.cc b/components/nacl/renderer/sandbox_arch.cc deleted file mode 100644 index 944bbc2..0000000 --- a/components/nacl/renderer/sandbox_arch.cc +++ /dev/null @@ -1,38 +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 "base/logging.h" -#if defined(OS_WIN) -#include "base/win/windows_version.h" -#endif - -namespace nacl { - -const char* GetSandboxArch() { -#if defined(ARCH_CPU_ARM_FAMILY) - return "arm"; -#elif defined(ARCH_CPU_MIPS_FAMILY) - return "mips32"; -#elif defined(ARCH_CPU_X86_FAMILY) - -#if defined(OS_WIN) - // We have to check the host architecture on Windows. - // See sandbox_isa.h for an explanation why. - if (base::win::OSInfo::GetInstance()->architecture() == - base::win::OSInfo::X64_ARCHITECTURE) - return "x86-64"; - else - return "x86-32"; -#elif ARCH_CPU_64_BITS - return "x86-64"; -#else - return "x86-32"; -#endif // defined(OS_WIN) - -#else -#error Architecture not supported. -#endif -} - -} // namespace nacl diff --git a/components/nacl/renderer/sandbox_arch.h b/components/nacl/renderer/sandbox_arch.h deleted file mode 100644 index e139b04..0000000 --- a/components/nacl/renderer/sandbox_arch.h +++ /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. - -// Routines for determining the most appropriate NaCl executable for -// the current CPU's architecture. - -#ifndef COMPONENTS_NACL_RENDERER_SANDBOX_ARCH_H -#define COMPONENTS_NACL_RENDERER_SANDBOX_ARCH_H - -namespace nacl { -// Returns the kind of SFI sandbox implemented by NaCl on this -// platform. See the implementation in sandbox_arch.cc for possible -// values. -const char* GetSandboxArch(); -} // namespace nacl - -#endif // COMPONENTS_NACL_RENDERER_SANDBOX_ARCH_H |