1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/logging.h"
7 #include "base/strings/string_util.h"
9 #include "base/win/windows_version.h"
14 const char* GetSandboxArch() {
15 #if defined(ARCH_CPU_ARM_FAMILY)
17 #elif defined(ARCH_CPU_MIPS_FAMILY)
19 #elif defined(ARCH_CPU_X86_FAMILY)
22 // We have to check the host architecture on Windows.
23 // See sandbox_isa.h for an explanation why.
24 if (base::win::OSInfo::GetInstance()->architecture() ==
25 base::win::OSInfo::X64_ARCHITECTURE
)
29 #elif ARCH_CPU_64_BITS
33 #endif // defined(OS_WIN)
36 #error Architecture not supported.
40 std::string
GetCpuFeatures() {
41 // PNaCl's translator from pexe to nexe can be told exactly what
42 // capabilities the user's machine has because the pexe to nexe
43 // translation is specific to the machine, and CPU information goes
44 // into the translation cache. This allows the translator to generate
47 // Care must be taken to avoid instructions which aren't supported by
48 // the NaCl sandbox. Ideally the translator would do this, but there's
49 // no point in not doing the whitelist here.
51 // TODO(jfb) Some features are missing, either because the NaCl
52 // sandbox doesn't support them, because base::CPU doesn't
53 // detect them, or because they don't help vector shuffles
54 // (and we omit them because it simplifies testing). Add the
57 // TODO(jfb) The following is x86-specific. The base::CPU class
58 // doesn't handle other architectures very well, and we
59 // should at least detect the presence of ARM's integer
61 std::vector
<std::string
> features
;
64 // On x86, SSE features are ordered: the most recent one implies the
65 // others. Care is taken here to only specify the latest SSE version,
66 // whereas non-SSE features don't follow this model: POPCNT is
67 // effectively always implied by SSE4.2 but has to be specified
70 // TODO: AVX2, AVX, SSE 4.2.
71 if (cpu
.has_sse41()) features
.push_back("+sse4.1");
72 // TODO: SSE 4A, SSE 4.
73 else if (cpu
.has_ssse3()) features
.push_back("+ssse3");
75 else if (cpu
.has_sse2()) features
.push_back("+sse2");
77 // TODO: AES, POPCNT, LZCNT, ...
78 return JoinString(features
, ',');