Skip to content

Commit f273035

Browse files
n0toosefogti
authored andcommitted
chore: stub/exclude macOS portions, fix errors
- Use macOS-specific KickSignal - Fix some XhyveCpu implementations - Stub out/exclude unused gdb portions - Use explicit allow(dead_code) to show warnings/what's missing - Add placeholder AllBreakpoints for macOS - Add placeholder DebugExitInfo (may need to be replaced)
1 parent e567479 commit f273035

8 files changed

Lines changed: 41 additions & 13 deletions

File tree

src/gdb/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ use gdbstub::{
1818
};
1919
use nix::sys::pthread::{Pthread, pthread_self};
2020

21+
#[cfg_attr(target_os = "macos", allow(unused_imports))]
22+
use crate::HypervisorResult;
23+
#[cfg_attr(target_os = "macos", allow(unused_imports))]
24+
use crate::os::Breakpoints;
2125
use crate::{
22-
HypervisorResult,
2326
gdb::resume::{ResumeMarker, ResumeMode},
24-
os::Breakpoints,
2527
vcpu::{VcpuStopReason, VirtualCPU},
2628
vm::{
2729
KernelInfo, VirtualizationBackend, VmPeripherals, internal::VirtualizationBackendInternal,
@@ -45,11 +47,13 @@ pub(crate) struct PthreadWrapper(pub Pthread);
4547
unsafe impl Send for PthreadWrapper {}
4648
unsafe impl Sync for PthreadWrapper {}
4749

50+
#[cfg_attr(target_os = "macos", allow(unused))]
4851
pub(crate) struct VcpuWrapperShared<VCpu> {
4952
pub(crate) vcpu: RwLock<VCpu>,
5053
pub(crate) resume: ResumeMarker,
5154
}
5255

56+
#[cfg_attr(target_os = "macos", allow(unused))]
5357
pub(crate) struct VcpuWrapper<VCpu> {
5458
pub(crate) shared: Arc<VcpuWrapperShared<VCpu>>,
5559

@@ -60,7 +64,9 @@ pub(crate) struct VcpuWrapper<VCpu> {
6064
pub(crate) planned_resume_mode: Option<ResumeMode>,
6165
}
6266

67+
#[cfg_attr(target_os = "macos", allow(unused))]
6368
pub(crate) struct GdbVcpuManager<Vm: VirtualizationBackend> {
69+
#[cfg(not(target_os = "macos"))]
6470
pub(crate) breakpoints: Arc<RwLock<Breakpoints>>,
6571

6672
pub(crate) peripherals: Arc<VmPeripherals>,
@@ -85,6 +91,7 @@ fn derive_tid(pthread: libc::pthread_t) -> NonZero<u32> {
8591
}
8692

8793
impl<Vm: VirtualizationBackend> crate::vm::UhyveVm<Vm> {
94+
#[cfg_attr(target_os = "macos", allow(dead_code))]
8895
pub(crate) fn spawn_cpu_manager_for_gdb(
8996
self,
9097
cpu_affinity: Option<Vec<CoreId>>,
@@ -97,6 +104,7 @@ impl<Vm: VirtualizationBackend> crate::vm::UhyveVm<Vm> {
97104
let (stops_s, stops_r) = async_channel::unbounded();
98105
let peripherals = Arc::clone(&self.peripherals);
99106
let kernel_info = Arc::clone(&self.kernel_info);
107+
#[cfg(not(target_os = "macos"))]
100108
let breakpoints = Arc::new(RwLock::new(Breakpoints::default()));
101109
let cpu_affinity: Option<Arc<[_]>> = cpu_affinity.map(Arc::from);
102110

@@ -107,6 +115,7 @@ impl<Vm: VirtualizationBackend> crate::vm::UhyveVm<Vm> {
107115
let vcpu_id = vcpu.get_vcpu_id();
108116
let vcpu = RwLock::new(vcpu);
109117
let stops_s = stops_s.clone();
118+
#[cfg(not(target_os = "macos"))]
110119
let breakpoints = Arc::clone(&breakpoints);
111120
let shared = Arc::new(VcpuWrapperShared {
112121
resume: ResumeMarker {
@@ -154,6 +163,7 @@ impl<Vm: VirtualizationBackend> crate::vm::UhyveVm<Vm> {
154163

155164
listener.wait();
156165
}
166+
#[cfg(not(target_os = "macos"))]
157167
shared
158168
.apply_current_guest_debug(&(*breakpoints).read().unwrap())
159169
.expect("GDB target error");
@@ -164,6 +174,9 @@ impl<Vm: VirtualizationBackend> crate::vm::UhyveVm<Vm> {
164174
.r#continue()
165175
.expect("GDB target error")
166176
{
177+
#[cfg(target_os = "macos")]
178+
VcpuStopReason::Debug(_debug) => todo!(),
179+
#[cfg(not(target_os = "macos"))]
167180
VcpuStopReason::Debug(debug) => crate::os::debug_info_to_stop_reason(
168181
debug,
169182
tid.try_into().unwrap(),
@@ -207,6 +220,7 @@ impl<Vm: VirtualizationBackend> crate::vm::UhyveVm<Vm> {
207220
trace!("tid2vcpu = {tid_to_vcpu:?}");
208221

209222
GdbVcpuManager {
223+
#[cfg(not(target_os = "macos"))]
210224
breakpoints,
211225
peripherals,
212226
kernel_info,
@@ -222,6 +236,7 @@ impl<Vm: VirtualizationBackend> crate::vm::UhyveVm<Vm> {
222236

223237
impl<Vm: VirtualizationBackend> GdbVcpuManager<Vm> {
224238
/// Resolves a [`Tid`] from GDB to the associated [`VcpuWrapper`].
239+
#[cfg_attr(target_os = "macos", allow(dead_code))]
225240
pub(crate) fn get_vcpu_wrapper(
226241
&self,
227242
tid: Tid,
@@ -244,6 +259,7 @@ impl<Vm: VirtualizationBackend> GdbVcpuManager<Vm> {
244259
}
245260

246261
/// Resolves a [`Tid`] from GDB to the lock around the associated [`KvmCpu`].
262+
#[cfg_attr(target_os = "macos", allow(dead_code))]
247263
pub(crate) fn get_vm_cpu(
248264
&self,
249265
tid: Tid,
@@ -257,6 +273,7 @@ impl<VCpu: VirtualCPU> VcpuWrapperShared<VCpu> {
257273
/// `ResumeMode`, and `breakpoints`.
258274
///
259275
/// This handles e.g. single-stepping of the vCPU.
276+
#[cfg(not(target_os = "macos"))]
260277
pub fn apply_current_guest_debug(&self, breakpoints: &Breakpoints) -> HypervisorResult<()> {
261278
// SAFETY: we trust the value of `self.resume.mode`.
262279
let mode: ResumeMode =

src/gdb/resume.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use gdbstub::{
88

99
use crate::{
1010
gdb::{GdbVcpuManager, VcpuWrapper, VcpuWrapperShared},
11-
os::KickSignal,
1211
vm::VirtualizationBackend,
1312
};
1413

@@ -31,6 +30,7 @@ pub enum ResumeMode {
3130
impl<Vm: VirtualizationBackend> GdbVcpuManager<Vm> {
3231
/// Signal to the vCPU manager that the `gdbstub` finished initializing,
3332
/// i.e. exited the `Idle` state and entered the `Running` state.
33+
#[cfg_attr(target_os = "macos", allow(dead_code))]
3434
pub fn set_finished_initializing(&mut self) {
3535
if core::mem::replace(&mut self.is_initializing, false) {
3636
for i in &mut self.vcpus {
@@ -44,10 +44,11 @@ impl<Vcpu> VcpuWrapper<Vcpu> {
4444
/// Kick the vCPU
4545
pub fn kick(&self) {
4646
trace!("vcpu: kick! {}", self.tid);
47-
KickSignal::pthread_kill(self.pthread.0).unwrap();
47+
crate::os::KickSignal::pthread_kill(self.pthread.0).unwrap();
4848
}
4949

5050
/// Resume the vCPU in free-wheeling / non-stepped mode
51+
#[cfg_attr(target_os = "macos", allow(dead_code))]
5152
fn r#continue(&mut self) {
5253
// TODO: refactor to get rid of mutability
5354
let old_planned = self.planned_resume_mode.take();

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub enum HypervisorError {
7474

7575
impl HypervisorError {
7676
/// Report an (target independent) invalid value error e.g. during debug interactions
77-
#[cfg_attr(target_os = "macos", expect(unused))]
7877
fn backend_invalid_value() -> Self {
7978
Self::BackendError({
8079
#[cfg(target_os = "linux")]

src/macos/aarch64/vcpu.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,15 @@ impl VirtualCPU for XhyveCpu {
331331
}
332332

333333
fn get_vcpu_id(&self) -> usize {
334-
self.id
334+
self.id.try_into().unwrap()
335+
}
336+
337+
fn apply_current_guest_debug(
338+
&mut self,
339+
_breakpoints: &crate::os::Breakpoints,
340+
_resume_mode: crate::gdb::resume::ResumeMode,
341+
) -> HypervisorResult<()> {
342+
todo!()
335343
}
336344
}
337345

src/macos/gdb/breakpoints.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// TODO: Implement breakpoinst for macOS.
2+
#[derive(Clone, Debug, Default)]
3+
pub struct AllBreakpoints;

src/macos/gdb/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(crate) mod breakpoints;

src/macos/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
#[cfg(target_arch = "aarch64")]
22
pub mod aarch64;
33

4+
pub(crate) mod gdb;
5+
46
use core_affinity::CoreId;
57
use nix::sys::{
68
pthread::{Pthread, pthread_kill},
79
signal::{SIGUSR1, SigHandler, Signal, signal},
810
};
911

10-
#[cfg(target_arch = "aarch64")]
1112
pub use crate::macos::aarch64::vcpu::{XhyveCpu, XhyveVm};
1213
use crate::vm::{UhyveVm, VmResult};
1314

15+
/// TODO: Use proper structure and methods for this
16+
pub(crate) type DebugExitInfo = xhypervisor::ffi::hv_vcpu_exit_exception_t;
17+
pub(crate) type Breakpoints = gdb::breakpoints::AllBreakpoints;
18+
1419
/// The signal for kicking vCPUs out of KVM_RUN.
1520
///
1621
/// It is used to stop a vCPU from another thread.
@@ -38,8 +43,6 @@ impl KickSignal {
3843
}
3944
}
4045

41-
pub(crate) type DebugExitInfo = ();
42-
4346
impl UhyveVm<XhyveVm> {
4447
/// Runs the VM.
4548
///

src/vcpu.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ use crate::{HypervisorResult, os::DebugExitInfo};
77
use crate::{gdb::resume::ResumeMode, stats::CpuStats};
88

99
/// Reasons for vCPU exits.
10-
#[cfg_attr(
11-
target_os = "macos",
12-
expect(dead_code, reason = "Not all variants used in macOS.")
13-
)]
1410
pub enum VcpuStopReason {
1511
/// The vCPU stopped for debugging.
1612
Debug(DebugExitInfo),

0 commit comments

Comments
 (0)