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

Side by Side Diff: src/trusted/validator_ragel/unreviewed/validator-x86_32.rl

Issue 10031039: Add ragel validator 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2011 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 <elf.h>
9 #include <inttypes.h>
10 #include <stddef.h> 8 #include <stddef.h>
11 #include <stdio.h> 9 #include <stdio.h>
12 #include <stdlib.h> 10 #include <stdlib.h>
13 #include <string.h> 11 #include <string.h>
14 #include "validator.h"
15 12
16 #undef TRUE 13 #include "native_client/src/shared/utils/types.h"
17 #define TRUE 1 14 #include "native_client/src/trusted/validator_ragel/unreviewed/validator.h"
18 15
19 #undef FALSE 16 #if defined(_MSC_VER)
20 #define FALSE 0 17 #define inline __inline
18 #endif
21 19
22 #define check_jump_dest \ 20 #define check_jump_dest \
23 if ((jump_dest & bundle_mask) != bundle_mask) { \ 21 if ((jump_dest & bundle_mask) != bundle_mask) { \
24 if (jump_dest >= size) { \ 22 if (jump_dest >= size) { \
25 printf("direct jump out of range: %zx\n", jump_dest); \ 23 printf("direct jump out of range: %"NACL_PRIxS"\n", jump_dest); \
26 result = 1; \ 24 result = 1; \
27 goto error_detected; \ 25 goto error_detected; \
28 } else { \ 26 } else { \
29 BitmapSetBit(jump_dests, jump_dest + 1); \ 27 BitmapSetBit(jump_dests, jump_dest + 1); \
30 } \ 28 } \
31 } 29 }
32 30
33 %%{ 31 %%{
34 machine x86_64_decoder; 32 machine x86_64_decoder;
35 alphtype unsigned char; 33 alphtype unsigned char;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 106
109 enum disp_mode { 107 enum disp_mode {
110 DISPNONE, 108 DISPNONE,
111 DISP8, 109 DISP8,
112 DISP16, 110 DISP16,
113 DISP32 111 DISP32
114 }; 112 };
115 113
116 static const int kBitsPerByte = 8; 114 static const int kBitsPerByte = 8;
117 115
118 static inline uint8_t *BitmapAllocate(uint32_t indexes) { 116 static inline uint8_t *BitmapAllocate(size_t indexes) {
119 uint32_t byte_count = (indexes + kBitsPerByte - 1) / kBitsPerByte; 117 size_t byte_count = (indexes + kBitsPerByte - 1) / kBitsPerByte;
120 uint8_t *bitmap = malloc(byte_count); 118 uint8_t *bitmap = malloc(byte_count);
121 if (bitmap != NULL) { 119 if (bitmap != NULL) {
122 memset(bitmap, 0, byte_count); 120 memset(bitmap, 0, byte_count);
123 } 121 }
124 return bitmap; 122 return bitmap;
125 } 123 }
126 124
127 static inline int BitmapIsBitSet(uint8_t *bitmap, uint32_t index) { 125 static inline int BitmapIsBitSet(uint8_t *bitmap, size_t index) {
128 return (bitmap[index / kBitsPerByte] & (1 << (index % kBitsPerByte))) != 0; 126 return (bitmap[index / kBitsPerByte] & (1 << (index % kBitsPerByte))) != 0;
129 } 127 }
130 128
131 static inline void BitmapSetBit(uint8_t *bitmap, uint32_t index) { 129 static inline void BitmapSetBit(uint8_t *bitmap, size_t index) {
132 bitmap[index / kBitsPerByte] |= 1 << (index % kBitsPerByte); 130 bitmap[index / kBitsPerByte] |= 1 << (index % kBitsPerByte);
133 } 131 }
134 132
135 static inline void BitmapClearBit(uint8_t *bitmap, uint32_t index) { 133 static inline void BitmapClearBit(uint8_t *bitmap, size_t index) {
136 bitmap[index / kBitsPerByte] &= ~(1 << (index % kBitsPerByte)); 134 bitmap[index / kBitsPerByte] &= ~(1 << (index % kBitsPerByte));
137 } 135 }
138 136
139 static int CheckJumpTargets(uint8_t *valid_targets, uint8_t *jump_dests, 137 static int CheckJumpTargets(uint8_t *valid_targets, uint8_t *jump_dests,
140 size_t size) { 138 size_t size) {
141 size_t i; 139 size_t i;
142 for (i = 0; i < size / 32; i++) { 140 for (i = 0; i < size / 32; i++) {
143 uint32_t jump_dest_mask = ((uint32_t *) jump_dests)[i]; 141 uint32_t jump_dest_mask = ((uint32_t *) jump_dests)[i];
144 uint32_t valid_target_mask = ((uint32_t *) valid_targets)[i]; 142 uint32_t valid_target_mask = ((uint32_t *) valid_targets)[i];
145 if ((jump_dest_mask & ~valid_target_mask) != 0) { 143 if ((jump_dest_mask & ~valid_target_mask) != 0) {
(...skipping 28 matching lines...) Expand all
174 %% write exec; 172 %% write exec;
175 } 173 }
176 174
177 if (CheckJumpTargets(valid_targets, jump_dests, size)) { 175 if (CheckJumpTargets(valid_targets, jump_dests, size)) {
178 return 1; 176 return 1;
179 } 177 }
180 178
181 error_detected: 179 error_detected:
182 return result; 180 return result;
183 } 181 }
OLDNEW
« no previous file with comments | « src/trusted/validator_ragel/unreviewed/validator-test.c ('k') | src/trusted/validator_ragel/unreviewed/validator-x86_64.rl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698