OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client 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 <assert.h> | 7 #include <assert.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 #include <string.h> | 11 #include <string.h> |
12 | 12 |
13 #include "native_client/src/include/elf32.h" | 13 #include "native_client/src/include/elf32.h" |
14 #include "native_client/src/include/elf64.h" | 14 #include "native_client/src/include/elf64.h" |
15 #include "native_client/src/shared/platform/nacl_check.h" | 15 #include "native_client/src/shared/platform/nacl_check.h" |
16 #include "native_client/src/shared/utils/types.h" | 16 #include "native_client/src/shared/utils/types.h" |
17 #include "native_client/src/trusted/validator_ragel/unreviewed/validator_interna l.h" | 17 #include "native_client/src/trusted/validator_ragel/validator_internal.h" |
18 | 18 |
19 /* This is a copy of NaClLog from shared/platform/nacl_log.c to avoid | 19 /* This is a copy of NaClLog from shared/platform/nacl_log.c to avoid |
20 * linking in code in NaCl shared code in the unreviewed/Makefile and be able to | 20 * linking in code in NaCl shared code in the unreviewed/Makefile and be able to |
21 * use CHECK(). | 21 * use CHECK(). |
22 | 22 |
23 * TODO(khim): remove the copy of NaClLog implementation as soon as | 23 * TODO(khim): remove the copy of NaClLog implementation as soon as |
24 * unreviewed/Makefile is eliminated. | 24 * unreviewed/Makefile is eliminated. |
25 */ | 25 */ |
26 void NaClLog(int detail_level, char const *fmt, ...) { | 26 void NaClLog(int detail_level, char const *fmt, ...) { |
27 va_list ap; | 27 va_list ap; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 | 225 |
226 ReadImage(filename, &data, &data_size); | 226 ReadImage(filename, &data, &data_size); |
227 | 227 |
228 for (count = 0; count < repeat_count; ++count) { | 228 for (count = 0; count < repeat_count; ++count) { |
229 Bool rc = FALSE; | 229 Bool rc = FALSE; |
230 if (raw_bitness == 0) | 230 if (raw_bitness == 0) |
231 rc = ValidateElf(filename, | 231 rc = ValidateElf(filename, |
232 data, data_size, | 232 data, data_size, |
233 options, | 233 options, |
234 cpu_features); | 234 cpu_features); |
235 else if (raw_bitness == 32) { | 235 else if (raw_bitness == 32) { |
Brad Chen
2012/10/05 16:47:21
This looks like non-standard formatting for if sta
khim
2012/10/15 16:38:57
Actually the style guide contains few recommendati
| |
236 struct ValidateState state; | 236 struct ValidateState state; |
237 state.offset = data; | 237 state.offset = data; |
238 CHECK(data_size % kBundleSize == 0); | 238 CHECK(data_size % kBundleSize == 0); |
239 rc = ValidateChunkIA32(data, data_size, | 239 rc = ValidateChunkIA32(data, data_size, |
240 options, cpu_features, | 240 options, cpu_features, |
241 ProcessError, &state); | 241 ProcessError, &state); |
242 } | 242 } |
243 else if (raw_bitness == 64) { | 243 else if (raw_bitness == 64) { |
244 struct ValidateState state; | 244 struct ValidateState state; |
245 state.offset = data; | 245 state.offset = data; |
246 CHECK(data_size % kBundleSize == 0); | 246 CHECK(data_size % kBundleSize == 0); |
247 rc = ValidateChunkAMD64(data, data_size, | 247 rc = ValidateChunkAMD64(data, data_size, |
248 options, cpu_features, | 248 options, cpu_features, |
249 ProcessError, &state); | 249 ProcessError, &state); |
250 } | 250 } |
251 if (!rc) { | 251 if (!rc) { |
252 printf("file '%s' can not be fully validated\n", filename); | 252 printf("file '%s' can not be fully validated\n", filename); |
253 exit(1); | 253 exit(1); |
254 } | 254 } |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 int main(int argc, char **argv) { | 258 int main(int argc, char **argv) { |
259 int index, initial_index = 1, repeat_count = 1; | 259 int index, initial_index = 1, repeat_count = 1; |
260 const NaClCPUFeaturesX86 *cpu_features = &full_cpuid_features; | 260 const NaClCPUFeaturesX86 *cpu_features = &kFullCPUIDFeatures; |
261 int raw_bitness = 0; | 261 int raw_bitness = 0; |
262 enum validation_options options = 0; | 262 enum validation_options options = 0; |
263 | 263 |
264 if (argc == 1) { | 264 if (argc == 1) { |
265 printf("%s: no input files\n", argv[0]); | 265 printf("%s: no input files\n", argv[0]); |
266 return 2; | 266 return 2; |
267 } | 267 } |
268 while (initial_index < argc) { | 268 while (initial_index < argc) { |
269 char *arg = argv[initial_index]; | 269 char *arg = argv[initial_index]; |
270 if (!strcmp(arg, "--repeat")) { | 270 if (!strcmp(arg, "--repeat")) { |
271 if (initial_index+1 >= argc) { | 271 if (initial_index+1 >= argc) { |
272 printf("%s: no integer after --repeat\n", argv[0]); | 272 printf("%s: no integer after --repeat\n", argv[0]); |
273 return 2; | 273 return 2; |
274 } | 274 } |
275 repeat_count = atoi(argv[initial_index + 1]); | 275 repeat_count = atoi(argv[initial_index + 1]); |
276 initial_index += 2; | 276 initial_index += 2; |
277 } | 277 } |
278 else if (!strcmp(arg, "--compatible")) { | 278 else if (!strcmp(arg, "--compatible")) { |
279 cpu_features = &validator_cpuid_features; | 279 cpu_features = &kValidatorCPUIDFeatures; |
280 initial_index++; | 280 initial_index++; |
281 } | 281 } |
282 else if (!strcmp(arg, "--nobundles")) { | 282 else if (!strcmp(arg, "--nobundles")) { |
283 options |= PROCESS_CHUNK_AS_A_CONTIGUOUS_STREAM; | 283 options |= PROCESS_CHUNK_AS_A_CONTIGUOUS_STREAM; |
284 initial_index++; | 284 initial_index++; |
285 } | 285 } |
286 else if (!strcmp(argv[initial_index], "--raw32")) { | 286 else if (!strcmp(argv[initial_index], "--raw32")) { |
287 raw_bitness = 32; | 287 raw_bitness = 32; |
288 initial_index++; | 288 initial_index++; |
289 } | 289 } |
290 else if (!strcmp(argv[initial_index], "--raw64")) { | 290 else if (!strcmp(argv[initial_index], "--raw64")) { |
291 raw_bitness = 64; | 291 raw_bitness = 64; |
292 initial_index++; | 292 initial_index++; |
293 } | 293 } |
294 else | 294 else |
295 break; | 295 break; |
296 } | 296 } |
297 for (index = initial_index; index < argc; ++index) { | 297 for (index = initial_index; index < argc; ++index) { |
298 const char *filename = argv[index]; | 298 const char *filename = argv[index]; |
299 ProcessFile(filename, repeat_count, raw_bitness, options, cpu_features); | 299 ProcessFile(filename, repeat_count, raw_bitness, options, cpu_features); |
300 } | 300 } |
301 return 0; | 301 return 0; |
302 } | 302 } |
OLD | NEW |