Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit b581698

Browse files
acatangiuioanachirca
authored andcommitted
x86: add versioning for x86_64 state structs
Signed-off-by: Adrian Catangiu <[email protected]>
1 parent 6d77d6e commit b581698

File tree

3 files changed

+91
-28
lines changed

3 files changed

+91
-28
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ fam-wrappers = ["vmm-sys-util"]
1515

1616
[dependencies]
1717
vmm-sys-util = { version = ">=0.2.0", optional = true }
18+
19+
versionize = { git = "https://github.com/firecracker-microvm/versionize", tag = "v0.1.0" }
20+
versionize_derive = { git = "https://github.com/firecracker-microvm/versionize_derive", tag = "v0.1.0" }

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
))]
1313
extern crate vmm_sys_util;
1414

15+
extern crate versionize;
16+
extern crate versionize_derive;
17+
1518
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
1619
mod x86;
1720
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

src/x86/bindings_v4_20_0.rs

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// SPDX-License-Identifier: Apache-2.0
33
/* automatically generated by rust-bindgen */
44

5+
use versionize::{VersionMap, Versionize, VersionizeResult};
6+
use versionize_derive::Versionize;
7+
58
#[repr(C)]
69
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
710
pub struct __BindgenBitfieldUnit<Storage, Align>
@@ -11,6 +14,35 @@ where
1114
storage: Storage,
1215
align: [Align; 0],
1316
}
17+
// Implementing Versionize by hand due to some weird errors when trying to derive (most likely
18+
// because versionize_derive does not support structs with generics at this point).
19+
impl<Storage, Align> Versionize for __BindgenBitfieldUnit<Storage, Align>
20+
where
21+
Storage: AsRef<[u8]> + AsMut<[u8]> + Versionize,
22+
{
23+
fn serialize<W: std::io::Write>(
24+
&self,
25+
writer: &mut W,
26+
version_map: &VersionMap,
27+
app_version: u16,
28+
) -> VersionizeResult<()> {
29+
Versionize::serialize(&self.storage, writer, version_map, app_version)
30+
}
31+
32+
fn deserialize<R: std::io::Read>(
33+
reader: &mut R,
34+
version_map: &VersionMap,
35+
app_version: u16,
36+
) -> VersionizeResult<Self> {
37+
let storage = Versionize::deserialize(reader, version_map, app_version)?;
38+
39+
Ok(__BindgenBitfieldUnit { storage, align: [] })
40+
}
41+
42+
fn version() -> u16 {
43+
1
44+
}
45+
}
1446
impl<Storage, Align> __BindgenBitfieldUnit<Storage, Align>
1547
where
1648
Storage: AsRef<[u8]> + AsMut<[u8]>,
@@ -120,6 +152,31 @@ impl<T> ::std::clone::Clone for __IncompleteArrayField<T> {
120152
Self::new()
121153
}
122154
}
155+
impl<T> Versionize for __IncompleteArrayField<T> {
156+
#[inline]
157+
fn serialize<W: std::io::Write>(
158+
&self,
159+
_writer: &mut W,
160+
_version_map: &VersionMap,
161+
_app_version: u16,
162+
) -> VersionizeResult<()> {
163+
Ok(())
164+
}
165+
166+
#[inline]
167+
fn deserialize<R: std::io::Read>(
168+
_reader: &mut R,
169+
_version_map: &VersionMap,
170+
_app_version: u16,
171+
) -> VersionizeResult<Self> {
172+
Ok(Self::new())
173+
}
174+
175+
// Not used.
176+
fn version() -> u16 {
177+
1
178+
}
179+
}
123180
pub const __BITS_PER_LONG: u32 = 64;
124181
pub const __FD_SETSIZE: u32 = 1024;
125182
pub const _IOC_NRBITS: u32 = 8;
@@ -733,7 +790,7 @@ fn bindgen_test_layout_kvm_memory_alias() {
733790
);
734791
}
735792
#[repr(C)]
736-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
793+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
737794
pub struct kvm_pic_state {
738795
pub last_irr: __u8,
739796
pub irr: __u8,
@@ -930,7 +987,7 @@ fn bindgen_test_layout_kvm_pic_state() {
930987
);
931988
}
932989
#[repr(C)]
933-
#[derive(Copy, Clone)]
990+
#[derive(Copy, Clone, Versionize)]
934991
pub struct kvm_ioapic_state {
935992
pub base_address: __u64,
936993
pub ioregsel: __u32,
@@ -940,14 +997,14 @@ pub struct kvm_ioapic_state {
940997
pub redirtbl: [kvm_ioapic_state__bindgen_ty_1; 24usize],
941998
}
942999
#[repr(C)]
943-
#[derive(Copy, Clone)]
1000+
#[derive(Copy, Clone, Versionize)]
9441001
pub union kvm_ioapic_state__bindgen_ty_1 {
9451002
pub bits: __u64,
9461003
pub fields: kvm_ioapic_state__bindgen_ty_1__bindgen_ty_1,
9471004
_bindgen_union_align: u64,
9481005
}
9491006
#[repr(C)]
950-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
1007+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
9511008
pub struct kvm_ioapic_state__bindgen_ty_1__bindgen_ty_1 {
9521009
pub vector: __u8,
9531010
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>,
@@ -1270,7 +1327,7 @@ impl Default for kvm_ioapic_state {
12701327
}
12711328
}
12721329
#[repr(C)]
1273-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
1330+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
12741331
pub struct kvm_regs {
12751332
pub rax: __u64,
12761333
pub rbx: __u64,
@@ -1485,7 +1542,7 @@ fn bindgen_test_layout_kvm_regs() {
14851542
);
14861543
}
14871544
#[repr(C)]
1488-
#[derive(Copy, Clone)]
1545+
#[derive(Copy, Clone, Versionize)]
14891546
pub struct kvm_lapic_state {
14901547
pub regs: [::std::os::raw::c_char; 1024usize],
14911548
}
@@ -1518,7 +1575,7 @@ impl Default for kvm_lapic_state {
15181575
}
15191576
}
15201577
#[repr(C)]
1521-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
1578+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
15221579
pub struct kvm_segment {
15231580
pub base: __u64,
15241581
pub limit: __u32,
@@ -1678,7 +1735,7 @@ fn bindgen_test_layout_kvm_segment() {
16781735
);
16791736
}
16801737
#[repr(C)]
1681-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
1738+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
16821739
pub struct kvm_dtable {
16831740
pub base: __u64,
16841741
pub limit: __u16,
@@ -1728,7 +1785,7 @@ fn bindgen_test_layout_kvm_dtable() {
17281785
);
17291786
}
17301787
#[repr(C)]
1731-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
1788+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
17321789
pub struct kvm_sregs {
17331790
pub cs: kvm_segment,
17341791
pub ds: kvm_segment,
@@ -2081,7 +2138,7 @@ fn bindgen_test_layout_kvm_fpu() {
20812138
);
20822139
}
20832140
#[repr(C)]
2084-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
2141+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
20852142
pub struct kvm_msr_entry {
20862143
pub index: __u32,
20872144
pub reserved: __u32,
@@ -2131,7 +2188,7 @@ fn bindgen_test_layout_kvm_msr_entry() {
21312188
);
21322189
}
21332190
#[repr(C)]
2134-
#[derive(Debug, Default)]
2191+
#[derive(Debug, Default, Versionize)]
21352192
pub struct kvm_msrs {
21362193
pub nmsrs: __u32,
21372194
pub pad: __u32,
@@ -2353,7 +2410,7 @@ fn bindgen_test_layout_kvm_cpuid() {
23532410
);
23542411
}
23552412
#[repr(C)]
2356-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
2413+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
23572414
pub struct kvm_cpuid_entry2 {
23582415
pub function: __u32,
23592416
pub index: __u32,
@@ -2458,7 +2515,7 @@ fn bindgen_test_layout_kvm_cpuid_entry2() {
24582515
);
24592516
}
24602517
#[repr(C)]
2461-
#[derive(Debug, Default)]
2518+
#[derive(Debug, Default, Versionize)]
24622519
pub struct kvm_cpuid2 {
24632520
pub nent: __u32,
24642521
pub padding: __u32,
@@ -2508,7 +2565,7 @@ fn bindgen_test_layout_kvm_cpuid2() {
25082565
);
25092566
}
25102567
#[repr(C)]
2511-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
2568+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
25122569
pub struct kvm_pit_channel_state {
25132570
pub count: __u32,
25142571
pub latched_count: __u16,
@@ -2810,7 +2867,7 @@ fn bindgen_test_layout_kvm_pit_state() {
28102867
);
28112868
}
28122869
#[repr(C)]
2813-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
2870+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
28142871
pub struct kvm_pit_state2 {
28152872
pub channels: [kvm_pit_channel_state; 3usize],
28162873
pub flags: __u32,
@@ -2901,7 +2958,7 @@ fn bindgen_test_layout_kvm_reinject_control() {
29012958
);
29022959
}
29032960
#[repr(C)]
2904-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
2961+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
29052962
pub struct kvm_vcpu_events {
29062963
pub exception: kvm_vcpu_events__bindgen_ty_1,
29072964
pub interrupt: kvm_vcpu_events__bindgen_ty_2,
@@ -2914,7 +2971,7 @@ pub struct kvm_vcpu_events {
29142971
pub exception_payload: __u64,
29152972
}
29162973
#[repr(C)]
2917-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
2974+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
29182975
pub struct kvm_vcpu_events__bindgen_ty_1 {
29192976
pub injected: __u8,
29202977
pub nr: __u8,
@@ -2998,7 +3055,7 @@ fn bindgen_test_layout_kvm_vcpu_events__bindgen_ty_1() {
29983055
);
29993056
}
30003057
#[repr(C)]
3001-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3058+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
30023059
pub struct kvm_vcpu_events__bindgen_ty_2 {
30033060
pub injected: __u8,
30043061
pub nr: __u8,
@@ -3067,7 +3124,7 @@ fn bindgen_test_layout_kvm_vcpu_events__bindgen_ty_2() {
30673124
);
30683125
}
30693126
#[repr(C)]
3070-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3127+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
30713128
pub struct kvm_vcpu_events__bindgen_ty_3 {
30723129
pub injected: __u8,
30733130
pub pending: __u8,
@@ -3136,7 +3193,7 @@ fn bindgen_test_layout_kvm_vcpu_events__bindgen_ty_3() {
31363193
);
31373194
}
31383195
#[repr(C)]
3139-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3196+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
31403197
pub struct kvm_vcpu_events__bindgen_ty_4 {
31413198
pub smm: __u8,
31423199
pub pending: __u8,
@@ -3314,7 +3371,7 @@ fn bindgen_test_layout_kvm_vcpu_events() {
33143371
);
33153372
}
33163373
#[repr(C)]
3317-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3374+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
33183375
pub struct kvm_debugregs {
33193376
pub db: [__u64; 4usize],
33203377
pub dr6: __u64,
@@ -3386,7 +3443,7 @@ fn bindgen_test_layout_kvm_debugregs() {
33863443
);
33873444
}
33883445
#[repr(C)]
3389-
#[derive(Copy, Clone)]
3446+
#[derive(Copy, Clone, Versionize)]
33903447
pub struct kvm_xsave {
33913448
pub region: [__u32; 1024usize],
33923449
}
@@ -3419,7 +3476,7 @@ impl Default for kvm_xsave {
34193476
}
34203477
}
34213478
#[repr(C)]
3422-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3479+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
34233480
pub struct kvm_xcr {
34243481
pub xcr: __u32,
34253482
pub reserved: __u32,
@@ -3469,7 +3526,7 @@ fn bindgen_test_layout_kvm_xcr() {
34693526
);
34703527
}
34713528
#[repr(C)]
3472-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
3529+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
34733530
pub struct kvm_xcrs {
34743531
pub nr_xcrs: __u32,
34753532
pub flags: __u32,
@@ -4157,14 +4214,14 @@ impl Default for kvm_irq_level {
41574214
}
41584215
}
41594216
#[repr(C)]
4160-
#[derive(Copy, Clone)]
4217+
#[derive(Copy, Clone, Versionize)]
41614218
pub struct kvm_irqchip {
41624219
pub chip_id: __u32,
41634220
pub pad: __u32,
41644221
pub chip: kvm_irqchip__bindgen_ty_1,
41654222
}
41664223
#[repr(C)]
4167-
#[derive(Copy, Clone)]
4224+
#[derive(Copy, Clone, Versionize)]
41684225
pub union kvm_irqchip__bindgen_ty_1 {
41694226
pub dummy: [::std::os::raw::c_char; 512usize],
41704227
pub pic: kvm_pic_state,
@@ -7058,7 +7115,7 @@ fn bindgen_test_layout_kvm_vapic_addr() {
70587115
);
70597116
}
70607117
#[repr(C)]
7061-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
7118+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
70627119
pub struct kvm_mp_state {
70637120
pub mp_state: __u32,
70647121
}
@@ -9121,7 +9178,7 @@ fn bindgen_test_layout_kvm_irqfd() {
91219178
);
91229179
}
91239180
#[repr(C)]
9124-
#[derive(Debug, Default, Copy, Clone, PartialEq)]
9181+
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
91259182
pub struct kvm_clock_data {
91269183
pub clock: __u64,
91279184
pub flags: __u32,

0 commit comments

Comments
 (0)