hypervisor: mshv: implement fetching instructions in emulator

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2024-06-27 23:47:21 +00:00 committed by Liu Wei
parent 67f22b6aa4
commit 5fec858130

View File

@ -6,13 +6,14 @@
use crate::arch::emulator::{PlatformEmulator, PlatformError};
#[cfg(target_arch = "x86_64")]
use crate::arch::x86::emulator::{Emulator, EmulatorCpuState};
use crate::arch::x86::emulator::{CpuStateManager, Emulator, EmulatorCpuState};
use crate::cpu;
use crate::cpu::Vcpu;
use crate::hypervisor;
use crate::vec_with_array_field;
use crate::vm::{self, InterruptSourceConfig, VmOps};
use crate::HypervisorType;
use iced_x86::Register;
use mshv_bindings::*;
use mshv_ioctls::{set_registers_64, InterruptRequest, Mshv, NoDatamatch, VcpuFd, VmFd, VmType};
use std::any::Any;
@ -1636,8 +1637,11 @@ impl<'a> PlatformEmulator for MshvEmulatorContext<'a> {
self.translate(gva)
}
fn fetch(&self, _ip: u64, _instruction_bytes: &mut [u8]) -> Result<(), PlatformError> {
Err(PlatformError::MemoryReadFailure(anyhow!("unimplemented")))
fn fetch(&self, ip: u64, instruction_bytes: &mut [u8]) -> Result<(), PlatformError> {
let rip =
self.cpu_state(self.vcpu.vp_index as usize)?
.linearize(Register::CS, ip, false)?;
self.read_memory(rip, instruction_bytes)
}
}