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 manifest file: | 47 // Sample 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 // "portable": { | 53 // "portable": { |
55 // "pnacl-translate": { | 54 // "pnacl-translate": { |
56 // "url": "myprogram.pexe", | 55 // "url": "myprogram.pexe", |
57 // "sha256": "...", | |
58 // "-O": 0 | 56 // "-O": 0 |
59 // } | 57 // } |
60 // } | 58 // } |
61 // }, | 59 // }, |
62 // "interpreter": { | 60 // "interpreter": { |
63 // "x86-32": {"url": "interpreter_x86-32.nexe"}, | 61 // "x86-32": {"url": "interpreter_x86-32.nexe"}, |
64 // "x86-64": {"url": "interpreter_x86-64.nexe"}, | 62 // "x86-64": {"url": "interpreter_x86-64.nexe"}, |
65 // "arm": {"url": "interpreter_arm.nexe"} | 63 // "arm": {"url": "interpreter_arm.nexe"} |
66 // }, | 64 // }, |
67 // "files": { | 65 // "files": { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // E.g., "container_key" : { "url": "foo.txt" } | 144 // E.g., "container_key" : { "url": "foo.txt" } |
147 bool IsValidUrlSpec(const Json::Value& url_spec, | 145 bool IsValidUrlSpec(const Json::Value& url_spec, |
148 const nacl::string& container_key, | 146 const nacl::string& container_key, |
149 const nacl::string& parent_key, | 147 const nacl::string& parent_key, |
150 nacl::string* error_string) { | 148 nacl::string* error_string) { |
151 static const char* kManifestUrlSpecRequired[] = { | 149 static const char* kManifestUrlSpecRequired[] = { |
152 kUrlKey | 150 kUrlKey |
153 }; | 151 }; |
154 static const char* kManifestUrlSpecPlusOptional[] = { | 152 static const char* kManifestUrlSpecPlusOptional[] = { |
155 kUrlKey, | 153 kUrlKey, |
156 kCacheIdentityKey | |
157 }; | 154 }; |
158 if (!IsValidDictionary(url_spec, container_key, parent_key, | 155 if (!IsValidDictionary(url_spec, container_key, parent_key, |
159 kManifestUrlSpecPlusOptional, | 156 kManifestUrlSpecPlusOptional, |
160 NACL_ARRAY_SIZE(kManifestUrlSpecPlusOptional), | 157 NACL_ARRAY_SIZE(kManifestUrlSpecPlusOptional), |
161 kManifestUrlSpecRequired, | 158 kManifestUrlSpecRequired, |
162 NACL_ARRAY_SIZE(kManifestUrlSpecRequired), | 159 NACL_ARRAY_SIZE(kManifestUrlSpecRequired), |
163 error_string)) { | 160 error_string)) { |
164 return false; | 161 return false; |
165 } | 162 } |
166 Json::Value url = url_spec[kUrlKey]; | 163 Json::Value url = url_spec[kUrlKey]; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 } | 264 } |
268 } | 265 } |
269 | 266 |
270 return true; | 267 return true; |
271 } | 268 } |
272 | 269 |
273 void GrabUrlAndPnaclOptions(const Json::Value& url_spec, | 270 void GrabUrlAndPnaclOptions(const Json::Value& url_spec, |
274 nacl::string* url, | 271 nacl::string* url, |
275 PnaclOptions* pnacl_options) { | 272 PnaclOptions* pnacl_options) { |
276 *url = url_spec[kUrlKey].asString(); | 273 *url = url_spec[kUrlKey].asString(); |
277 if (url_spec.isMember(kCacheIdentityKey)) { | |
278 pnacl_options->set_bitcode_hash(url_spec[kCacheIdentityKey].asString()); | |
279 } | |
280 if (url_spec.isMember(kOptLevelKey)) { | 274 if (url_spec.isMember(kOptLevelKey)) { |
281 uint32_t opt_raw = url_spec[kOptLevelKey].asUInt(); | 275 uint32_t opt_raw = url_spec[kOptLevelKey].asUInt(); |
282 // Clamp the opt value to fit into an int8_t. | 276 // Clamp the opt value to fit into an int8_t. |
283 if (opt_raw > 3) | 277 if (opt_raw > 3) |
284 opt_raw = 3; | 278 opt_raw = 3; |
285 pnacl_options->set_opt_level(static_cast<int8_t>(opt_raw)); | 279 pnacl_options->set_opt_level(static_cast<int8_t>(opt_raw)); |
286 } | 280 } |
287 if (url_spec.isMember(kPnaclExperimentalFlags)) { | 281 if (url_spec.isMember(kPnaclExperimentalFlags)) { |
288 pnacl_options->set_experimental_flags( | 282 pnacl_options->set_experimental_flags( |
289 url_spec[kPnaclExperimentalFlags].asString()); | 283 url_spec[kPnaclExperimentalFlags].asString()); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 error_info->SetReport( | 546 error_info->SetReport( |
553 ERROR_MANIFEST_RESOLVE_URL, | 547 ERROR_MANIFEST_RESOLVE_URL, |
554 nacl::string("ResolveKey: no such \"files\" entry: ") + key); | 548 nacl::string("ResolveKey: no such \"files\" entry: ") + key); |
555 return false; | 549 return false; |
556 } | 550 } |
557 return GetKeyUrl(files, rest, sandbox_isa_, this, prefer_portable_, | 551 return GetKeyUrl(files, rest, sandbox_isa_, this, prefer_portable_, |
558 full_url, pnacl_options, error_info); | 552 full_url, pnacl_options, error_info); |
559 } | 553 } |
560 | 554 |
561 } // namespace plugin | 555 } // namespace plugin |
OLD | NEW |