OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "native_client/src/trusted/plugin/json_manifest.h" | 9 #include "native_client/src/trusted/plugin/json_manifest.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 const char* const kX8632Key = "x86-32"; | 34 const char* const kX8632Key = "x86-32"; |
35 const char* const kX8664Key = "x86-64"; | 35 const char* const kX8664Key = "x86-64"; |
36 const char* const kArmKey = "arm"; | 36 const char* const kArmKey = "arm"; |
37 const char* const kPortableKey = "portable"; | 37 const char* const kPortableKey = "portable"; |
38 | 38 |
39 // Url Resolution keys | 39 // Url Resolution keys |
40 const char* const kPnaclTranslateKey = "pnacl-translate"; | 40 const char* const kPnaclTranslateKey = "pnacl-translate"; |
41 const char* const kUrlKey = "url"; | 41 const char* const kUrlKey = "url"; |
42 | 42 |
43 // Pnacl keys | 43 // Pnacl keys |
44 const char* const kCacheIdentityKey = "sha256"; | |
45 const char* const kOptLevelKey = "-O"; | 44 const char* const kOptLevelKey = "-O"; |
46 const char* const kPnaclExperimentalFlags = "experimental_flags"; | 45 const char* const kPnaclExperimentalFlags = "experimental_flags"; |
47 | 46 |
48 // Sample NaCL manifest file: | 47 // Sample NaCL manifest file: |
49 // { | 48 // { |
50 // "program": { | 49 // "program": { |
51 // "x86-32": {"url": "myprogram_x86-32.nexe"}, | 50 // "x86-32": {"url": "myprogram_x86-32.nexe"}, |
52 // "x86-64": {"url": "myprogram_x86-64.nexe"}, | 51 // "x86-64": {"url": "myprogram_x86-64.nexe"}, |
53 // "arm": {"url": "myprogram_arm.nexe"} | 52 // "arm": {"url": "myprogram_arm.nexe"} |
54 // }, | 53 // }, |
(...skipping 15 matching lines...) Expand all Loading... |
70 // } | 69 // } |
71 // } | 70 // } |
72 // } | 71 // } |
73 | 72 |
74 // Sample PNaCl manifest file: | 73 // Sample PNaCl manifest file: |
75 // { | 74 // { |
76 // "program": { | 75 // "program": { |
77 // "portable": { | 76 // "portable": { |
78 // "pnacl-translate": { | 77 // "pnacl-translate": { |
79 // "url": "myprogram.pexe", | 78 // "url": "myprogram.pexe", |
80 // "sha256": "...", | |
81 // "-O": 0 | 79 // "-O": 0 |
82 // } | 80 // } |
83 // } | 81 // } |
84 // }, | 82 // }, |
85 // "files": { | 83 // "files": { |
86 // "foo.txt": { | 84 // "foo.txt": { |
87 // "portable": {"url": "foo.txt"} | 85 // "portable": {"url": "foo.txt"} |
88 // }, | 86 // }, |
89 // "bar.txt": { | 87 // "bar.txt": { |
90 // "portable": {"url": "bar.txt"} | 88 // "portable": {"url": "bar.txt"} |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 const nacl::string& sandbox_isa, | 160 const nacl::string& sandbox_isa, |
163 nacl::string* error_string) { | 161 nacl::string* error_string) { |
164 static const char* kManifestUrlSpecRequired[] = { | 162 static const char* kManifestUrlSpecRequired[] = { |
165 kUrlKey | 163 kUrlKey |
166 }; | 164 }; |
167 const char** urlSpecPlusOptional; | 165 const char** urlSpecPlusOptional; |
168 size_t urlSpecPlusOptionalLength; | 166 size_t urlSpecPlusOptionalLength; |
169 if (sandbox_isa == kPortableKey) { | 167 if (sandbox_isa == kPortableKey) { |
170 static const char* kPnaclUrlSpecPlusOptional[] = { | 168 static const char* kPnaclUrlSpecPlusOptional[] = { |
171 kUrlKey, | 169 kUrlKey, |
172 kCacheIdentityKey, | |
173 kOptLevelKey, | 170 kOptLevelKey, |
174 }; | 171 }; |
175 urlSpecPlusOptional = kPnaclUrlSpecPlusOptional; | 172 urlSpecPlusOptional = kPnaclUrlSpecPlusOptional; |
176 urlSpecPlusOptionalLength = NACL_ARRAY_SIZE(kPnaclUrlSpecPlusOptional); | 173 urlSpecPlusOptionalLength = NACL_ARRAY_SIZE(kPnaclUrlSpecPlusOptional); |
177 } else { | 174 } else { |
178 urlSpecPlusOptional = kManifestUrlSpecRequired; | 175 urlSpecPlusOptional = kManifestUrlSpecRequired; |
179 urlSpecPlusOptionalLength = NACL_ARRAY_SIZE(kManifestUrlSpecRequired); | 176 urlSpecPlusOptionalLength = NACL_ARRAY_SIZE(kManifestUrlSpecRequired); |
180 } | 177 } |
181 if (!IsValidDictionary(url_spec, container_key, parent_key, | 178 if (!IsValidDictionary(url_spec, container_key, parent_key, |
182 urlSpecPlusOptional, | 179 urlSpecPlusOptional, |
(...skipping 16 matching lines...) Expand all Loading... |
199 // Verify the correct types of the fields if they exist. | 196 // Verify the correct types of the fields if they exist. |
200 Json::Value url = url_spec[kUrlKey]; | 197 Json::Value url = url_spec[kUrlKey]; |
201 if (!url.isString()) { | 198 if (!url.isString()) { |
202 nacl::stringstream error_stream; | 199 nacl::stringstream error_stream; |
203 error_stream << parent_key << " property '" << container_key << | 200 error_stream << parent_key << " property '" << container_key << |
204 "' has non-string value '" << url.toStyledString() << | 201 "' has non-string value '" << url.toStyledString() << |
205 "' for key '" << kUrlKey << "'."; | 202 "' for key '" << kUrlKey << "'."; |
206 *error_string = error_stream.str(); | 203 *error_string = error_stream.str(); |
207 return false; | 204 return false; |
208 } | 205 } |
209 Json::Value cache_identity = url_spec[kCacheIdentityKey]; | |
210 if (!cache_identity.empty() && !cache_identity.isString()) { | |
211 nacl::stringstream error_stream; | |
212 error_stream << parent_key << " property '" << container_key << | |
213 "' has non-string value '" << cache_identity.toStyledString() << | |
214 "' for key '" << kCacheIdentityKey << "'."; | |
215 *error_string = error_stream.str(); | |
216 return false; | |
217 } | |
218 Json::Value opt_level = url_spec[kOptLevelKey]; | 206 Json::Value opt_level = url_spec[kOptLevelKey]; |
219 if (!opt_level.empty() && !opt_level.isNumeric()) { | 207 if (!opt_level.empty() && !opt_level.isNumeric()) { |
220 nacl::stringstream error_stream; | 208 nacl::stringstream error_stream; |
221 error_stream << parent_key << " property '" << container_key << | 209 error_stream << parent_key << " property '" << container_key << |
222 "' has non-numeric value '" << opt_level.toStyledString() << | 210 "' has non-numeric value '" << opt_level.toStyledString() << |
223 "' for key '" << kOptLevelKey << "'."; | 211 "' for key '" << kOptLevelKey << "'."; |
224 *error_string = error_stream.str(); | 212 *error_string = error_stream.str(); |
225 return false; | 213 return false; |
226 } | 214 } |
227 return true; | 215 return true; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 356 } |
369 } | 357 } |
370 | 358 |
371 return true; | 359 return true; |
372 } | 360 } |
373 | 361 |
374 void GrabUrlAndPnaclOptions(const Json::Value& url_spec, | 362 void GrabUrlAndPnaclOptions(const Json::Value& url_spec, |
375 nacl::string* url, | 363 nacl::string* url, |
376 PnaclOptions* pnacl_options) { | 364 PnaclOptions* pnacl_options) { |
377 *url = url_spec[kUrlKey].asString(); | 365 *url = url_spec[kUrlKey].asString(); |
378 if (url_spec.isMember(kCacheIdentityKey)) { | |
379 pnacl_options->set_bitcode_hash(url_spec[kCacheIdentityKey].asString()); | |
380 } | |
381 if (url_spec.isMember(kOptLevelKey)) { | 366 if (url_spec.isMember(kOptLevelKey)) { |
382 uint32_t opt_raw = url_spec[kOptLevelKey].asUInt(); | 367 uint32_t opt_raw = url_spec[kOptLevelKey].asUInt(); |
383 // Clamp the opt value to fit into an int8_t. | 368 // Clamp the opt value to fit into an int8_t. |
384 if (opt_raw > 3) | 369 if (opt_raw > 3) |
385 opt_raw = 3; | 370 opt_raw = 3; |
386 pnacl_options->set_opt_level(static_cast<int8_t>(opt_raw)); | 371 pnacl_options->set_opt_level(static_cast<int8_t>(opt_raw)); |
387 } | 372 } |
388 if (url_spec.isMember(kPnaclExperimentalFlags)) { | 373 if (url_spec.isMember(kPnaclExperimentalFlags)) { |
389 pnacl_options->set_experimental_flags( | 374 pnacl_options->set_experimental_flags( |
390 url_spec[kPnaclExperimentalFlags].asString()); | 375 url_spec[kPnaclExperimentalFlags].asString()); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 error_info->SetReport( | 650 error_info->SetReport( |
666 ERROR_MANIFEST_RESOLVE_URL, | 651 ERROR_MANIFEST_RESOLVE_URL, |
667 nacl::string("ResolveKey: no such \"files\" entry: ") + key); | 652 nacl::string("ResolveKey: no such \"files\" entry: ") + key); |
668 return false; | 653 return false; |
669 } | 654 } |
670 return GetKeyUrl(files, rest, sandbox_isa_, this, full_url, pnacl_options, | 655 return GetKeyUrl(files, rest, sandbox_isa_, this, full_url, pnacl_options, |
671 error_info); | 656 error_info); |
672 } | 657 } |
673 | 658 |
674 } // namespace plugin | 659 } // namespace plugin |
OLD | NEW |