Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: components/nacl/renderer/plugin/pnacl_resources.cc

Issue 1005173006: Add a switch for using PNaCl Subzero and use it for -O0 translation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix takefileinfo Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/plugin/pnacl_resources.h" 5 #include "components/nacl/renderer/plugin/pnacl_resources.h"
6 6
7 #include <vector>
8
7 #include "components/nacl/renderer/plugin/plugin.h" 9 #include "components/nacl/renderer/plugin/plugin.h"
8 #include "components/nacl/renderer/plugin/utility.h" 10 #include "components/nacl/renderer/plugin/utility.h"
9 #include "native_client/src/include/portability_io.h" 11 #include "native_client/src/include/portability_io.h"
10 #include "native_client/src/shared/platform/nacl_check.h" 12 #include "native_client/src/shared/platform/nacl_check.h"
11 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 13 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
12 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
13 15
14 namespace plugin { 16 namespace plugin {
15 17
16 namespace { 18 namespace {
17 19
18 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; 20 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/";
19 21
20 std::string GetFullUrl(const std::string& partial_url) { 22 std::string GetFullUrl(const std::string& partial_url) {
21 return std::string(kPnaclBaseUrl) + GetNaClInterface()->GetSandboxArch() + 23 return std::string(kPnaclBaseUrl) + GetNaClInterface()->GetSandboxArch() +
22 "/" + partial_url; 24 "/" + partial_url;
23 } 25 }
24 26
25 } // namespace 27 } // namespace
26 28
27 PnaclResources::PnaclResources(Plugin* plugin) 29 PnaclResources::PnaclResources(Plugin* plugin, bool use_subzero)
28 : plugin_(plugin) { 30 : plugin_(plugin), use_subzero_(use_subzero) {
29 llc_file_info_ = kInvalidNaClFileInfo; 31 for (PnaclResourceEntry& entry : resources_) {
30 ld_file_info_ = kInvalidNaClFileInfo; 32 entry.file_info = kInvalidNaClFileInfo;
33 }
31 } 34 }
32 35
33 PnaclResources::~PnaclResources() { 36 PnaclResources::~PnaclResources() {
34 if (llc_file_info_.handle != PP_kInvalidFileHandle) 37 for (PnaclResourceEntry& entry : resources_) {
35 CloseFileHandle(llc_file_info_.handle); 38 if (entry.file_info.handle != PP_kInvalidFileHandle)
36 if (ld_file_info_.handle != PP_kInvalidFileHandle) 39 CloseFileHandle(entry.file_info.handle);
37 CloseFileHandle(ld_file_info_.handle); 40 }
41 }
42
43 const std::string& PnaclResources::GetUrl(ResourceType type) const {
44 size_t index = static_cast<size_t>(type);
45 if (index < NUM_TYPES) {
46 return resources_[index].tool_name;
47 }
48 // TODO(jvoung): Use NOTREACHED() from base/logging.h once
49 // we are able to use base/logging.h without conflicting
50 // with NaCl macros.
51 DCHECK(false && "Index out of bounds");
52 // Return a dummy tool name.
53 return resources_[index].tool_name;
54 }
55
56 PP_NaClFileInfo PnaclResources::TakeFileInfo(ResourceType type) {
57 size_t index = static_cast<size_t>(type);
58 if (index >= NUM_TYPES) {
59 DCHECK(false && "Index out of bounds");
60 return kInvalidNaClFileInfo;
61 }
62 PP_NaClFileInfo to_return = resources_[index].file_info;
63 resources_[index].file_info = kInvalidNaClFileInfo;
64 return to_return;
38 } 65 }
39 66
40 bool PnaclResources::ReadResourceInfo() { 67 bool PnaclResources::ReadResourceInfo() {
41 PP_Var pp_llc_tool_name_var; 68 PP_Var pp_llc_tool_name_var;
42 PP_Var pp_ld_tool_name_var; 69 PP_Var pp_ld_tool_name_var;
70 PP_Var pp_subzero_tool_name_var;
43 if (!plugin_->nacl_interface()->GetPnaclResourceInfo( 71 if (!plugin_->nacl_interface()->GetPnaclResourceInfo(
44 plugin_->pp_instance(), 72 plugin_->pp_instance(), &pp_llc_tool_name_var, &pp_ld_tool_name_var,
45 &pp_llc_tool_name_var, 73 &pp_subzero_tool_name_var)) {
46 &pp_ld_tool_name_var)) {
47 return false; 74 return false;
48 } 75 }
49 pp::Var llc_tool_name(pp::PASS_REF, pp_llc_tool_name_var); 76 pp::Var llc_tool_name(pp::PASS_REF, pp_llc_tool_name_var);
50 pp::Var ld_tool_name(pp::PASS_REF, pp_ld_tool_name_var); 77 pp::Var ld_tool_name(pp::PASS_REF, pp_ld_tool_name_var);
51 llc_tool_name_ = GetFullUrl(llc_tool_name.AsString()); 78 pp::Var subzero_tool_name(pp::PASS_REF, pp_subzero_tool_name_var);
52 ld_tool_name_ = GetFullUrl(ld_tool_name.AsString()); 79 resources_[LLC].tool_name = GetFullUrl(llc_tool_name.AsString());
80 resources_[LD].tool_name = GetFullUrl(ld_tool_name.AsString());
81 resources_[SUBZERO].tool_name = GetFullUrl(subzero_tool_name.AsString());
53 return true; 82 return true;
54 } 83 }
55 84
56 PP_NaClFileInfo PnaclResources::TakeLlcFileInfo() {
57 PP_NaClFileInfo to_return = llc_file_info_;
58 llc_file_info_ = kInvalidNaClFileInfo;
59 return to_return;
60 }
61
62 PP_NaClFileInfo PnaclResources::TakeLdFileInfo() {
63 PP_NaClFileInfo to_return = ld_file_info_;
64 ld_file_info_ = kInvalidNaClFileInfo;
65 return to_return;
66 }
67 85
68 bool PnaclResources::StartLoad() { 86 bool PnaclResources::StartLoad() {
69 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); 87 PLUGIN_PRINTF(("PnaclResources::StartLoad\n"));
70 88
71 // Do a blocking load of each of the resources. 89 // Do a blocking load of each of the resources.
72 plugin_->nacl_interface()->GetReadExecPnaclFd(llc_tool_name_.c_str(), 90 std::vector<ResourceType> to_load;
73 &llc_file_info_); 91 if (use_subzero_) {
74 plugin_->nacl_interface()->GetReadExecPnaclFd(ld_tool_name_.c_str(), 92 to_load.push_back(SUBZERO);
75 &ld_file_info_); 93 } else {
76 return (llc_file_info_.handle != PP_kInvalidFileHandle && 94 to_load.push_back(LLC);
77 ld_file_info_.handle != PP_kInvalidFileHandle); 95 }
96 to_load.push_back(LD);
97 bool all_valid = true;
98 for (ResourceType t : to_load) {
99 plugin_->nacl_interface()->GetReadExecPnaclFd(
100 resources_[t].tool_name.c_str(), &resources_[t].file_info);
101 all_valid =
102 all_valid && resources_[t].file_info.handle != PP_kInvalidFileHandle;
103 }
104 return all_valid;
78 } 105 }
79 106
80 } // namespace plugin 107 } // namespace plugin
OLDNEW
« no previous file with comments | « components/nacl/renderer/plugin/pnacl_resources.h ('k') | components/nacl/renderer/plugin/pnacl_translate_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698