OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" | 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "components/nacl/common/nacl_messages.h" | 21 #include "components/nacl/common/nacl_messages.h" |
22 #include "components/nacl/common/nacl_nonsfi_util.h" | 22 #include "components/nacl/common/nacl_nonsfi_util.h" |
23 #include "components/nacl/common/nacl_switches.h" | 23 #include "components/nacl/common/nacl_switches.h" |
24 #include "components/nacl/common/nacl_types.h" | 24 #include "components/nacl/common/nacl_types.h" |
25 #include "components/nacl/renderer/file_downloader.h" | 25 #include "components/nacl/renderer/file_downloader.h" |
26 #include "components/nacl/renderer/histogram.h" | 26 #include "components/nacl/renderer/histogram.h" |
27 #include "components/nacl/renderer/json_manifest.h" | 27 #include "components/nacl/renderer/json_manifest.h" |
28 #include "components/nacl/renderer/manifest_downloader.h" | 28 #include "components/nacl/renderer/manifest_downloader.h" |
29 #include "components/nacl/renderer/manifest_service_channel.h" | 29 #include "components/nacl/renderer/manifest_service_channel.h" |
30 #include "components/nacl/renderer/nexe_load_manager.h" | 30 #include "components/nacl/renderer/nexe_load_manager.h" |
31 #include "components/nacl/renderer/platform_info.h" | |
31 #include "components/nacl/renderer/pnacl_translation_resource_host.h" | 32 #include "components/nacl/renderer/pnacl_translation_resource_host.h" |
32 #include "components/nacl/renderer/progress_event.h" | 33 #include "components/nacl/renderer/progress_event.h" |
33 #include "components/nacl/renderer/sandbox_arch.h" | |
34 #include "components/nacl/renderer/trusted_plugin_channel.h" | 34 #include "components/nacl/renderer/trusted_plugin_channel.h" |
35 #include "content/public/common/content_client.h" | 35 #include "content/public/common/content_client.h" |
36 #include "content/public/common/content_switches.h" | 36 #include "content/public/common/content_switches.h" |
37 #include "content/public/common/sandbox_init.h" | 37 #include "content/public/common/sandbox_init.h" |
38 #include "content/public/renderer/pepper_plugin_instance.h" | 38 #include "content/public/renderer/pepper_plugin_instance.h" |
39 #include "content/public/renderer/render_thread.h" | 39 #include "content/public/renderer/render_thread.h" |
40 #include "content/public/renderer/render_view.h" | 40 #include "content/public/renderer/render_view.h" |
41 #include "content/public/renderer/renderer_ppapi_host.h" | 41 #include "content/public/renderer/renderer_ppapi_host.h" |
42 #include "native_client/src/public/imc_types.h" | 42 #include "native_client/src/public/imc_types.h" |
43 #include "net/base/data_url.h" | 43 #include "net/base/data_url.h" |
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1212 if (json_data.isMember("pnacl-ld-name")) { | 1212 if (json_data.isMember("pnacl-ld-name")) { |
1213 Json::Value json_name = json_data["pnacl-ld-name"]; | 1213 Json::Value json_name = json_data["pnacl-ld-name"]; |
1214 if (json_name.isString()) { | 1214 if (json_name.isString()) { |
1215 std::string ld_tool_name_str = json_name.asString(); | 1215 std::string ld_tool_name_str = json_name.asString(); |
1216 *ld_tool_name = ppapi::StringVar::StringToPPVar(ld_tool_name_str); | 1216 *ld_tool_name = ppapi::StringVar::StringToPPVar(ld_tool_name_str); |
1217 } | 1217 } |
1218 } | 1218 } |
1219 return PP_TRUE; | 1219 return PP_TRUE; |
1220 } | 1220 } |
1221 | 1221 |
1222 // Helper to std::accumulate that creates a comma-separated list from the input. | 1222 PP_Var ExternalGetCpuFeatureAttrs() { |
1223 std::string CommaAccumulator(const std::string &lhs, const std::string &rhs) { | 1223 return ppapi::StringVar::StringToPPVar(GetCpuFeatureAttrs()); |
1224 if (lhs.empty()) | |
1225 return rhs; | |
1226 return lhs + "," + rhs; | |
1227 } | |
1228 | |
1229 PP_Var GetCpuFeatureAttrs() { | |
1230 // PNaCl's translator from pexe to nexe can be told exactly what | |
1231 // capabilities the user's machine has because the pexe to nexe | |
1232 // translation is specific to the machine, and CPU information goes | |
1233 // into the translation cache. This allows the translator to generate | |
1234 // faster code. | |
1235 // | |
1236 // Care must be taken to avoid instructions which aren't supported by | |
1237 // the NaCl sandbox. Ideally the translator would do this, but there's | |
1238 // no point in not doing the whitelist here. | |
1239 // | |
1240 // TODO(jfb) Some features are missing, either because the NaCl | |
1241 // sandbox doesn't support them, because base::CPU doesn't | |
1242 // detect them, or because they don't help vector shuffles | |
1243 // (and we omit them because it simplifies testing). Add the | |
1244 // other features. | |
1245 // | |
1246 // TODO(jfb) The following is x86-specific. The base::CPU class | |
1247 // doesn't handle other architectures very well, and we | |
1248 // should at least detect the presence of ARM's integer | |
1249 // divide. | |
1250 std::vector<std::string> attrs; | |
1251 base::CPU cpu; | |
1252 | |
1253 // On x86, SSE features are ordered: the most recent one implies the | |
1254 // others. Care is taken here to only specify the latest SSE version, | |
1255 // whereas non-SSE features don't follow this model: POPCNT is | |
1256 // effectively always implied by SSE4.2 but has to be specified | |
1257 // separately. | |
1258 // | |
1259 // TODO: AVX2, AVX, SSE 4.2. | |
1260 if (cpu.has_sse41()) attrs.push_back("+sse4.1"); | |
1261 // TODO: SSE 4A, SSE 4. | |
1262 else if (cpu.has_ssse3()) attrs.push_back("+ssse3"); | |
1263 // TODO: SSE 3 | |
1264 else if (cpu.has_sse2()) attrs.push_back("+sse2"); | |
1265 | |
1266 // TODO: AES, POPCNT, LZCNT, ... | |
1267 | |
1268 return ppapi::StringVar::StringToPPVar(std::accumulate( | |
1269 attrs.begin(), attrs.end(), std::string(), CommaAccumulator)); | |
1270 } | 1224 } |
1271 | 1225 |
1272 void PostMessageToJavaScriptMainThread(PP_Instance instance, | 1226 void PostMessageToJavaScriptMainThread(PP_Instance instance, |
1273 const std::string& message) { | 1227 const std::string& message) { |
1274 content::PepperPluginInstance* plugin_instance = | 1228 content::PepperPluginInstance* plugin_instance = |
1275 content::PepperPluginInstance::Get(instance); | 1229 content::PepperPluginInstance::Get(instance); |
1276 if (plugin_instance) { | 1230 if (plugin_instance) { |
1277 PP_Var message_var = ppapi::StringVar::StringToPPVar(message); | 1231 PP_Var message_var = ppapi::StringVar::StringToPPVar(message); |
1278 plugin_instance->PostMessageToJavaScript(message_var); | 1232 plugin_instance->PostMessageToJavaScript(message_var); |
1279 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(message_var); | 1233 ppapi::PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(message_var); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1636 &SetExitStatus, | 1590 &SetExitStatus, |
1637 &Vlog, | 1591 &Vlog, |
1638 &InitializePlugin, | 1592 &InitializePlugin, |
1639 &GetNexeSize, | 1593 &GetNexeSize, |
1640 &RequestNaClManifest, | 1594 &RequestNaClManifest, |
1641 &GetManifestBaseURL, | 1595 &GetManifestBaseURL, |
1642 &ProcessNaClManifest, | 1596 &ProcessNaClManifest, |
1643 &DevInterfacesEnabled, | 1597 &DevInterfacesEnabled, |
1644 &ManifestGetProgramURL, | 1598 &ManifestGetProgramURL, |
1645 &GetPNaClResourceInfo, | 1599 &GetPNaClResourceInfo, |
1646 &GetCpuFeatureAttrs, | 1600 &ExternalGetCpuFeatureAttrs, |
bbudge
2014/07/17 17:57:55
If you rename the components/nacl function, you co
teravest
2014/07/17 18:01:40
Done.
| |
1647 &PostMessageToJavaScript, | 1601 &PostMessageToJavaScript, |
1648 &DownloadNexe, | 1602 &DownloadNexe, |
1649 &ReportSelLdrStatus, | 1603 &ReportSelLdrStatus, |
1650 &LogTranslateTime, | 1604 &LogTranslateTime, |
1651 &OpenManifestEntry, | 1605 &OpenManifestEntry, |
1652 &SetPNaClStartTime | 1606 &SetPNaClStartTime |
1653 }; | 1607 }; |
1654 | 1608 |
1655 } // namespace | 1609 } // namespace |
1656 | 1610 |
1657 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1611 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1658 return &nacl_interface; | 1612 return &nacl_interface; |
1659 } | 1613 } |
1660 | 1614 |
1661 } // namespace nacl | 1615 } // namespace nacl |
OLD | NEW |