Skip to content

Commit 2dff256

Browse files
committed
singlestep support added
1 parent 39625c8 commit 2dff256

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ use xenctrl_sys::{xc_error_code, xc_interface, xenmem_access_t, xentoollog_logge
2828
use xenvmevent_sys::{
2929
vm_event_back_ring, vm_event_request_t, vm_event_response_t, vm_event_sring, MEM_ACCESS_R,
3030
MEM_ACCESS_RW, MEM_ACCESS_RWX, MEM_ACCESS_RX, MEM_ACCESS_W, MEM_ACCESS_WX, MEM_ACCESS_X,
31-
VM_EVENT_REASON_MEM_ACCESS, VM_EVENT_REASON_MOV_TO_MSR, VM_EVENT_REASON_SOFTWARE_BREAKPOINT,
32-
VM_EVENT_REASON_WRITE_CTRLREG, VM_EVENT_X86_CR0, VM_EVENT_X86_CR3, VM_EVENT_X86_CR4,
31+
VM_EVENT_REASON_MEM_ACCESS, VM_EVENT_REASON_MOV_TO_MSR, VM_EVENT_REASON_SINGLESTEP,
32+
VM_EVENT_REASON_SOFTWARE_BREAKPOINT, VM_EVENT_REASON_WRITE_CTRLREG, VM_EVENT_X86_CR0,
33+
VM_EVENT_X86_CR3, VM_EVENT_X86_CR4,
3334
};
3435

3536
#[derive(Copy, Clone, Debug)]
@@ -122,6 +123,9 @@ pub enum XenEventType {
122123
gpa: u64,
123124
access: XenPageAccess,
124125
},
126+
Singlestep {
127+
gpa: u64,
128+
},
125129
}
126130

127131
#[derive(Debug)]
@@ -325,6 +329,9 @@ impl XenControl {
325329
flag.try_into().unwrap()
326330
},
327331
},
332+
VM_EVENT_REASON_SINGLESTEP => XenEventType::Singlestep {
333+
gpa: req.u.singlestep.gfn << PAGE_SHIFT,
334+
},
328335
_ => unimplemented!(),
329336
};
330337
}
@@ -362,6 +369,16 @@ impl XenControl {
362369
last_error!(self, ())
363370
}
364371

372+
pub fn monitor_singlestep(&self, domid: u32, enable: bool) -> Result<(), XcError> {
373+
let xc = self.handle.as_ptr();
374+
(self.libxenctrl.clear_last_error)(xc);
375+
let rc = (self.libxenctrl.monitor_singlestep)(xc, domid, enable);
376+
if rc < 0 {
377+
println!("last OS error: {:?}", Error::last_os_error());
378+
}
379+
last_error!(self, ())
380+
}
381+
365382
pub fn monitor_mov_to_msr(&self, domid: u32, msr: u32, enable: bool) -> Result<(), XcError> {
366383
let xc = self.handle.as_ptr();
367384
(self.libxenctrl.clear_last_error)(xc);

src/libxenctrl.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type FnMonitorSoftwareBreakpoint = fn(xch: *mut xc_interface, domid: u32, enable
5252
//xc_monitor_mov_to_msr
5353
type FnMonitorMovToMsr =
5454
fn(xch: *mut xc_interface, domain_id: domid_t, msr: u32, enable: bool) -> c_int;
55+
//xc_monitor_singlestep
56+
type FnMonitorSinglestep = fn(xch: *mut xc_interface, domid: u32, enable: bool) -> c_int;
5557
//xc_monitor_write_ctrlreg
5658
type FnMonitorWriteCtrlreg = fn(
5759
xch: *mut xc_interface,
@@ -94,6 +96,7 @@ pub struct LibXenCtrl {
9496
pub monitor_write_ctrlreg: RawSymbol<FnMonitorWriteCtrlreg>,
9597
pub get_mem_access: RawSymbol<FnGetMemAccess>,
9698
pub set_mem_access: RawSymbol<FnSetMemAccess>,
99+
pub monitor_singlestep: RawSymbol<FnMonitorSinglestep>,
97100
}
98101

99102
impl LibXenCtrl {
@@ -149,6 +152,10 @@ impl LibXenCtrl {
149152
lib.get(b"xc_monitor_write_ctrlreg\0").unwrap();
150153
let monitor_write_ctrlreg = monitor_write_ctrlreg_sym.into_raw();
151154

155+
let monitor_singlestep_sym: Symbol<FnMonitorSinglestep> =
156+
lib.get(b"xc_monitor_singlestep\0").unwrap();
157+
let monitor_singlestep = monitor_singlestep_sym.into_raw();
158+
152159
let get_mem_access_sym: Symbol<FnGetMemAccess> = lib.get(b"xc_get_mem_access\0").unwrap();
153160
let get_mem_access = get_mem_access_sym.into_raw();
154161

@@ -182,6 +189,7 @@ impl LibXenCtrl {
182189
monitor_write_ctrlreg,
183190
get_mem_access,
184191
set_mem_access,
192+
monitor_singlestep,
185193
domain_pause,
186194
domain_unpause,
187195
domain_maximum_gpfn,

0 commit comments

Comments
 (0)