diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crosvm_plugin/src/lib.rs | 13 | ||||
-rw-r--r-- | plugin_proto/Cargo.toml | 1 | ||||
-rw-r--r-- | plugin_proto/src/lib.rs | 32 |
4 files changed, 36 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock index 523e4e3..fa6f505 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,6 +176,7 @@ name = "plugin_proto" version = "0.10.0" dependencies = [ "gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)", + "kvm_sys 0.1.0", "protobuf 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "protoc-rust 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/crosvm_plugin/src/lib.rs b/crosvm_plugin/src/lib.rs index 6f56341..250692a 100644 --- a/crosvm_plugin/src/lib.rs +++ b/crosvm_plugin/src/lib.rs @@ -43,8 +43,7 @@ use sys_util::Scm; use kvm::dirty_log_bitmap_size; -use kvm_sys::{kvm_regs, kvm_sregs, kvm_fpu, kvm_debugregs, kvm_msr_entry, kvm_cpuid_entry2, - KVM_CPUID_FLAG_SIGNIFCANT_INDEX}; +use kvm_sys::{kvm_regs, kvm_sregs, kvm_fpu, kvm_debugregs, kvm_msr_entry, kvm_cpuid_entry2}; use plugin_proto::*; @@ -753,15 +752,7 @@ impl crosvm_vcpu { { let set_cpuid_entries: &mut RepeatedField<CpuidEntry> = r.mut_set_cpuid().mut_entries(); for cpuid_entry in cpuid_entries.iter() { - let mut entry = CpuidEntry::new(); - entry.function = cpuid_entry.function; - entry.has_index = cpuid_entry.flags & KVM_CPUID_FLAG_SIGNIFCANT_INDEX != 0; - entry.index = cpuid_entry.index; - entry.eax = cpuid_entry.eax; - entry.ebx = cpuid_entry.ebx; - entry.ecx = cpuid_entry.ecx; - entry.edx = cpuid_entry.edx; - set_cpuid_entries.push(entry); + set_cpuid_entries.push(cpuid_kvm_to_proto(cpuid_entry)); } } self.vcpu_transaction(&r)?; diff --git a/plugin_proto/Cargo.toml b/plugin_proto/Cargo.toml index cb6c7fd..bb43452 100644 --- a/plugin_proto/Cargo.toml +++ b/plugin_proto/Cargo.toml @@ -6,6 +6,7 @@ build = "build.rs" [dependencies] protobuf = "*" +kvm_sys = { path = "../kvm_sys" } [build-dependencies] gcc = "=0.3.54" diff --git a/plugin_proto/src/lib.rs b/plugin_proto/src/lib.rs index 7f0d66c..c28635a 100644 --- a/plugin_proto/src/lib.rs +++ b/plugin_proto/src/lib.rs @@ -1,2 +1,34 @@ extern crate protobuf; +extern crate kvm_sys; include!(concat!(env!("OUT_DIR"), "/proto_include.rs")); + +/// Converts protobuf representation of CpuId data into KVM format. +pub fn cpuid_proto_to_kvm(entry: &CpuidEntry) -> kvm_sys::kvm_cpuid_entry2 { + // Safe: C structures are expected to be zero-initialized. + let mut e: kvm_sys::kvm_cpuid_entry2 = unsafe { std::mem::zeroed() }; + e.function = entry.function; + if entry.has_index { + e.flags = kvm_sys::KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + } + e.index = entry.index; + e.eax = entry.eax; + e.ebx = entry.ebx; + e.ecx = entry.ecx; + e.edx = entry.edx; + + e +} + +/// Converts KVM representation of CpuId data into protobuf format. +pub fn cpuid_kvm_to_proto(entry: &kvm_sys::kvm_cpuid_entry2) -> CpuidEntry { + let mut e = CpuidEntry::new(); + e.function = entry.function; + e.has_index = entry.flags & kvm_sys::KVM_CPUID_FLAG_SIGNIFCANT_INDEX != 0; + e.index = entry.index; + e.eax = entry.eax; + e.ebx = entry.ebx; + e.ecx = entry.ecx; + e.edx = entry.edx; + + e +} |