fn run_emulation(&mut self) -> Result<VcpuEmulation> {
        match self.fd.run() {
            Ok(run) => match run {
                #[cfg(target_arch = "x86_64")]
                VcpuExit::IoIn(addr, data) => {
                    self.io_bus.read(0, u64::from(addr), data);
                    Ok(VcpuEmulation::Handled)
                }
                #[cfg(target_arch = "x86_64")]
                VcpuExit::IoOut(addr, data) => {
                    self.check_boot_complete_signal(u64::from(addr), data);

                    self.io_bus.write(0, u64::from(addr), data);
                    Ok(VcpuEmulation::Handled)
                }
                VcpuExit::MmioRead(addr, data) => {
                    if let Some(ref mmio_bus) = self.mmio_bus {
                        mmio_bus.read(0, addr, data);
                    }
                    Ok(VcpuEmulation::Handled)
                }
                VcpuExit::MmioWrite(addr, data) => {
                    if let Some(ref mmio_bus) = self.mmio_bus {
                        #[cfg(target_arch = "aarch64")]
                        self.check_boot_complete_signal(addr, data);

                        mmio_bus.write(0, addr, data);
                    }
                    Ok(VcpuEmulation::Handled)
                }
                VcpuExit::Hlt => {
                    info!("Received KVM_EXIT_HLT signal");
                    Ok(VcpuEmulation::Stopped)
                }
                VcpuExit::Shutdown => {
                    info!("Received KVM_EXIT_SHUTDOWN signal");
                    Ok(VcpuEmulation::Stopped)
                }
                // Documentation specifies that below kvm exits are considered
                // errors.
                VcpuExit::FailEntry => {
                    error!("Received KVM_EXIT_FAIL_ENTRY signal");
                    Err(Error::VcpuUnhandledKvmExit)
                }
                VcpuExit::InternalError => {
                    error!("Received KVM_EXIT_INTERNAL_ERROR signal");
                    Err(Error::VcpuUnhandledKvmExit)
                }
                r => {
                    // TODO: Are we sure we want to finish running a vcpu upon
                    // receiving a vm exit that is not necessarily an error?
                    error!("Unexpected exit reason on vcpu run: {:?}", r);
                    Err(Error::VcpuUnhandledKvmExit)
                }
            },
            // The unwrap on raw_os_error can only fail if we have a logic
            // error in our code in which case it is better to panic.
            Err(ref e) => {
                match e.errno() {
                    libc::EAGAIN => Ok(VcpuEmulation::Handled),
                    libc::EINTR => {
                        self.fd.set_kvm_immediate_exit(0);
                        // Notify that this KVM_RUN was interrupted.
                        Ok(VcpuEmulation::Interrupted)
                    }
                    _ => {
                        error!("Failure during vcpu run: {}", e);
                        Err(Error::VcpuUnhandledKvmExit)
                    }
                }
            }
        }
    }
