hypervisor: emulator: use wrapping arithmetic

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2025-01-02 05:13:20 +00:00 committed by Wei Liu
parent 1180f757b3
commit 73e1451a12
2 changed files with 4 additions and 4 deletions

View File

@ -116,14 +116,14 @@ fn memory_operand_address<T: CpuStateManager>(
if insn.memory_base() != iced_x86::Register::None {
let base: u64 = state.read_reg(insn.memory_base())?;
address += base;
address = address.wrapping_add(base);
}
if insn.memory_index() != iced_x86::Register::None {
let mut index: u64 = state.read_reg(insn.memory_index())?;
index *= insn.memory_index_scale() as u64;
index = index.wrapping_mul(insn.memory_index_scale() as u64);
address += index;
address = address.wrapping_add(index);
}
address = address.wrapping_add(insn.memory_displacement64());

View File

@ -185,7 +185,7 @@ pub trait CpuStateManager: Clone {
)));
}
Ok(logical_addr + segment_register.base)
Ok(logical_addr.wrapping_add(segment_register.base))
}
_ => Err(PlatformError::UnsupportedCpuMode(anyhow!("{:?}", mode))),