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

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

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 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" 12
13 #include "native_client/src/trusted/validator_ragel/unreviewed/validator.h"
14
15 #if defined(_MSC_VER)
16 #define inline __inline
17 #endif
15 18
16 #undef TRUE 19 #undef TRUE
17 #define TRUE 1 20 #define TRUE 1
18 21
19 #undef FALSE 22 #undef FALSE
20 #define FALSE 0 23 #define FALSE 0
21 24
22 #define check_jump_dest \ 25 #define check_jump_dest \
23 if ((jump_dest & bundle_mask) != bundle_mask) { \ 26 if ((jump_dest & bundle_mask) != bundle_mask) { \
24 if (jump_dest >= size) { \ 27 if (jump_dest >= size) { \
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 111
109 enum disp_mode { 112 enum disp_mode {
110 DISPNONE, 113 DISPNONE,
111 DISP8, 114 DISP8,
112 DISP16, 115 DISP16,
113 DISP32 116 DISP32
114 }; 117 };
115 118
116 static const int kBitsPerByte = 8; 119 static const int kBitsPerByte = 8;
117 120
118 static inline uint8_t *BitmapAllocate(uint32_t indexes) { 121 static inline uint8_t *BitmapAllocate(size_t indexes) {
119 uint32_t byte_count = (indexes + kBitsPerByte - 1) / kBitsPerByte; 122 size_t byte_count = (indexes + kBitsPerByte - 1) / kBitsPerByte;
120 uint8_t *bitmap = malloc(byte_count); 123 uint8_t *bitmap = malloc(byte_count);
121 if (bitmap != NULL) { 124 if (bitmap != NULL) {
122 memset(bitmap, 0, byte_count); 125 memset(bitmap, 0, byte_count);
123 } 126 }
124 return bitmap; 127 return bitmap;
125 } 128 }
126 129
127 static inline int BitmapIsBitSet(uint8_t *bitmap, uint32_t index) { 130 static inline int BitmapIsBitSet(uint8_t *bitmap, size_t index) {
128 return (bitmap[index / kBitsPerByte] & (1 << (index % kBitsPerByte))) != 0; 131 return (bitmap[index / kBitsPerByte] & (1 << (index % kBitsPerByte))) != 0;
129 } 132 }
130 133
131 static inline void BitmapSetBit(uint8_t *bitmap, uint32_t index) { 134 static inline void BitmapSetBit(uint8_t *bitmap, size_t index) {
132 bitmap[index / kBitsPerByte] |= 1 << (index % kBitsPerByte); 135 bitmap[index / kBitsPerByte] |= 1 << (index % kBitsPerByte);
133 } 136 }
134 137
135 static inline void BitmapClearBit(uint8_t *bitmap, uint32_t index) { 138 static inline void BitmapClearBit(uint8_t *bitmap, size_t index) {
136 bitmap[index / kBitsPerByte] &= ~(1 << (index % kBitsPerByte)); 139 bitmap[index / kBitsPerByte] &= ~(1 << (index % kBitsPerByte));
137 } 140 }
138 141
139 static int CheckJumpTargets(uint8_t *valid_targets, uint8_t *jump_dests, 142 static int CheckJumpTargets(uint8_t *valid_targets, uint8_t *jump_dests,
140 size_t size) { 143 size_t size) {
141 size_t i; 144 size_t i;
142 for (i = 0; i < size / 32; i++) { 145 for (i = 0; i < size / 32; i++) {
143 uint32_t jump_dest_mask = ((uint32_t *) jump_dests)[i]; 146 uint32_t jump_dest_mask = ((uint32_t *) jump_dests)[i];
144 uint32_t valid_target_mask = ((uint32_t *) valid_targets)[i]; 147 uint32_t valid_target_mask = ((uint32_t *) valid_targets)[i];
145 if ((jump_dest_mask & ~valid_target_mask) != 0) { 148 if ((jump_dest_mask & ~valid_target_mask) != 0) {
(...skipping 28 matching lines...) Expand all
174 %% write exec; 177 %% write exec;
175 } 178 }
176 179
177 if (CheckJumpTargets(valid_targets, jump_dests, size)) { 180 if (CheckJumpTargets(valid_targets, jump_dests, size)) {
178 return 1; 181 return 1;
179 } 182 }
180 183
181 error_detected: 184 error_detected:
182 return result; 185 return result;
183 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698