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

Side by Side Diff: src/trusted/validator_ragel/unreviewed/validator_internal.h

Issue 12226019: Move bitmap manipulation functions in bitmap.h (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 7 years, 10 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) 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 /* 7 /*
8 * This file contains common parts of x86-32 and x86-64 internals (inline 8 * This file contains common parts of x86-32 and x86-64 internals (inline
9 * functions and defines). 9 * functions and defines).
10 */ 10 */
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 #define SET_IMM_TYPE_IMM8 (instruction_info_collected += IMMEDIATE_8BIT) 241 #define SET_IMM_TYPE_IMM8 (instruction_info_collected += IMMEDIATE_8BIT)
242 #define SET_IMM_TYPE_IMM16 (instruction_info_collected += IMMEDIATE_16BIT) 242 #define SET_IMM_TYPE_IMM16 (instruction_info_collected += IMMEDIATE_16BIT)
243 #define SET_IMM_TYPE_IMM32 (instruction_info_collected += IMMEDIATE_32BIT) 243 #define SET_IMM_TYPE_IMM32 (instruction_info_collected += IMMEDIATE_32BIT)
244 #define SET_IMM_TYPE_IMM64 (instruction_info_collected += IMMEDIATE_64BIT) 244 #define SET_IMM_TYPE_IMM64 (instruction_info_collected += IMMEDIATE_64BIT)
245 #define SET_IMM2_TYPE(T) SET_IMM2_TYPE_##T 245 #define SET_IMM2_TYPE(T) SET_IMM2_TYPE_##T
246 #define SET_IMM2_TYPE_IMM8 \ 246 #define SET_IMM2_TYPE_IMM8 \
247 (instruction_info_collected += SECOND_IMMEDIATE_8BIT) 247 (instruction_info_collected += SECOND_IMMEDIATE_8BIT)
248 #define SET_IMM2_TYPE_IMM16 \ 248 #define SET_IMM2_TYPE_IMM16 \
249 (instruction_info_collected += SECOND_IMMEDIATE_16BIT) 249 (instruction_info_collected += SECOND_IMMEDIATE_16BIT)
250 250
251 #define BITMAP_WORD_NAME BITMAP_WORD_NAME1(NACL_HOST_WORDSIZE)
252 #define BITMAP_WORD_NAME1(size) BITMAP_WORD_NAME2(size)
253 #define BITMAP_WORD_NAME2(size) uint##size##_t
254
255 typedef BITMAP_WORD_NAME bitmap_word;
256
257 static INLINE bitmap_word *BitmapAllocate(size_t indexes) {
258 bitmap_word *bitmap;
259 size_t byte_count = ((indexes + NACL_HOST_WORDSIZE - 1) / NACL_HOST_WORDSIZE)*
260 sizeof *bitmap;
261 bitmap = malloc(byte_count);
262 if (bitmap != NULL) {
263 memset(bitmap, 0, byte_count);
264 }
265 return bitmap;
266 }
267
268 static FORCEINLINE int BitmapIsBitSet(bitmap_word *bitmap, size_t index) {
269 return (bitmap[index / NACL_HOST_WORDSIZE] &
270 (((bitmap_word)1) << (index % NACL_HOST_WORDSIZE))) != 0;
271 }
272
273 static FORCEINLINE void BitmapSetBit(bitmap_word *bitmap, size_t index) {
274 bitmap[index / NACL_HOST_WORDSIZE] |=
275 ((bitmap_word)1) << (index % NACL_HOST_WORDSIZE);
276 }
277
278 static FORCEINLINE void BitmapClearBit(bitmap_word *bitmap, size_t index) {
279 bitmap[index / NACL_HOST_WORDSIZE] &=
280 ~(((bitmap_word)1) << (index % NACL_HOST_WORDSIZE));
281 }
282
283 /* All the bits must be in a single 32-bit bundle. */
284 static FORCEINLINE int BitmapIsAnyBitSet(bitmap_word *bitmap,
285 size_t index, size_t bits) {
286 return (bitmap[index / NACL_HOST_WORDSIZE] &
287 (((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE))) != 0;
288 }
289
290 /* All the bits must be in a single 32-bit bundle. */
291 static FORCEINLINE void BitmapSetBits(bitmap_word *bitmap,
292 size_t index,
293 size_t bits) {
294 bitmap[index / NACL_HOST_WORDSIZE] |=
295 ((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE);
296 }
297
298 /* All the bits must be in a single 32-bit bundle. */
299 static FORCEINLINE void BitmapClearBits(bitmap_word *bitmap,
300 size_t index, size_t bits) {
301 bitmap[index / NACL_HOST_WORDSIZE] &=
302 ~(((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE));
303 }
304
305 /* Mark the destination of a jump instruction and make an early validity check: 251 /* Mark the destination of a jump instruction and make an early validity check:
306 * to jump outside given code region, the target address must be aligned. 252 * to jump outside given code region, the target address must be aligned.
307 * 253 *
308 * Returns TRUE iff the jump passes the early validity check. 254 * Returns TRUE iff the jump passes the early validity check.
309 */ 255 */
310 static FORCEINLINE int MarkJumpTarget(size_t jump_dest, 256 static FORCEINLINE int MarkJumpTarget(size_t jump_dest,
311 bitmap_word *jump_dests, 257 bitmap_word *jump_dests,
312 size_t size) { 258 size_t size) {
313 if ((jump_dest & kBundleMask) == 0) { 259 if ((jump_dest & kBundleMask) == 0) {
314 return TRUE; 260 return TRUE;
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 const uint8_t *data, 804 const uint8_t *data,
859 bitmap_word *valid_targets) { 805 bitmap_word *valid_targets) {
860 if (VerifyNaclCallOrJmpAddToReg(*instruction_start, current_position)) 806 if (VerifyNaclCallOrJmpAddToReg(*instruction_start, current_position))
861 ExpandSuperinstructionBySandboxingBytes( 807 ExpandSuperinstructionBySandboxingBytes(
862 4 /* and */ + 3 /* add */, instruction_start, data, valid_targets); 808 4 /* and */ + 3 /* add */, instruction_start, data, valid_targets);
863 else 809 else
864 *instruction_info_collected |= UNRECOGNIZED_INSTRUCTION; 810 *instruction_info_collected |= UNRECOGNIZED_INSTRUCTION;
865 } 811 }
866 812
867 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_VALIDATOR_INTERNAL_H_ */ 813 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_VALIDATOR_INTERNAL_H_ */
OLDNEW
« no previous file with comments | « src/trusted/validator_ragel/unreviewed/dfa_validate_64.c ('k') | src/trusted/validator_ragel/unreviewed/validator_x86_32.rl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698