Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: src/trusted/validator_ragel/unreviewed/validator-test.c

Issue 9968039: Add ragel machine generators to SCONS (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/trusted/validator_ragel/unreviewed/validator-test.c
===================================================================
--- src/trusted/validator_ragel/unreviewed/validator-test.c (revision 8189)
+++ src/trusted/validator_ragel/unreviewed/validator-test.c (working copy)
@@ -5,29 +5,41 @@
*/
#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
+/* This is a copy of NaClLog_Function from shared/platform/nacl_log.c to avoid
+ * linking in code in NaCl shared code in the unreviewed/Makefile and be able to
+ * use CHECK().
-/* This may help with portability but makes code less readable. */
-#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
+ * TODO(khim): remove the copy of NaClLog_Function implementation as soon as
+ *unreviewed/Makefile is eliminated.
+ */
+void NaClLog_Function(int detail_level, char const *fmt, ...) {
+ va_list ap;
+ 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 +78,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 +105,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 +117,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 +141,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 +155,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;

Powered by Google App Engine
This is Rietveld 408576698