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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 enum ValidationOptions options, | 234 enum ValidationOptions options, |
235 const NaClCPUFeaturesX86 *cpu_features) { | 235 const NaClCPUFeaturesX86 *cpu_features) { |
236 size_t data_size; | 236 size_t data_size; |
237 uint8_t *data; | 237 uint8_t *data; |
238 int count; | 238 int count; |
239 | 239 |
240 ReadImage(filename, &data, &data_size); | 240 ReadImage(filename, &data, &data_size); |
241 | 241 |
242 for (count = 0; count < repeat_count; ++count) { | 242 for (count = 0; count < repeat_count; ++count) { |
243 Bool rc = FALSE; | 243 Bool rc = FALSE; |
244 if (raw_bitness == 0) | 244 if (raw_bitness == 0) { |
245 rc = ValidateElf(filename, | 245 rc = ValidateElf(filename, |
246 data, data_size, | 246 data, data_size, |
247 warnings, | 247 warnings, |
248 options, | 248 options, |
249 cpu_features); | 249 cpu_features); |
250 else if (raw_bitness == 32) { | 250 } else if (raw_bitness == 32) { |
251 struct ValidateState state; | 251 struct ValidateState state; |
252 state.offset = data; | 252 state.offset = data; |
253 CHECK(data_size % kBundleSize == 0); | 253 CHECK(data_size % kBundleSize == 0); |
254 rc = ValidateChunkIA32(data, data_size, | 254 rc = ValidateChunkIA32(data, data_size, |
255 options, cpu_features, | 255 options, cpu_features, |
256 warnings ? ProcessErrorOrWarning : ProcessError, | 256 warnings ? ProcessErrorOrWarning : ProcessError, |
257 &state); | 257 &state); |
258 } | 258 } else if (raw_bitness == 64) { |
259 else if (raw_bitness == 64) { | |
260 struct ValidateState state; | 259 struct ValidateState state; |
261 state.offset = data; | 260 state.offset = data; |
262 CHECK(data_size % kBundleSize == 0); | 261 CHECK(data_size % kBundleSize == 0); |
263 rc = ValidateChunkAMD64(data, data_size, | 262 rc = ValidateChunkAMD64(data, data_size, |
264 options, cpu_features, | 263 options, cpu_features, |
265 warnings ? ProcessErrorOrWarning : ProcessError, | 264 warnings ? ProcessErrorOrWarning : ProcessError, |
266 &state); | 265 &state); |
267 } | 266 } |
268 if (!rc) { | 267 if (!rc) { |
269 printf("file '%s' can not be fully validated\n", filename); | 268 printf("file '%s' can not be fully validated\n", filename); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 break; | 311 break; |
313 } | 312 } |
314 } | 313 } |
315 for (index = initial_index; index < argc; ++index) { | 314 for (index = initial_index; index < argc; ++index) { |
316 const char *filename = argv[index]; | 315 const char *filename = argv[index]; |
317 ProcessFile(filename, repeat_count, raw_bitness, warnings, options, | 316 ProcessFile(filename, repeat_count, raw_bitness, warnings, options, |
318 cpu_features); | 317 cpu_features); |
319 } | 318 } |
320 return 0; | 319 return 0; |
321 } | 320 } |
OLD | NEW |