Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix structs incorrect memory layout #208

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions crates/vhost/src/vhost_user/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ bitflags! {
/// Common message header for vhost-user requests and replies.
/// A vhost-user message consists of 3 header fields and an optional payload. All numbers are in the
/// machine native byte order.
#[repr(packed)]
#[repr(C, packed)]
#[derive(Copy)]
pub(super) struct VhostUserMsgHeader<R: Req> {
request: u32,
Expand Down Expand Up @@ -438,7 +438,7 @@ bitflags! {
}

/// A generic message to encapsulate a 64-bit value.
#[repr(packed)]
#[repr(transparent)]
#[derive(Copy, Clone, Default)]
pub struct VhostUserU64 {
/// The encapsulated 64-bit common value.
Expand All @@ -458,7 +458,7 @@ unsafe impl ByteValued for VhostUserU64 {}
impl VhostUserMsgValidator for VhostUserU64 {}

/// Memory region descriptor for the SET_MEM_TABLE request.
#[repr(packed)]
#[repr(C, packed)]
#[derive(Copy, Clone, Default)]
pub struct VhostUserMemory {
/// Number of memory regions in the payload.
Expand Down Expand Up @@ -493,7 +493,7 @@ impl VhostUserMsgValidator for VhostUserMemory {
}

/// Memory region descriptors as payload for the SET_MEM_TABLE request.
#[repr(packed)]
#[repr(C, packed)]
#[derive(Default, Clone, Copy)]
pub struct VhostUserMemoryRegion {
/// Guest physical address of the memory region.
Expand Down Expand Up @@ -676,7 +676,7 @@ unsafe impl ByteValued for VhostUserSingleMemoryRegion {}
impl VhostUserMsgValidator for VhostUserSingleMemoryRegion {}

/// Vring state descriptor.
#[repr(packed)]
#[repr(C, packed)]
#[derive(Copy, Clone, Default)]
pub struct VhostUserVringState {
/// Vring index.
Expand Down Expand Up @@ -708,7 +708,7 @@ bitflags! {
}

/// Vring address descriptor.
#[repr(packed)]
#[repr(C, packed)]
#[derive(Copy, Clone, Default)]
pub struct VhostUserVringAddr {
/// Vring index.
Expand Down Expand Up @@ -792,7 +792,7 @@ bitflags! {
}

/// Message to read/write device configuration space.
#[repr(packed)]
#[repr(C, packed)]
#[derive(Copy, Clone, Default)]
pub struct VhostUserConfig {
/// Offset of virtio device's configuration space.
Expand Down Expand Up @@ -925,7 +925,7 @@ bitflags! {
pub const VHOST_USER_FS_BACKEND_ENTRIES: usize = 8;

/// Backend request message to update the MMIO window.
#[repr(packed)]
#[repr(C, packed)]
#[derive(Copy, Clone, Default)]
pub struct VhostUserFSBackendMsg {
/// File offset.
Expand Down Expand Up @@ -956,7 +956,7 @@ impl VhostUserMsgValidator for VhostUserFSBackendMsg {
}

/// Inflight I/O descriptor state for split virtqueues
#[repr(packed)]
#[repr(C, packed)]
#[derive(Clone, Copy, Default)]
pub struct DescStateSplit {
/// Indicate whether this descriptor (only head) is inflight or not.
Expand All @@ -977,7 +977,7 @@ impl DescStateSplit {
}

/// Inflight I/O queue region for split virtqueues
#[repr(packed)]
#[repr(C, packed)]
pub struct QueueRegionSplit {
/// Features flags of this region
pub features: u64,
Expand Down Expand Up @@ -1008,7 +1008,7 @@ impl QueueRegionSplit {
}

/// Inflight I/O descriptor state for packed virtqueues
#[repr(packed)]
#[repr(C, packed)]
#[derive(Clone, Copy, Default)]
pub struct DescStatePacked {
/// Indicate whether this descriptor (only head) is inflight or not.
Expand Down Expand Up @@ -1041,7 +1041,7 @@ impl DescStatePacked {
}

/// Inflight I/O queue region for packed virtqueues
#[repr(packed)]
#[repr(C, packed)]
pub struct QueueRegionPacked {
/// Features flags of this region
pub features: u64,
Expand Down