Index: src/trusted/validator_ragel/unreviewed/dfa_validate_64.c |
=================================================================== |
--- src/trusted/validator_ragel/unreviewed/dfa_validate_64.c (revision 9570) |
+++ src/trusted/validator_ragel/unreviewed/dfa_validate_64.c (working copy) |
@@ -34,7 +34,7 @@ |
UNREFERENCED_PARAMETER(info); |
/* Instruction is unsupported by CPU, but otherwise valid. */ |
- if ((info & VALIDATION_ERRORS) == CPUID_UNSUPPORTED_INSTRUCTION) { |
+ if ((info & VALIDATION_ERRORS_MASK) == CPUID_UNSUPPORTED_INSTRUCTION) { |
*((enum NaClValidationStatus*)callback_data) = |
NaClValidationFailedCpuNotSupported; |
} |
@@ -46,7 +46,7 @@ |
UNREFERENCED_PARAMETER(callback_data); |
/* Stubout unsupported by CPU, but otherwise valid instructions. */ |
- if ((info & VALIDATION_ERRORS) == CPUID_UNSUPPORTED_INSTRUCTION) { |
+ if ((info & VALIDATION_ERRORS_MASK) == CPUID_UNSUPPORTED_INSTRUCTION) { |
memset((uint8_t *)begin, NACL_HALT_OPCODE, end - begin + 1); |
return TRUE; |
} else { |
@@ -111,7 +111,7 @@ |
return data->copy_func( |
(uint8_t *)begin_new + data->delta, |
- (info & VALIDATION_ERRORS) == CPUID_UNSUPPORTED_INSTRUCTION ? |
+ (info & VALIDATION_ERRORS_MASK) == CPUID_UNSUPPORTED_INSTRUCTION ? |
(uint8_t *)kStubOutMem : |
(uint8_t *)begin_new, |
(uint8_t)(end_new - begin_new + 1)); |
@@ -157,7 +157,7 @@ |
CHECK(instruction_length <= MAX_INSTRUCTION_LENGTH); |
/* Unsupported instruction must have been replaced with HLTs. */ |
- if ((info & VALIDATION_ERRORS) == CPUID_UNSUPPORTED_INSTRUCTION) { |
+ if ((info & VALIDATION_ERRORS_MASK) == CPUID_UNSUPPORTED_INSTRUCTION) { |
if (memcmp(kStubOutMem, begin_old, instruction_length) == 0) { |
return TRUE; |
} else { |
@@ -166,11 +166,11 @@ |
/* If we have jump which jumps out of it's range... */ |
} else if (info & DIRECT_JUMP_OUT_OF_RANGE) { |
/* then everything is fine if it's the only error and jump is unchanged! */ |
- if ((info & (VALIDATION_ERRORS & ~DIRECT_JUMP_OUT_OF_RANGE)) || |
+ if ((info & (VALIDATION_ERRORS_MASK & ~DIRECT_JUMP_OUT_OF_RANGE)) || |
memcmp(begin_new, begin_old, instruction_length) != 0) |
return FALSE; |
/* If instruction is not accepted then we have nothing to do here. */ |
- } else if (info & (VALIDATION_ERRORS | BAD_JUMP_TARGET)) { |
+ } else if (info & (VALIDATION_ERRORS_MASK | BAD_JUMP_TARGET)) { |
return FALSE; |
/* Instruction is untouched: we are done. */ |
} else if (memcmp(begin_new, begin_old, instruction_length) == 0) { |
@@ -180,17 +180,21 @@ |
return FALSE; |
/* Instruction with two-bit immediate can only change these two bits. */ |
} else if ((info & IMMEDIATE_2BIT) == IMMEDIATE_2BIT) { |
- if (memcmp(begin_new, begin_old, instruction_length - 1) != 0 || |
+ if (memcmp(begin_new, begin_old, |
+ instruction_length - (info & IMMEDIATES_SIZE_MASK) - 1) != 0 || |
(*end_new & 0xfc) != (*end_old & 0xfc)) { |
return FALSE; |
} |
+ /* Instruction's last byte is not immediate, thus it must be unchanged. */ |
} else if (info & LAST_BYTE_IS_NOT_IMMEDIATE) { |
- if (memcmp(begin_new, begin_old, instruction_length - 1) != 0) { |
+ if (memcmp(begin_new, begin_old, |
+ instruction_length - (info & IMMEDIATES_SIZE_MASK) - 1) != 0 || |
+ (*end_new) != (*end_old)) { |
return FALSE; |
} |
/* Normal instruction can only change an immediate. */ |
} else if (memcmp(begin_new, begin_old, |
- instruction_length - (info & IMMEDIATES_SIZE)) != 0) { |
+ instruction_length - (info & IMMEDIATES_SIZE_MASK)) != 0) { |
return FALSE; |
} |
return TRUE; |