• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 pub use crate::generated::plugin::*;
6 
7 /// Converts protobuf representation of CpuId data into KVM format.
cpuid_proto_to_kvm(entry: &CpuidEntry) -> kvm_sys::kvm_cpuid_entry28 pub fn cpuid_proto_to_kvm(entry: &CpuidEntry) -> kvm_sys::kvm_cpuid_entry2 {
9     // Safe: C structures are expected to be zero-initialized.
10     let mut e: kvm_sys::kvm_cpuid_entry2 = unsafe { std::mem::zeroed() };
11     e.function = entry.function;
12     if entry.has_index {
13         e.flags = kvm_sys::KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
14     }
15     e.index = entry.index;
16     e.eax = entry.eax;
17     e.ebx = entry.ebx;
18     e.ecx = entry.ecx;
19     e.edx = entry.edx;
20 
21     e
22 }
23 
24 /// Converts KVM representation of CpuId data into protobuf format.
cpuid_kvm_to_proto(entry: &kvm_sys::kvm_cpuid_entry2) -> CpuidEntry25 pub fn cpuid_kvm_to_proto(entry: &kvm_sys::kvm_cpuid_entry2) -> CpuidEntry {
26     let mut e = CpuidEntry::new();
27     e.function = entry.function;
28     e.has_index = entry.flags & kvm_sys::KVM_CPUID_FLAG_SIGNIFCANT_INDEX != 0;
29     e.index = entry.index;
30     e.eax = entry.eax;
31     e.ebx = entry.ebx;
32     e.ecx = entry.ecx;
33     e.edx = entry.edx;
34 
35     e
36 }
37