OLD | NEW |
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 "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" | 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" |
6 | 6 |
7 #include "native_client/src/include/portability_io.h" | 7 #include "native_client/src/include/portability_io.h" |
8 #include "native_client/src/shared/platform/nacl_check.h" | 8 #include "native_client/src/shared/platform/nacl_check.h" |
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 10 #include "native_client/src/trusted/desc_cacheability/desc_cacheability.h" |
10 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/native_client/src/trusted/plugin/file_utils.h" | 12 #include "ppapi/native_client/src/trusted/plugin/file_utils.h" |
12 #include "ppapi/native_client/src/trusted/plugin/manifest.h" | 13 #include "ppapi/native_client/src/trusted/plugin/manifest.h" |
13 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 14 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
14 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" | 15 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" |
15 #include "ppapi/native_client/src/trusted/plugin/utility.h" | 16 #include "ppapi/native_client/src/trusted/plugin/utility.h" |
16 #include "third_party/jsoncpp/source/include/json/reader.h" | 17 #include "third_party/jsoncpp/source/include/json/reader.h" |
17 #include "third_party/jsoncpp/source/include/json/value.h" | 18 #include "third_party/jsoncpp/source/include/json/value.h" |
18 | 19 |
19 namespace plugin { | 20 namespace plugin { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 for (std::map<nacl::string, nacl::DescWrapper*>::iterator | 58 for (std::map<nacl::string, nacl::DescWrapper*>::iterator |
58 i = resource_wrappers_.begin(), e = resource_wrappers_.end(); | 59 i = resource_wrappers_.begin(), e = resource_wrappers_.end(); |
59 i != e; | 60 i != e; |
60 ++i) { | 61 ++i) { |
61 delete i->second; | 62 delete i->second; |
62 } | 63 } |
63 resource_wrappers_.clear(); | 64 resource_wrappers_.clear(); |
64 } | 65 } |
65 | 66 |
66 // static | 67 // static |
67 int32_t PnaclResources::GetPnaclFD(Plugin* plugin, const char* filename) { | 68 int32_t PnaclResources::GetPnaclFD(Plugin* plugin, |
| 69 const char* filename, |
| 70 bool is_executable, |
| 71 uint64_t* file_token_lo, |
| 72 uint64_t* file_token_hi) { |
68 PP_FileHandle file_handle = | 73 PP_FileHandle file_handle = |
69 plugin->nacl_interface()->GetReadonlyPnaclFd(filename); | 74 plugin->nacl_interface()->GetReadonlyPnaclFd( |
| 75 filename, PP_FromBool(is_executable), file_token_lo, file_token_hi); |
70 if (file_handle == PP_kInvalidFileHandle) | 76 if (file_handle == PP_kInvalidFileHandle) |
71 return -1; | 77 return -1; |
72 | 78 |
73 #if NACL_WINDOWS | 79 int32_t posix_desc = file_utils::ConvertFileDescriptor(file_handle); |
74 //////// Now try the posix view. | 80 return posix_desc; // Also need file info! |
75 int32_t posix_desc = _open_osfhandle(reinterpret_cast<intptr_t>(file_handle), | |
76 _O_RDONLY | _O_BINARY); | |
77 if (posix_desc == -1) { | |
78 PLUGIN_PRINTF(( | |
79 "PnaclResources::GetPnaclFD failed to convert HANDLE to posix\n")); | |
80 // Close the Windows HANDLE if it can't be converted. | |
81 CloseHandle(file_handle); | |
82 } | |
83 return posix_desc; | |
84 #else | |
85 return file_handle; | |
86 #endif | |
87 } | 81 } |
88 | 82 |
89 nacl::DescWrapper* PnaclResources::WrapperForUrl(const nacl::string& url) { | 83 nacl::DescWrapper* PnaclResources::WrapperForUrl(const nacl::string& url) { |
90 CHECK(resource_wrappers_.find(url) != resource_wrappers_.end()); | 84 CHECK(resource_wrappers_.find(url) != resource_wrappers_.end()); |
91 return resource_wrappers_[url]; | 85 return resource_wrappers_[url]; |
92 } | 86 } |
93 | 87 |
94 void PnaclResources::ReadResourceInfo( | 88 void PnaclResources::ReadResourceInfo( |
95 const nacl::string& resource_info_url, | 89 const nacl::string& resource_info_url, |
96 const pp::CompletionCallback& resource_info_read_cb) { | 90 const pp::CompletionCallback& resource_info_read_cb) { |
97 PLUGIN_PRINTF(("PnaclResources::ReadResourceInfo\n")); | 91 PLUGIN_PRINTF(("PnaclResources::ReadResourceInfo\n")); |
98 | 92 |
99 nacl::string full_url = PnaclUrls::GetBaseUrl() + resource_info_url; | 93 nacl::string full_url = PnaclUrls::GetBaseUrl() + resource_info_url; |
100 PLUGIN_PRINTF(("Resolved resources info url: %s\n", full_url.c_str())); | 94 PLUGIN_PRINTF(("Resolved resources info url: %s\n", full_url.c_str())); |
101 nacl::string resource_info_filename = | 95 nacl::string resource_info_filename = |
102 PnaclUrls::PnaclComponentURLToFilename(full_url); | 96 PnaclUrls::PnaclComponentURLToFilename(full_url); |
103 | 97 |
104 PLUGIN_PRINTF(("Pnacl-converted resources info url: %s\n", | 98 PLUGIN_PRINTF(("Pnacl-converted resources info url: %s\n", |
105 resource_info_filename.c_str())); | 99 resource_info_filename.c_str())); |
106 | 100 |
107 int32_t fd = GetPnaclFD(plugin_, resource_info_filename.c_str()); | 101 uint64_t file_token_lo; |
| 102 uint64_t file_token_hi; |
| 103 int32_t fd = GetPnaclFD(plugin_, resource_info_filename.c_str(), false, |
| 104 &file_token_lo, &file_token_hi); |
108 if (fd < 0) { | 105 if (fd < 0) { |
109 // File-open failed. Assume this means that the file is | 106 // File-open failed. Assume this means that the file is |
110 // not actually installed. | 107 // not actually installed. |
111 ReadResourceInfoError( | 108 ReadResourceInfoError( |
112 nacl::string("The Portable Native Client (pnacl) component is not " | 109 nacl::string("The Portable Native Client (pnacl) component is not " |
113 "installed. Please consult chrome://components for more " | 110 "installed. Please consult chrome://components for more " |
114 "information.")); | 111 "information.")); |
115 return; | 112 return; |
116 } | 113 } |
117 | 114 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 nacl::string full_url = GetFullUrl( | 197 nacl::string full_url = GetFullUrl( |
201 resource_urls[i], plugin_->nacl_interface()->GetSandboxArch()); | 198 resource_urls[i], plugin_->nacl_interface()->GetSandboxArch()); |
202 if (full_url == "") { | 199 if (full_url == "") { |
203 coordinator_->ReportNonPpapiError( | 200 coordinator_->ReportNonPpapiError( |
204 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 201 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
205 nacl::string("failed to resolve ") + resource_urls[i] + "."); | 202 nacl::string("failed to resolve ") + resource_urls[i] + "."); |
206 break; | 203 break; |
207 } | 204 } |
208 nacl::string filename = PnaclUrls::PnaclComponentURLToFilename(full_url); | 205 nacl::string filename = PnaclUrls::PnaclComponentURLToFilename(full_url); |
209 | 206 |
210 int32_t fd = PnaclResources::GetPnaclFD(plugin_, filename.c_str()); | 207 NaClFileInfo tmp_info; |
211 if (fd < 0) { | 208 tmp_info.desc = PnaclResources::GetPnaclFD(plugin_, filename.c_str(), true, |
| 209 &tmp_info.file_token.lo, |
| 210 &tmp_info.file_token.hi); |
| 211 if (tmp_info.desc < 0) { |
212 // File-open failed. Assume this means that the file is | 212 // File-open failed. Assume this means that the file is |
213 // not actually installed. This shouldn't actually occur since | 213 // not actually installed. This shouldn't actually occur since |
214 // ReadResourceInfo() should happen first, and error out. | 214 // ReadResourceInfo() should happen first, and error out. |
215 coordinator_->ReportNonPpapiError( | 215 coordinator_->ReportNonPpapiError( |
216 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, | 216 PP_NACL_ERROR_PNACL_RESOURCE_FETCH, |
217 nacl::string("The Portable Native Client (pnacl) component is not " | 217 nacl::string("The Portable Native Client (pnacl) component is not " |
218 "installed. Please consult chrome://components for more " | 218 "installed. Please consult chrome://components for more " |
219 "information.")); | 219 "information.")); |
220 result = PP_ERROR_FILENOTFOUND; | 220 result = PP_ERROR_FILENOTFOUND; |
221 break; | 221 break; |
222 } else { | 222 } else { |
223 resource_wrappers_[resource_urls[i]] = | 223 resource_wrappers_[resource_urls[i]] = |
224 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); | 224 plugin_->wrapper_factory()->MakeFileDesc(tmp_info.desc, O_RDONLY); |
| 225 if (tmp_info.file_token.lo != 0 && tmp_info.file_token.hi != 0) { |
| 226 if (!NaClDescSetFileToken(resource_wrappers_[resource_urls[i]]->desc(), |
| 227 &tmp_info.file_token)) { |
| 228 PLUGIN_PRINTF(( |
| 229 "PnaclResources::StartLoad: NaClDescSetFileToken failed\n")); |
| 230 } else { |
| 231 PLUGIN_PRINTF(( |
| 232 "PnaclResources::StartLoad: NaClDescSetFileToken success\n")); |
| 233 } |
| 234 } else { |
| 235 PLUGIN_PRINTF(( |
| 236 "PnaclResources::StartLoad: no file token\n")); |
| 237 } |
225 } | 238 } |
226 } | 239 } |
227 // We're done! Queue the callback. | 240 // We're done! Queue the callback. |
228 pp::Core* core = pp::Module::Get()->core(); | 241 pp::Core* core = pp::Module::Get()->core(); |
229 core->CallOnMainThread(0, all_loaded_callback, result); | 242 core->CallOnMainThread(0, all_loaded_callback, result); |
230 } | 243 } |
231 | 244 |
232 } // namespace plugin | 245 } // namespace plugin |
OLD | NEW |