/// Runs the vCPU in KVM context and handles the kvm exit reason.
///
/// Returns error or enum specifying whether emulation was handled or interrupted.
Runs the vCPU in KVM context and handles the kvm exit reason.
Returns error or enum specifying whether emulation was handled or interrupted.
Runs the vCPU in KVM context and handles the kvm exit reason . Returns error or enum specifying whether emulation was handled or interrupted .
fn run_emulation(&mut self) -> Result<VcpuEmulation> {
        match self.fd.run() {
            Ok(run) => match run {
                #[cfg(target_arch = "x86_64")]
                VcpuExit::IoIn(addr, data) => {
                    self.io_bus.read(0, u64::from(addr), data);
                    Ok(VcpuEmulation::Handled)
                }
                #[cfg(target_arch = "x86_64")]
                VcpuExit::IoOut(addr, data) => {
                    self.check_boot_complete_signal(u64::from(addr), data);
                    self.io_bus.write(0, u64::from(addr), data);
                    Ok(VcpuEmulation::Handled)
                }
                VcpuExit::MmioRead(addr, data) => {
                    if let Some(ref mmio_bus) = self.mmio_bus {
                        mmio_bus.read(0, addr, data);
                    }
                    Ok(VcpuEmulation::Handled)
                }
                VcpuExit::MmioWrite(addr, data) => {
                    if let Some(ref mmio_bus) = self.mmio_bus {
                        #[cfg(target_arch = "aarch64")]
                        self.check_boot_complete_signal(addr, data);
                        mmio_bus.write(0, addr, data);
                    }
                    Ok(VcpuEmulation::Handled)
                }
                VcpuExit::Hlt => {
                    info!("Received KVM_EXIT_HLT signal");
                    Ok(VcpuEmulation::Stopped)
                }
                VcpuExit::Shutdown => {
                    info!("Received KVM_EXIT_SHUTDOWN signal");
                    Ok(VcpuEmulation::Stopped)
                }
                // Documentation specifies that below kvm exits are considered
                // errors.
                VcpuExit::FailEntry => {
                    error!("Received KVM_EXIT_FAIL_ENTRY signal");
                    Err(Error::VcpuUnhandledKvmExit)
                }
                VcpuExit::InternalError => {
                    error!("Received KVM_EXIT_INTERNAL_ERROR signal");
                    Err(Error::VcpuUnhandledKvmExit)
                }
                r => {
                    // TODO: Are we sure we want to finish running a vcpu upon
                    // receiving a vm exit that is not necessarily an error?
                    error!("Unexpected exit reason on vcpu run: {:?}", r);
                    Err(Error::VcpuUnhandledKvmExit)
                }
            },
            // The unwrap on raw_os_error can only fail if we have a logic
            // error in our code in which case it is better to panic.
            Err(ref e) => {
                match e.errno() {
                    libc::EAGAIN => Ok(VcpuEmulation::Handled),
                    libc::EINTR => {
                        self.fd.set_kvm_immediate_exit(0);
                        // Notify that this KVM_RUN was interrupted.
                        Ok(VcpuEmulation::Interrupted)
                    }
                    _ => {
                        error!("Failure during vcpu run: {}", e);
                        Err(Error::VcpuUnhandledKvmExit)
                    }
                }
            }
        }
    }
fn run_emulation ( & mut self ) -> Result < VcpuEmulation > { match self . fd . run ( ) { Ok ( run ) => match run { # [ cfg ( target_arch " " ) ] VcpuExit :: IoIn ( addr , data ) => { self . io_bus . read ( 0 , u64 :: from ( addr ) , data ) ; Ok ( VcpuEmulation :: Handled ) } # [ cfg ( target_arch " " ) ] VcpuExit :: IoOut ( addr , data ) => { self . check_boot_complete_signal ( u64 :: from ( addr ) , data ) ; self . io_bus . write ( 0 , u64 :: from ( addr ) , data ) ; Ok ( VcpuEmulation :: Handled ) } VcpuExit :: MmioRead ( addr , data ) => { if let Some ( ref mmio_bus ) = self . mmio_bus { mmio_bus . read ( 0 , addr , data ) ; } Ok ( VcpuEmulation :: Handled ) } VcpuExit :: MmioWrite ( addr , data ) => { if let Some ( ref mmio_bus ) = self . mmio_bus { # [ cfg ( target_arch " " ) ] self . check_boot_complete_signal ( addr , data ) ; mmio_bus . write ( 0 , addr , data ) ; } Ok ( VcpuEmulation :: Handled ) } VcpuExit :: Hlt => { info ! ( " " ) ; Ok ( VcpuEmulation :: Stopped ) } VcpuExit :: Shutdown => { info ! ( " " ) ; Ok ( VcpuEmulation :: Stopped ) } // Documentation specifies that below kvm exits are considered // errors. VcpuExit :: FailEntry => { error ! ( " " ) ; Err ( Error :: VcpuUnhandledKvmExit ) } VcpuExit :: InternalError => { error ! ( " " ) ; Err ( Error :: VcpuUnhandledKvmExit ) } r => { // TODO: Are we sure we want to finish running a vcpu upon // receiving a vm exit that is not necessarily an error? error ! ( " " r ) ; Err ( Error :: VcpuUnhandledKvmExit ) } } , // The unwrap on raw_os_error can only fail if we have a logic // error in our code in which case it is better to panic. Err ( ref e ) => { match e . errno ( ) { libc :: EAGAIN => Ok ( VcpuEmulation :: Handled ) , libc :: EINTR => { self . fd . set_kvm_immediate_exit ( 0 ) ; // Notify that this KVM_RUN was interrupted. Ok ( VcpuEmulation :: Interrupted ) } _ => { error ! ( " " e ) ; Err ( Error :: VcpuUnhandledKvmExit ) } } } } }
Runs the vCPU in KVM context and handles the kvm exit reason.
Runs the vCPU in KVM context and handles the kvm exit reason .
&mut self