Chromium Code Reviews| Index: src/trusted/validator_ragel/unreviewed/validator-test.c |
| =================================================================== |
| --- src/trusted/validator_ragel/unreviewed/validator-test.c (revision 8170) |
| +++ src/trusted/validator_ragel/unreviewed/validator-test.c (working copy) |
| @@ -5,29 +5,34 @@ |
| */ |
| #include <assert.h> |
| -#include <elf.h> |
| -#include <inttypes.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| -#include "validator.h" |
| -#undef TRUE |
| -#define TRUE 1 |
| +#include "native_client/src/include/elf32.h" |
| +#include "native_client/src/include/elf64.h" |
| +#include "native_client/src/shared/platform/nacl_check.h" |
| +#include "native_client/src/shared/utils/types.h" |
| +#include "native_client/src/trusted/validator_ragel/unreviewed/validator.h" |
| -#undef FALSE |
| -#define FALSE 0 |
| +void NaClLog_Function(int detail_level, char const *fmt, ...) { |
|
pasko-google - do not use
2012/04/06 15:23:58
same TODO here please
khim
2012/04/06 15:30:04
Done.
|
| + va_list ap; |
| -/* This may help with portability but makes code less readable. */ |
| -#pragma GCC diagnostic ignored "-Wdeclaration-after-statement" |
| + va_start(ap, fmt); |
| + vfprintf(stderr, fmt, ap); |
| + exit(1); |
| + NaClLogV_mu(detail_level, fmt, ap); |
| + va_end(ap); |
| + NaClLogUnlock(); |
| +} |
| static void CheckBounds(unsigned char *data, size_t data_size, |
| void *ptr, size_t inside_size) { |
| - assert(data <= (unsigned char *) ptr); |
| - assert((unsigned char *) ptr + inside_size <= data + data_size); |
| + CHECK(data <= (unsigned char *) ptr); |
| + CHECK((unsigned char *) ptr + inside_size <= data + data_size); |
| } |
| -void ReadFile(const char *filename, uint8_t **result, size_t *result_size) { |
| +void ReadImage(const char *filename, uint8_t **result, size_t *result_size) { |
| FILE *fp; |
| uint8_t *data; |
| size_t file_size; |
| @@ -66,16 +71,17 @@ |
| }; |
| void ProcessError (const uint8_t *ptr, void *userdata) { |
| - printf("offset 0x%zx: DFA error in validator\n", |
| - ptr - (((struct ValidateState *)userdata)->offset)); |
| + printf("offset 0x%"NACL_PRIxS": DFA error in validator\n", |
| + ptr - (((struct ValidateState *)userdata)->offset)); |
| } |
| int ValidateFile(const char *filename, int repeat_count) { |
| size_t data_size; |
| uint8_t *data; |
| - ReadFile(filename, &data, &data_size); |
| + int count; |
| - int count; |
| + ReadImage(filename, &data, &data_size); |
| + |
| if (data[4] == 1) { |
| for (count = 0; count < repeat_count; ++count) { |
| Elf32_Ehdr *header; |
| @@ -92,6 +98,8 @@ |
| if ((section->sh_flags & SHF_EXECINSTR) != 0) { |
| struct ValidateState state; |
| + int res; |
| + |
| state.offset = data + section->sh_offset - section->sh_addr; |
| if (section->sh_size <= 0xfff) { |
| state.width = 4; |
| @@ -102,7 +110,7 @@ |
| } |
| CheckBounds(data, data_size, |
| data + section->sh_offset, section->sh_size); |
| - int res = ValidateChunkIA32(data + section->sh_offset, |
| + res = ValidateChunkIA32(data + section->sh_offset, |
| section->sh_size, ProcessError, &state); |
| if (res != 0) { |
| return res; |
| @@ -126,6 +134,8 @@ |
| if ((section->sh_flags & SHF_EXECINSTR) != 0) { |
| struct ValidateState state; |
| + int res; |
| + |
| state.offset = data + section->sh_offset - section->sh_addr; |
| if (section->sh_size <= 0xfff) { |
| state.width = 4; |
| @@ -138,7 +148,7 @@ |
| } |
| CheckBounds(data, data_size, |
| data + section->sh_offset, section->sh_size); |
| - int res = ValidateChunkAMD64(data + section->sh_offset, |
| + res = ValidateChunkAMD64(data + section->sh_offset, |
| section->sh_size, ProcessError, &state); |
| if (res != 0) { |
| return res; |