aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/kvm_sys.rs73
-rw-r--r--sysdeps/kvm.c22
2 files changed, 95 insertions, 0 deletions
diff --git a/src/kvm_sys.rs b/src/kvm_sys.rs
index d21da47..2ee97a1 100644
--- a/src/kvm_sys.rs
+++ b/src/kvm_sys.rs
@@ -91,6 +91,32 @@ pub(crate) struct kvm_userspace_memory_region {
pub userspace_addr: u64,
}
+#[cfg(target_arch = "x86_64")]
+#[repr(C)]
+#[derive(Default, Debug)]
+pub struct kvm_debugregs {
+ pub db: [u64; 4],
+ pub dr6: u64,
+ pub dr7: u64,
+ pub flags: u64,
+ pub reserved: [u64; 9],
+}
+
+#[repr(C)]
+#[derive(Default, Debug)]
+pub(crate) struct kvm_guest_debug {
+ pub control: u32,
+ pad: u32,
+ pub arch: kvm_guest_debug_arch,
+}
+
+#[cfg(target_arch = "x86_64")]
+#[repr(C)]
+#[derive(Default, Debug)]
+pub(crate) struct kvm_guest_debug_arch {
+ pub debugreg: [u64; 8],
+}
+
#[repr(C)]
pub(crate) struct kvm_run {
request_interrupt_window: u8,
@@ -127,11 +153,23 @@ pub(crate) struct kvm_run_mmio {
pub is_write: u8,
}
+#[cfg(target_arch = "x86_64")]
+#[repr(C)]
+#[derive(Copy, Clone, Debug)]
+pub(crate) struct kvm_run_debug {
+ pub exception: u32,
+ pad: u32,
+ pub pc: u64,
+ pub dr6: u64,
+ pub dr7: u64,
+}
+
// Only add the union fields used here.
#[repr(C)]
pub(crate) union kvm_run_union {
pub io: kvm_run_io,
pub mmio: kvm_run_mmio,
+ pub debug: kvm_run_debug,
padding: [u8; 256],
}
@@ -194,4 +232,39 @@ mod tests {
assert_eq!(mem::size_of::<kvm_run_mmio>(), TEST_KVM_RUN_MMIO_SIZE);
assert_eq!(mem::size_of::<kvm_run_union_s>(), TEST_KVM_RUN_UNION_S_SIZE);
}
+
+ #[cfg(target_arch = "x86_64")]
+ #[test]
+ fn check_kvm_run_x86() {
+ assert_eq!(mem::size_of::<kvm_run_debug>(), TEST_KVM_RUN_DEBUG_SIZE);
+ }
+
+ #[cfg(target_arch = "x86_64")]
+ #[test]
+ fn check_kvm_debugregs() {
+ assert_eq!(mem::size_of::<kvm_debugregs>(), TEST_KVM_DEBUGREGS_SIZE);
+ assert_eq!(mem::align_of::<kvm_debugregs>(), TEST_KVM_DEBUGREGS_ALIGN);
+ }
+
+ #[test]
+ fn check_kvm_guest_dbg() {
+ assert_eq!(mem::size_of::<kvm_guest_debug>(), TEST_KVM_GUEST_DEBUG_SIZE);
+ assert_eq!(
+ mem::align_of::<kvm_guest_debug>(),
+ TEST_KVM_GUEST_DEBUG_ALIGN
+ );
+ }
+
+ #[cfg(target_arch = "x86_64")]
+ #[test]
+ fn check_kvm_guest_dbg_arch() {
+ assert_eq!(
+ mem::size_of::<kvm_guest_debug_arch>(),
+ TEST_KVM_GUEST_DEBUG_ARCH_SIZE
+ );
+ assert_eq!(
+ mem::align_of::<kvm_guest_debug_arch>(),
+ TEST_KVM_GUEST_DEBUG_ARCH_ALIGN
+ );
+ }
}
diff --git a/sysdeps/kvm.c b/sysdeps/kvm.c
index f7ff1a4..2be08a9 100644
--- a/sysdeps/kvm.c
+++ b/sysdeps/kvm.c
@@ -47,6 +47,20 @@ int main() {
// param: struct kvm_sregs
// ret : 0 success, -1 error
printf("pub(crate) const KVM_SET_SREGS : u64 = 0x%lx;\n", KVM_SET_SREGS);
+ // param: struct kvm_debugregs
+ // ret : 0 success, -1 error
+ printf("pub(crate) const KVM_GET_DEBUGREGS : u64 = 0x%lx;\n", KVM_GET_DEBUGREGS);
+ // param: struct kvm_debugregs
+ // ret : 0 success, -1 error
+ printf("pub(crate) const KVM_SET_DEBUGREGS : u64 = 0x%lx;\n", KVM_SET_DEBUGREGS);
+ // param: struct kvm_guest_debug
+ // ret : 0 success, -1 error
+ printf("pub(crate) const KVM_SET_GUEST_DEBUG : u64 = 0x%lx;\n", KVM_SET_GUEST_DEBUG);
+
+ /* struct kvm_guest_debug constants */
+
+ printf("pub(crate) const KVM_GUESTDBG_ENABLE : u32 = 0x%x;\n", KVM_GUESTDBG_ENABLE);
+ printf("pub(crate) const KVM_GUESTDBG_SINGLESTEP : u32 = 0x%x;\n", KVM_GUESTDBG_SINGLESTEP);
/* struct kvm_run constants */
@@ -55,6 +69,7 @@ int main() {
printf("pub(crate) const KVM_EXIT_IO_IN : u64 = 0x%x;\n", KVM_EXIT_IO_IN);
printf("pub(crate) const KVM_EXIT_IO_OUT : u64 = 0x%x;\n", KVM_EXIT_IO_OUT);
printf("pub(crate) const KVM_EXIT_MMIO : u64 = 0x%x;\n", KVM_EXIT_MMIO);
+ printf("pub(crate) const KVM_EXIT_DEBUG : u64 = 0x%x;\n", KVM_EXIT_DEBUG);
/* Capabilities */
@@ -99,7 +114,14 @@ int main() {
printf("#[cfg(test)] const TEST_KVM_RUN_ALIGN : usize = %ld;\n", alignof(struct kvm_run));
printf("#[cfg(test)] const TEST_KVM_RUN_IO_SIZE : usize = %ld;\n", sizeof(((struct kvm_run*)0)->io));
printf("#[cfg(test)] const TEST_KVM_RUN_MMIO_SIZE : usize = %ld;\n", sizeof(((struct kvm_run*)0)->mmio));
+ printf("#[cfg(test)] const TEST_KVM_RUN_DEBUG_SIZE : usize = %ld;\n", sizeof(((struct kvm_run*)0)->debug));
printf("#[cfg(test)] const TEST_KVM_RUN_UNION_S_SIZE : usize = %ld;\n", sizeof(((struct kvm_run*)0)->s));
+ printf("#[cfg(test)] const TEST_KVM_DEBUGREGS_SIZE: usize = %ld;\n", sizeof(struct kvm_debugregs));
+ printf("#[cfg(test)] const TEST_KVM_DEBUGREGS_ALIGN: usize = %ld;\n", alignof(struct kvm_debugregs));
+ printf("#[cfg(test)] const TEST_KVM_GUEST_DEBUG_SIZE: usize = %ld;\n", sizeof(struct kvm_guest_debug));
+ printf("#[cfg(test)] const TEST_KVM_GUEST_DEBUG_ALIGN: usize = %ld;\n", alignof(struct kvm_guest_debug));
+ printf("#[cfg(test)] const TEST_KVM_GUEST_DEBUG_ARCH_SIZE: usize = %ld;\n", sizeof(struct kvm_guest_debug_arch));
+ printf("#[cfg(test)] const TEST_KVM_GUEST_DEBUG_ARCH_ALIGN: usize = %ld;\n", alignof(struct kvm_guest_debug_arch));
return 0;
}