2019-04-22 22:59:43 +00:00
|
|
|
// Copyright 2019 The Chromium OS Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-04-06 03:34:50 +00:00
|
|
|
pub use crate::generated::plugin::*;
|
2018-02-27 23:53:12 +00:00
|
|
|
|
|
|
|
/// Converts protobuf representation of CpuId data into KVM format.
|
2020-08-10 23:14:44 +00:00
|
|
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
2018-02-27 23:53:12 +00:00
|
|
|
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.
|
2020-08-10 23:14:44 +00:00
|
|
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
2018-02-27 23:53:12 +00:00
|
|
|
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
|
|
|
|
}
|