From d8becc742cc53770f0b2ea889f6c25ae0e8ae6f5 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 17 Nov 2021 13:33:13 +0000 Subject: [PATCH] vfio_user: add safety comments for `impl ByteValued` Signed-off-by: Wei Liu --- vfio_user/src/lib.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/vfio_user/src/lib.rs b/vfio_user/src/lib.rs index 2b5ab4162..8dae052ba 100644 --- a/vfio_user/src/lib.rs +++ b/vfio_user/src/lib.rs @@ -73,8 +73,6 @@ struct Header { error: u32, } -unsafe impl ByteValued for Header {} - #[repr(C)] #[derive(Default, Clone, Copy, Debug)] struct Version { @@ -82,7 +80,6 @@ struct Version { major: u16, minor: u16, } -unsafe impl ByteValued for Version {} #[derive(Serialize, Deserialize, Debug)] struct MigrationCapabilities { @@ -128,8 +125,6 @@ struct DmaMap { size: u64, } -unsafe impl ByteValued for DmaMap {} - #[repr(C)] #[derive(Default, Clone, Copy, Debug)] struct DmaUnmap { @@ -140,8 +135,6 @@ struct DmaUnmap { size: u64, } -unsafe impl ByteValued for DmaUnmap {} - #[repr(C)] #[derive(Default, Clone, Copy, Debug)] struct DeviceGetInfo { @@ -152,8 +145,6 @@ struct DeviceGetInfo { num_irqs: u32, } -unsafe impl ByteValued for DeviceGetInfo {} - #[repr(C)] #[derive(Default, Clone, Copy, Debug)] struct DeviceGetRegionInfo { @@ -161,8 +152,6 @@ struct DeviceGetRegionInfo { region_info: vfio_region_info, } -unsafe impl ByteValued for DeviceGetRegionInfo {} - #[repr(C)] #[derive(Default, Clone, Copy, Debug)] struct RegionAccess { @@ -172,8 +161,6 @@ struct RegionAccess { count: u32, } -unsafe impl ByteValued for RegionAccess {} - #[repr(C)] #[derive(Default, Clone, Copy, Debug)] struct GetIrqInfo { @@ -184,8 +171,6 @@ struct GetIrqInfo { count: u32, } -unsafe impl ByteValued for GetIrqInfo {} - #[repr(C)] #[derive(Default, Clone, Copy, Debug)] struct SetIrqs { @@ -197,14 +182,22 @@ struct SetIrqs { count: u32, } -unsafe impl ByteValued for SetIrqs {} - #[repr(C)] #[derive(Default, Clone, Copy, Debug)] struct DeviceReset { header: Header, } +// SAFETY: these data structures only contain a sereis of integers +unsafe impl ByteValued for Header {} +unsafe impl ByteValued for Version {} +unsafe impl ByteValued for DmaMap {} +unsafe impl ByteValued for DmaUnmap {} +unsafe impl ByteValued for DeviceGetInfo {} +unsafe impl ByteValued for DeviceGetRegionInfo {} +unsafe impl ByteValued for RegionAccess {} +unsafe impl ByteValued for GetIrqInfo {} +unsafe impl ByteValued for SetIrqs {} unsafe impl ByteValued for DeviceReset {} #[derive(Serialize, Deserialize, Debug)]