From 93894163b5c10d060d517c920ac4ada319363dbb Mon Sep 17 00:00:00 2001 From: SuchAFuriousDeath <48620541+SuchAFuriousDeath@users.noreply.github.com> Date: Sat, 26 Oct 2024 10:39:52 +0200 Subject: [PATCH] Implements MultiThreadResume for CpuManager (#1068) Co-authored-by: tompro --- gui/src/vmm/cpu/mod.rs | 29 +++++++++++++++++++++++++++-- gui/src/vmm/cpu/x86_64.rs | 8 +------- gui/src/vmm/hv/linux/mod.rs | 4 ++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/gui/src/vmm/cpu/mod.rs b/gui/src/vmm/cpu/mod.rs index a90cec93..95e77bda 100644 --- a/gui/src/vmm/cpu/mod.rs +++ b/gui/src/vmm/cpu/mod.rs @@ -9,9 +9,11 @@ use super::ram::RamMap; use super::{VmmEvent, VmmEventHandler}; use crate::error::RustError; use crate::screen::Screen; -use gdbstub::common::Tid; +use gdbstub::common::{Signal, Tid}; use gdbstub::stub::MultiThreadStopReason; -use gdbstub::target::ext::base::multithread::MultiThreadBase; +use gdbstub::target::ext::base::multithread::{ + MultiThreadBase, MultiThreadResume, MultiThreadResumeOps, +}; use gdbstub::target::ext::thread_extra_info::{ThreadExtraInfo, ThreadExtraInfoOps}; use gdbstub::target::{TargetError, TargetResult}; use std::collections::BTreeMap; @@ -496,6 +498,11 @@ impl MultiThreadBase for CpuManager { Ok(()) } + #[inline(always)] + fn support_resume(&mut self) -> Option> { + Some(self) + } + #[inline(always)] fn support_thread_extra_info(&mut self) -> Option> { Some(self) @@ -508,6 +515,24 @@ impl ThreadExtraInfo for CpuManager { } } +impl MultiThreadResume for CpuManager { + fn resume(&mut self) -> Result<(), Self::Error> { + todo!() + } + + fn clear_resume_actions(&mut self) -> Result<(), Self::Error> { + todo!() + } + + fn set_resume_action_continue( + &mut self, + tid: Tid, + signal: Option, + ) -> Result<(), Self::Error> { + todo!() + } +} + /// Encapsulates arguments for a function to run a CPU. struct Args { hv: Arc, diff --git a/gui/src/vmm/cpu/x86_64.rs b/gui/src/vmm/cpu/x86_64.rs index 869f78bf..be12f015 100644 --- a/gui/src/vmm/cpu/x86_64.rs +++ b/gui/src/vmm/cpu/x86_64.rs @@ -1,19 +1,13 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use super::controller::CpuController; use super::{CpuManager, GdbError}; use crate::screen::Screen; use crate::vmm::hv::Hypervisor; -use gdbstub::common::Tid; -use gdbstub::target::ext::base::multithread::MultiThreadBase; use gdbstub::target::ext::base::BaseOps; use gdbstub::target::ext::breakpoints::{ Breakpoints, BreakpointsOps, SwBreakpoint, SwBreakpointOps, }; -use gdbstub::target::ext::thread_extra_info::{ThreadExtraInfo, ThreadExtraInfoOps}; -use gdbstub::target::{TargetError as GdbTargetError, TargetResult}; -use gdbstub_arch::x86::reg::X86_64CoreRegs; +use gdbstub::target::TargetResult; use gdbstub_arch::x86::X86_64_SSE; -use std::num::NonZero; pub type GdbRegs = gdbstub_arch::x86::reg::X86_64CoreRegs; diff --git a/gui/src/vmm/hv/linux/mod.rs b/gui/src/vmm/hv/linux/mod.rs index 91ce38c6..23658724 100644 --- a/gui/src/vmm/hv/linux/mod.rs +++ b/gui/src/vmm/hv/linux/mod.rs @@ -26,7 +26,7 @@ mod run; pub fn new(cpu: usize, ram: Ram, debug: bool) -> Result { // Open KVM device. - let kvm = unsafe { open(b"/dev/kvm\0".as_ptr().cast(), O_RDWR) }; + let kvm = unsafe { open("/dev/kvm\0".as_ptr().cast(), O_RDWR) }; if kvm < 0 { return Err(KvmError::OpenKvmFailed(Error::last_os_error())); @@ -45,7 +45,7 @@ pub fn new(cpu: usize, ram: Ram, debug: bool) -> Result { // Check max CPU. let max = get_ext(kvm.as_fd(), KVM_CAP_MAX_VCPUS).map_err(KvmError::GetMaxCpuFailed)?; - if TryInto::::try_into(max).unwrap() < cpu { + if usize::try_from(max).unwrap() < cpu { return Err(KvmError::MaxCpuTooLow(cpu)); }