aboutsummaryrefslogtreecommitdiff
path: root/src/long_mode/mod.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-07-02 00:39:35 -0700
committeriximeow <me@iximeow.net>2021-07-02 00:39:35 -0700
commit1d4b7c2dad97694a6980d95287519ba4c3d582ff (patch)
tree924de949f5701db1d21ff0f81396066dbd73de93 /src/long_mode/mod.rs
parent714f6cfc5ae07d1c6836d72edf85147c985a3c93 (diff)
consolidate length/extension checks to help compilers DCE
Diffstat (limited to 'src/long_mode/mod.rs')
-rw-r--r--src/long_mode/mod.rs57
1 files changed, 24 insertions, 33 deletions
diff --git a/src/long_mode/mod.rs b/src/long_mode/mod.rs
index 861160a..65bda54 100644
--- a/src/long_mode/mod.rs
+++ b/src/long_mode/mod.rs
@@ -4094,11 +4094,32 @@ impl Default for InstDecoder {
impl Decoder<Arch> for InstDecoder {
fn decode<T: Reader<<Arch as yaxpeax_arch::Arch>::Address, <Arch as yaxpeax_arch::Arch>::Word>>(&self, words: &mut T) -> Result<Instruction, <Arch as yaxpeax_arch::Arch>::DecodeError> {
let mut instr = Instruction::invalid();
- read_instr(self, words, &mut instr)
- .map(|_: ()| instr)
+ read_instr(self, words, &mut instr)?;
+
+ instr.length = words.offset() as u8;
+ if words.offset() > 15 {
+ return Err(DecodeError::TooLong);
+ }
+
+ if self != &InstDecoder::default() {
+ self.revise_instruction(&mut instr)?;
+ }
+
+ Ok(instr)
}
fn decode_into<T: Reader<<Arch as yaxpeax_arch::Arch>::Address, <Arch as yaxpeax_arch::Arch>::Word>>(&self, instr: &mut Instruction, words: &mut T) -> Result<(), <Arch as yaxpeax_arch::Arch>::DecodeError> {
- read_instr(self, words, instr)
+ read_instr(self, words, instr)?;
+
+ instr.length = words.offset() as u8;
+ if words.offset() > 15 {
+ return Err(DecodeError::TooLong);
+ }
+
+ if self != &InstDecoder::default() {
+ self.revise_instruction(instr)?;
+ }
+
+ Ok(())
}
}
@@ -7019,13 +7040,6 @@ fn read_instr<T: Reader<<Arch as yaxpeax_arch::Arch>::Address, <Arch as yaxpeax_
} else {
instruction.prefixes = prefixes;
vex::two_byte_vex(words, instruction)?;
- instruction.length = words.offset() as u8;
- if instruction.length > 15 {
- return Err(DecodeError::TooLong);
- }
- if decoder != &InstDecoder::default() {
- decoder.revise_instruction(instruction)?;
- }
return Ok(());
}
} else if b == 0xc4 {
@@ -7035,13 +7049,6 @@ fn read_instr<T: Reader<<Arch as yaxpeax_arch::Arch>::Address, <Arch as yaxpeax_
} else {
instruction.prefixes = prefixes;
vex::three_byte_vex(words, instruction)?;
- instruction.length = words.offset() as u8;
- if instruction.length > 15 {
- return Err(DecodeError::TooLong);
- }
- if decoder != &InstDecoder::default() {
- decoder.revise_instruction(instruction)?;
- }
return Ok(());
}
} else if b == 0x62 {
@@ -7052,13 +7059,6 @@ fn read_instr<T: Reader<<Arch as yaxpeax_arch::Arch>::Address, <Arch as yaxpeax_
} else {
instruction.prefixes = prefixes;
evex::read_evex(words, instruction, None)?;
- instruction.length = words.offset() as u8;
- if instruction.length > 15 {
- return Err(DecodeError::TooLong);
- }
- if decoder != &InstDecoder::default() {
- decoder.revise_instruction(instruction)?;
- }
return Ok(());
}
}
@@ -7106,10 +7106,6 @@ fn read_instr<T: Reader<<Arch as yaxpeax_arch::Arch>::Address, <Arch as yaxpeax_
}
instruction.prefixes = prefixes;
read_operands(decoder, words, instruction, record.1)?;
- instruction.length = words.offset() as u8;
- if words.offset() > 15 {
- return Err(DecodeError::TooLong);
- }
if instruction.prefixes.lock() {
if !LOCKABLE_INSTRUCTIONS.contains(&instruction.opcode) || !instruction.operands[0].is_memory() {
@@ -7117,11 +7113,6 @@ fn read_instr<T: Reader<<Arch as yaxpeax_arch::Arch>::Address, <Arch as yaxpeax_
}
}
- if decoder != &InstDecoder::default() {
- // we might have to fix up or reject this instruction under whatever cpu features we need to
- // pretend to have.
- decoder.revise_instruction(instruction)?;
- }
Ok(())
}
/* likely cases