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

Commit dba286d

Browse files
sandreimdianpopa
authored andcommitted
Implement Versionize for some unions.
- kvm_ioapic_state__bindgen_ty_1 - kvm_irqchip__bindgen_ty_1 Signed-off-by: Andrei Sandu <[email protected]>
1 parent b289093 commit dba286d

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

src/x86/bindings_v4_20_0.rs

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,45 @@ pub struct kvm_ioapic_state {
997997
pub redirtbl: [kvm_ioapic_state__bindgen_ty_1; 24usize],
998998
}
999999
#[repr(C)]
1000-
#[derive(Copy, Clone, Versionize)]
1000+
#[derive(Copy, Clone)]
10011001
pub union kvm_ioapic_state__bindgen_ty_1 {
10021002
pub bits: __u64,
10031003
pub fields: kvm_ioapic_state__bindgen_ty_1__bindgen_ty_1,
10041004
_bindgen_union_align: u64,
10051005
}
1006+
1007+
// Manual implementation of `Versionize` since `versionize_derive` doesn't support unions
1008+
// anymore. What we're doing here is equivalent to the old autogenerated implementation, namely
1009+
// we're creating a bitwise serialization of the object.
1010+
impl Versionize for kvm_ioapic_state__bindgen_ty_1 {
1011+
fn serialize<W: std::io::Write>(
1012+
&self,
1013+
writer: &mut W,
1014+
version_map: &VersionMap,
1015+
app_version: u16,
1016+
) -> VersionizeResult<()> {
1017+
// Safe because this is a POD object and we're only using the read result to serialize
1018+
// the underlying bytes.
1019+
let bits = unsafe { self.bits };
1020+
assert_eq!(std::mem::size_of_val(&bits), std::mem::size_of::<Self>());
1021+
Versionize::serialize(&bits, writer, version_map, app_version)
1022+
}
1023+
1024+
fn deserialize<R: std::io::Read>(
1025+
reader: &mut R,
1026+
version_map: &VersionMap,
1027+
app_version: u16,
1028+
) -> VersionizeResult<Self> {
1029+
let bits: __u64 = Versionize::deserialize(reader, version_map, app_version)?;
1030+
assert_eq!(std::mem::size_of_val(&bits), std::mem::size_of::<Self>());
1031+
Ok(Self { bits })
1032+
}
1033+
1034+
fn version() -> u16 {
1035+
1
1036+
}
1037+
}
1038+
10061039
#[repr(C)]
10071040
#[derive(Debug, Default, Copy, Clone, PartialEq, Versionize)]
10081041
pub struct kvm_ioapic_state__bindgen_ty_1__bindgen_ty_1 {
@@ -4221,13 +4254,61 @@ pub struct kvm_irqchip {
42214254
pub chip: kvm_irqchip__bindgen_ty_1,
42224255
}
42234256
#[repr(C)]
4224-
#[derive(Copy, Clone, Versionize)]
4257+
#[derive(Copy, Clone)]
42254258
pub union kvm_irqchip__bindgen_ty_1 {
42264259
pub dummy: [::std::os::raw::c_char; 512usize],
42274260
pub pic: kvm_pic_state,
42284261
pub ioapic: kvm_ioapic_state,
42294262
_bindgen_union_align: [u64; 64usize],
42304263
}
4264+
4265+
// Helper struct for the manual `Versionize` implementation below. This makes things easier,
4266+
// because there's no default way of serializing larger arrays.
4267+
#[repr(transparent)]
4268+
#[derive(Versionize)]
4269+
struct kvm_irqchip__bindgen_ty_1_dummy {
4270+
dummy: [::std::os::raw::c_char; 512usize],
4271+
}
4272+
4273+
impl kvm_irqchip__bindgen_ty_1_dummy {
4274+
fn new(dummy: [::std::os::raw::c_char; 512usize]) -> Self {
4275+
Self { dummy }
4276+
}
4277+
}
4278+
4279+
// Manual implementation of `Versionize` since `versionize_derive` doesn't support unions
4280+
// anymore. What we're doing here is equivalent to the old autogenerated implementation, namely
4281+
// we're creating a bitwise serialization of the object.
4282+
impl Versionize for kvm_irqchip__bindgen_ty_1 {
4283+
fn serialize<W: std::io::Write>(
4284+
&self,
4285+
writer: &mut W,
4286+
version_map: &VersionMap,
4287+
app_version: u16,
4288+
) -> VersionizeResult<()> {
4289+
// Safe because this is a POD struct and we're only using the read result to serialize
4290+
// the underlying bytes.
4291+
let dummy = kvm_irqchip__bindgen_ty_1_dummy::new(unsafe { self.dummy });
4292+
assert_eq!(std::mem::size_of_val(&dummy), std::mem::size_of::<Self>());
4293+
Versionize::serialize(&dummy, writer, version_map, app_version)
4294+
}
4295+
4296+
fn deserialize<R: std::io::Read>(
4297+
reader: &mut R,
4298+
version_map: &VersionMap,
4299+
app_version: u16,
4300+
) -> VersionizeResult<Self> {
4301+
let dummy: kvm_irqchip__bindgen_ty_1_dummy =
4302+
Versionize::deserialize(reader, version_map, app_version)?;
4303+
assert_eq!(std::mem::size_of_val(&dummy), std::mem::size_of::<Self>());
4304+
Ok(Self { dummy: dummy.dummy })
4305+
}
4306+
4307+
fn version() -> u16 {
4308+
1
4309+
}
4310+
}
4311+
42314312
#[test]
42324313
fn bindgen_test_layout_kvm_irqchip__bindgen_ty_1() {
42334314
assert_eq!(

0 commit comments

Comments
 (0)