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

Unified Diff: src/trusted/validator_ragel/unreviewed/validator_internal.h

Issue 10860010: Fix uint8_t/unit32_t mix, always use wordsize access (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 4 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_internal.h
===================================================================
--- src/trusted/validator_ragel/unreviewed/validator_internal.h (revision 9487)
+++ src/trusted/validator_ragel/unreviewed/validator_internal.h (working copy)
@@ -137,27 +137,32 @@
#define SET_IMM2_TYPE(T)
#define SET_IMM2_PTR(P)
-static const int kBitsPerByte = 8;
+#define BITMAP_WORD_NAME BITMAP_WORD_NAME1(NACL_HOST_WORDSIZE)
+#define BITMAP_WORD_NAME1(size) BITMAP_WORD_NAME2(size)
+#define BITMAP_WORD_NAME2(size) uint##size##_t
-static INLINE uint8_t *BitmapAllocate(size_t indexes) {
- size_t byte_count = (indexes + kBitsPerByte - 1) / kBitsPerByte;
- uint8_t *bitmap = malloc(byte_count);
+typedef BITMAP_WORD_NAME bitmap_word;
+
+static INLINE bitmap_word *BitmapAllocate(size_t indexes) {
+ size_t byte_count = (indexes + NACL_HOST_WORDSIZE - 1) / NACL_HOST_WORDSIZE;
halyavin 2012/08/17 15:22:37 byte_count->word_count
+ bitmap_word *bitmap = malloc(byte_count/(NACL_HOST_WORDSIZE/8));
halyavin 2012/08/17 15:22:37 *sizeof(bitmap_word)
if (bitmap != NULL) {
memset(bitmap, 0, byte_count);
}
return bitmap;
}
-static FORCEINLINE int BitmapIsBitSet(uint8_t *bitmap, size_t index) {
- return (bitmap[index / kBitsPerByte] & (1 << (index % kBitsPerByte))) != 0;
+static FORCEINLINE int BitmapIsBitSet(bitmap_word *bitmap, size_t index) {
+ return (bitmap[index / NACL_HOST_WORDSIZE] &
+ (1 << (index % NACL_HOST_WORDSIZE))) != 0;
halyavin 2012/08/17 15:22:37 ((bitmap_word)1)
}
-static FORCEINLINE void BitmapSetBit(uint8_t *bitmap, size_t index) {
- bitmap[index / kBitsPerByte] |= 1 << (index % kBitsPerByte);
+static FORCEINLINE void BitmapSetBit(bitmap_word *bitmap, size_t index) {
+ bitmap[index / NACL_HOST_WORDSIZE] |= 1 << (index % NACL_HOST_WORDSIZE);
halyavin 2012/08/17 15:22:37 same
}
-static FORCEINLINE void BitmapClearBit(uint8_t *bitmap, size_t index) {
- bitmap[index / kBitsPerByte] &= ~(1 << (index % kBitsPerByte));
+static FORCEINLINE void BitmapClearBit(bitmap_word *bitmap, size_t index) {
+ bitmap[index / NACL_HOST_WORDSIZE] &= ~(1 << (index % NACL_HOST_WORDSIZE));
halyavin 2012/08/17 15:22:37 same
}
/* Mark the destination of a jump instruction and make an early validity check:
@@ -166,7 +171,7 @@
* Returns TRUE iff the jump passes the early validity check.
*/
static FORCEINLINE int MarkJumpTarget(size_t jump_dest,
- uint8_t *jump_dests,
+ bitmap_word *jump_dests,
size_t size) {
if ((jump_dest & kBundleMask) == 0) {
return TRUE;
@@ -182,21 +187,22 @@
static INLINE Bool ProcessInvalidJumpTargets(
const uint8_t *data,
size_t size,
- uint8_t *valid_targets,
- uint8_t *jump_dests,
+ bitmap_word *valid_targets,
+ bitmap_word *jump_dests,
validation_callback_func user_callback,
void *callback_data) {
+ size_t elements = (size + NACL_HOST_WORDSIZE / 8 - 1) &
+ ~(NACL_HOST_WORDSIZE / 8 - 1);
size_t i;
- assert(size % 32 == 0);
-
- for (i = 0; i < size / 32; i++) {
- uint32_t jump_dest_mask = ((uint32_t *) jump_dests)[i];
- uint32_t valid_target_mask = ((uint32_t *) valid_targets)[i];
+ for (i = 0; i < elements ; i++) {
+ bitmap_word jump_dest_mask = jump_dests[i];
+ bitmap_word valid_target_mask = valid_targets[i];
if ((jump_dest_mask & ~valid_target_mask) != 0) {
// TODO(shcherbina): report address precisely, not just 32-byte block
// TODO(khim): report all errors found, not just the first one
- return user_callback(data + i * 32, data + i * 32, BAD_JUMP_TARGET,
+ return user_callback(data + i * NACL_HOST_WORDSIZE,
+ data + i * NACL_HOST_WORDSIZE, BAD_JUMP_TARGET,
callback_data);
}
}
@@ -212,7 +218,8 @@
*/
static FORCEINLINE void rel8_operand(const uint8_t *rip,
const uint8_t* codeblock_start,
- uint8_t *jump_dests, size_t jumpdests_size,
+ bitmap_word *jump_dests,
+ size_t jumpdests_size,
uint32_t *instruction_info_collected) {
int8_t offset = (uint8_t) (rip[-1]);
size_t jump_dest = offset + (rip - codeblock_start);
@@ -229,7 +236,7 @@
*/
static FORCEINLINE void rel32_operand(const uint8_t *rip,
const uint8_t* codeblock_start,
- uint8_t *jump_dests,
+ bitmap_word *jump_dests,
size_t jumpdests_size,
uint32_t *instruction_info_collected) {
int32_t offset = (rip[-4] + 256U * (rip[-3] + 256U * (
@@ -245,7 +252,7 @@
enum register_name base,
enum register_name index,
uint8_t restricted_register,
- uint8_t *valid_targets,
+ bitmap_word *valid_targets,
uint32_t *instruction_info_collected) {
if ((base == REG_RIP) || (base == REG_R15) ||
(base == REG_RSP) || (base == REG_RBP)) {
« no previous file with comments | « src/trusted/validator_ragel/gen/validator_x86_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