crosvm: upgrade zerocopy to 0.8
BUG=b:372549215 TEST=tools/dev_container tools/presubmit Change-Id: I3fcc524d1c6c41ae92c51cecb6e4d856c3d60670 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6255229 Reviewed-by: Frederick Mayle <fmayle@google.com> Reviewed-by: Dennis Kempin <denniskempin@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
8416da4a71
commit
f20af151e2
146 changed files with 1169 additions and 1035 deletions
47
Cargo.lock
generated
47
Cargo.lock
generated
|
|
@ -34,7 +34,7 @@ name = "acpi_tables"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"tempfile",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -309,7 +309,7 @@ dependencies = [
|
|||
"uuid",
|
||||
"win_util",
|
||||
"winapi",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -895,7 +895,7 @@ dependencies = [
|
|||
"win_util",
|
||||
"winapi",
|
||||
"x86_64",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -989,7 +989,7 @@ name = "data_model"
|
|||
version = "0.1.1-alpha.1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1101,7 +1101,7 @@ dependencies = [
|
|||
"win_audio",
|
||||
"win_util",
|
||||
"winapi",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1127,7 +1127,7 @@ dependencies = [
|
|||
"uuid",
|
||||
"vm_memory",
|
||||
"winapi",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
"zstd",
|
||||
]
|
||||
|
||||
|
|
@ -1238,7 +1238,7 @@ dependencies = [
|
|||
"tempfile",
|
||||
"uuid",
|
||||
"walkdir",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1325,7 +1325,7 @@ dependencies = [
|
|||
"libc",
|
||||
"remain",
|
||||
"thiserror",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1494,7 +1494,7 @@ dependencies = [
|
|||
"which",
|
||||
"win_util",
|
||||
"winapi",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1567,7 +1567,7 @@ dependencies = [
|
|||
"win_util",
|
||||
"winapi",
|
||||
"windows",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1694,7 +1694,7 @@ dependencies = [
|
|||
"serde_keyvalue",
|
||||
"static_assertions",
|
||||
"which",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1728,7 +1728,7 @@ dependencies = [
|
|||
"tempfile",
|
||||
"thiserror",
|
||||
"vm_memory",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1742,7 +1742,7 @@ dependencies = [
|
|||
"static_assertions",
|
||||
"sync",
|
||||
"vm_memory",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1752,7 +1752,7 @@ dependencies = [
|
|||
"base",
|
||||
"data_model",
|
||||
"libc",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1853,7 +1853,7 @@ dependencies = [
|
|||
"base",
|
||||
"data_model",
|
||||
"libc",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2077,7 +2077,7 @@ dependencies = [
|
|||
"thiserror",
|
||||
"virtio_sys",
|
||||
"winapi",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2300,7 +2300,7 @@ dependencies = [
|
|||
"protobuf",
|
||||
"serde",
|
||||
"sync",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3141,7 +3141,7 @@ dependencies = [
|
|||
"sync",
|
||||
"thiserror",
|
||||
"usb_sys",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3211,7 +3211,7 @@ name = "vfio_sys"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3250,7 +3250,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"base",
|
||||
"data_model",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3319,7 +3319,7 @@ dependencies = [
|
|||
"snapshot",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3338,7 +3338,7 @@ dependencies = [
|
|||
"tempfile",
|
||||
"thiserror",
|
||||
"tube_transporter",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3744,7 +3744,7 @@ dependencies = [
|
|||
"uuid",
|
||||
"vm_control",
|
||||
"vm_memory",
|
||||
"zerocopy 0.7.32",
|
||||
"zerocopy 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -3759,7 +3759,6 @@ version = "0.7.32"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"zerocopy-derive 0.7.32",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -545,7 +545,7 @@ acpi_tables = { path = "acpi_tables" }
|
|||
vm_memory = { path = "vm_memory" }
|
||||
vmm_vhost = { path = "third_party/vmm_vhost" }
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
||||
[target.'cfg(target_arch = "riscv64")'.dependencies]
|
||||
riscv64 = { path = "riscv64" }
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ authors = ["The ChromiumOS Authors"]
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3"
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone, Copy, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct FACS {
|
||||
pub signature: [u8; 4],
|
||||
pub length: u32,
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone, Copy, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct RSDP {
|
||||
pub signature: [u8; 8],
|
||||
pub checksum: u8,
|
||||
|
|
@ -46,7 +47,7 @@ impl RSDP {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::RSDP;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ use std::io::Read;
|
|||
use std::io::Result;
|
||||
use std::path::Path;
|
||||
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
/// SDT represents for System Description Table. The structure SDT is a
|
||||
/// generic format for creating various ACPI tables like DSDT/FADT/MADT.
|
||||
|
|
@ -89,7 +90,7 @@ impl SDT {
|
|||
self.data.as_slice()
|
||||
}
|
||||
|
||||
pub fn append<T: AsBytes>(&mut self, value: T) {
|
||||
pub fn append<T: IntoBytes + Immutable>(&mut self, value: T) {
|
||||
self.data.extend_from_slice(value.as_bytes());
|
||||
self.write(LENGTH_OFFSET, self.data.len() as u32);
|
||||
}
|
||||
|
|
@ -100,18 +101,18 @@ impl SDT {
|
|||
}
|
||||
|
||||
/// Read a value at the given offset
|
||||
pub fn read<T: FromBytes + AsBytes + Default>(&self, offset: usize) -> T {
|
||||
let value_len = std::mem::size_of::<T>();
|
||||
T::read_from(
|
||||
self.as_slice()
|
||||
.get(offset..offset + value_len)
|
||||
.unwrap_or(T::default().as_bytes()),
|
||||
)
|
||||
.unwrap()
|
||||
pub fn read<T: FromBytes + Default>(&self, offset: usize) -> T {
|
||||
self.as_slice()
|
||||
.get(offset..)
|
||||
.and_then(|bytes| {
|
||||
let (val, _) = T::read_from_prefix(bytes).ok()?;
|
||||
Some(val)
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Write a value at the given offset
|
||||
pub fn write<T: AsBytes>(&mut self, offset: usize, value: T) {
|
||||
pub fn write<T: IntoBytes + Immutable>(&mut self, offset: usize, value: T) {
|
||||
let value_len = std::mem::size_of::<T>();
|
||||
if (offset + value_len) > self.data.len() {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ serde_json = "1"
|
|||
smallvec = "1.6.1"
|
||||
thiserror = "1.0.20"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
protos = { path = "../protos", features = ["composite-disk"] }
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ use std::sync::OnceLock;
|
|||
use remain::sorted;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::SafeDescriptor;
|
||||
|
|
@ -252,7 +253,7 @@ impl MemoryMapping {
|
|||
/// let res = mem_map.write_obj(55u64, 16);
|
||||
/// assert!(res.is_ok());
|
||||
/// ```
|
||||
pub fn write_obj<T: AsBytes>(&self, val: T, offset: usize) -> Result<()> {
|
||||
pub fn write_obj<T: IntoBytes + Immutable>(&self, val: T, offset: usize) -> Result<()> {
|
||||
self.mapping.range_end(offset, size_of::<T>())?;
|
||||
// SAFETY:
|
||||
// This is safe because we checked the bounds above.
|
||||
|
|
@ -311,7 +312,11 @@ impl MemoryMapping {
|
|||
/// let res = mem_map.write_obj_volatile(0xf00u32, 16);
|
||||
/// assert!(res.is_ok());
|
||||
/// ```
|
||||
pub fn write_obj_volatile<T: AsBytes>(&self, val: T, offset: usize) -> Result<()> {
|
||||
pub fn write_obj_volatile<T: IntoBytes + Immutable>(
|
||||
&self,
|
||||
val: T,
|
||||
offset: usize,
|
||||
) -> Result<()> {
|
||||
self.mapping.range_end(offset, size_of::<T>())?;
|
||||
// Make sure writes to memory have been committed before performing I/O that could
|
||||
// potentially depend on them.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ use std::str;
|
|||
|
||||
use thiserror::Error;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::netlink::*;
|
||||
|
||||
|
|
@ -40,10 +41,10 @@ enum GenmsghdrCmd {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, KnownLayout)]
|
||||
struct AcpiGenlEvent {
|
||||
device_class: [::std::os::raw::c_char; 20usize],
|
||||
bus_id: [::std::os::raw::c_char; 15usize],
|
||||
device_class: [u8; 20],
|
||||
bus_id: [u8; 15],
|
||||
_type: u32,
|
||||
data: u32,
|
||||
}
|
||||
|
|
@ -63,12 +64,11 @@ impl AcpiNotifyEvent {
|
|||
return Err(AcpiEventError::InvalidMsgLen(msg_len));
|
||||
}
|
||||
|
||||
let genl_hdr = GenlMsgHdr::read_from(&netlink_message.data[..GENL_HDRLEN])
|
||||
let (genl_hdr, nl_attr) = GenlMsgHdr::read_from_prefix(netlink_message.data)
|
||||
.expect("unable to get GenlMsgHdr from slice");
|
||||
|
||||
let nlattr_end = GENL_HDRLEN + NLA_HDRLEN;
|
||||
let nl_attr = NlAttr::read_from(&netlink_message.data[GENL_HDRLEN..nlattr_end])
|
||||
.expect("unable to get NlAttr from slice");
|
||||
let (nl_attr, body) =
|
||||
NlAttr::read_from_prefix(nl_attr).expect("unable to get NlAttr from slice");
|
||||
|
||||
// Sanity check that the headers have correct for acpi event `cmd` and `_type`
|
||||
if genl_hdr.cmd != GenmsghdrCmd::AcpiGenlCmdEvent as u8
|
||||
|
|
@ -77,21 +77,12 @@ impl AcpiNotifyEvent {
|
|||
return Err(AcpiEventError::TypeAttrMissmatch);
|
||||
}
|
||||
|
||||
let acpi_event = AcpiGenlEvent::read_from(&netlink_message.data[nlattr_end..msg_len])
|
||||
.expect("unable to get AcpiGenlEvent from slice");
|
||||
|
||||
// The raw::c_char is either i8 or u8 which is known portability issue:
|
||||
// https://github.com/rust-lang/rust/issues/79089,
|
||||
// before using device_class further cast it to u8.
|
||||
let device_class: &[u8; 20usize] =
|
||||
// SAFETY: trivially safe
|
||||
unsafe { ::std::mem::transmute(&acpi_event.device_class) };
|
||||
// SAFETY: trivially safe
|
||||
let bus_id: &[u8; 15usize] = unsafe { ::std::mem::transmute(&acpi_event.bus_id) };
|
||||
let acpi_event =
|
||||
AcpiGenlEvent::read_from_bytes(body).expect("unable to get AcpiGenlEvent from slice");
|
||||
|
||||
Ok(AcpiNotifyEvent {
|
||||
device_class: strip_padding(device_class).to_owned(),
|
||||
bus_id: strip_padding(bus_id).to_owned(),
|
||||
device_class: strip_padding(&acpi_event.device_class).to_owned(),
|
||||
bus_id: strip_padding(&acpi_event.bus_id).to_owned(),
|
||||
_type: acpi_event._type,
|
||||
data: acpi_event.data,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ use std::str;
|
|||
|
||||
use libc::EINVAL;
|
||||
use log::error;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Ref;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::errno_result;
|
||||
use super::getpid;
|
||||
|
|
@ -36,7 +36,7 @@ const NLA_HDRLEN: usize = std::mem::size_of::<NlAttr>();
|
|||
const NLATTR_ALIGN_TO: usize = 4;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct NlMsgHdr {
|
||||
pub nlmsg_len: u32,
|
||||
pub nlmsg_type: u16,
|
||||
|
|
@ -47,7 +47,7 @@ struct NlMsgHdr {
|
|||
|
||||
/// Netlink attribute struct, can be used by netlink consumer
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NlAttr {
|
||||
pub len: u16,
|
||||
pub _type: u16,
|
||||
|
|
@ -55,7 +55,7 @@ pub struct NlAttr {
|
|||
|
||||
/// Generic netlink header struct, can be used by netlink consumer
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct GenlMsgHdr {
|
||||
pub cmd: u8,
|
||||
pub version: u8,
|
||||
|
|
@ -76,10 +76,6 @@ pub struct NlAttrWithData<'a> {
|
|||
pub data: &'a [u8],
|
||||
}
|
||||
|
||||
fn nlattr_align(offset: usize) -> usize {
|
||||
(offset + NLATTR_ALIGN_TO - 1) & !(NLATTR_ALIGN_TO - 1)
|
||||
}
|
||||
|
||||
/// Iterator over `struct NlAttr` as received from a netlink socket.
|
||||
pub struct NetlinkGenericDataIter<'a> {
|
||||
// `data` must be properly aligned for NlAttr.
|
||||
|
|
@ -90,28 +86,13 @@ impl<'a> Iterator for NetlinkGenericDataIter<'a> {
|
|||
type Item = NlAttrWithData<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.data.len() < NLA_HDRLEN {
|
||||
return None;
|
||||
}
|
||||
let nl_hdr = NlAttr::read_from(&self.data[..NLA_HDRLEN])?;
|
||||
|
||||
// Make sure NlAtrr fits
|
||||
let (nl_hdr, _) = NlAttr::read_from_prefix(self.data).ok()?;
|
||||
let nl_data_len = nl_hdr.len as usize;
|
||||
if nl_data_len < NLA_HDRLEN || nl_data_len > self.data.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Get data related to processed NlAttr
|
||||
let data_start = NLA_HDRLEN;
|
||||
let data = &self.data[data_start..nl_data_len];
|
||||
let data = self.data.get(NLA_HDRLEN..nl_data_len)?;
|
||||
|
||||
// Get next NlAttr
|
||||
let next_hdr = nlattr_align(nl_data_len);
|
||||
if next_hdr >= self.data.len() {
|
||||
self.data = &[];
|
||||
} else {
|
||||
self.data = &self.data[next_hdr..];
|
||||
}
|
||||
let next_hdr = nl_data_len.next_multiple_of(NLATTR_ALIGN_TO);
|
||||
self.data = self.data.get(next_hdr..).unwrap_or(&[]);
|
||||
|
||||
Some(NlAttrWithData {
|
||||
_type: nl_hdr._type,
|
||||
|
|
@ -131,29 +112,13 @@ impl<'a> Iterator for NetlinkMessageIter<'a> {
|
|||
type Item = NetlinkMessage<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.data.len() < NLMSGHDR_SIZE {
|
||||
return None;
|
||||
}
|
||||
let hdr = NlMsgHdr::read_from(&self.data[..NLMSGHDR_SIZE])?;
|
||||
|
||||
// NLMSG_OK
|
||||
let (hdr, _) = NlMsgHdr::read_from_prefix(self.data).ok()?;
|
||||
let msg_len = hdr.nlmsg_len as usize;
|
||||
if msg_len < NLMSGHDR_SIZE || msg_len > self.data.len() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// NLMSG_DATA
|
||||
let data_start = NLMSGHDR_SIZE;
|
||||
let data = &self.data[data_start..msg_len];
|
||||
let data = self.data.get(NLMSGHDR_SIZE..msg_len)?;
|
||||
|
||||
// NLMSG_NEXT
|
||||
let align_to = std::mem::align_of::<NlMsgHdr>();
|
||||
let next_hdr = (msg_len + align_to - 1) & !(align_to - 1);
|
||||
if next_hdr >= self.data.len() {
|
||||
self.data = &[];
|
||||
} else {
|
||||
self.data = &self.data[next_hdr..];
|
||||
}
|
||||
let next_hdr = msg_len.next_multiple_of(std::mem::align_of::<NlMsgHdr>());
|
||||
self.data = self.data.get(next_hdr..).unwrap_or(&[]);
|
||||
|
||||
Some(NetlinkMessage {
|
||||
_type: hdr.nlmsg_type,
|
||||
|
|
@ -262,9 +227,7 @@ impl NetlinkGenericSocket {
|
|||
let data = unsafe { allocation.as_mut_slice(buf_size) };
|
||||
|
||||
// Prepare the netlink message header
|
||||
let hdr = Ref::<_, NlMsgHdr>::new(&mut data[..NLMSGHDR_SIZE])
|
||||
.expect("failed to unwrap")
|
||||
.into_mut();
|
||||
let (hdr, genl_hdr) = NlMsgHdr::mut_from_prefix(data).expect("failed to unwrap");
|
||||
hdr.nlmsg_len = NLMSGHDR_SIZE as u32 + GENL_HDRLEN as u32;
|
||||
hdr.nlmsg_len += NLA_HDRLEN as u32 + family_name.len() as u32 + 1;
|
||||
hdr.nlmsg_flags = libc::NLM_F_REQUEST as u16;
|
||||
|
|
@ -272,36 +235,26 @@ impl NetlinkGenericSocket {
|
|||
hdr.nlmsg_pid = getpid() as u32;
|
||||
|
||||
// Prepare generic netlink message header
|
||||
let genl_hdr_end = NLMSGHDR_SIZE + GENL_HDRLEN;
|
||||
let genl_hdr = Ref::<_, GenlMsgHdr>::new(&mut data[NLMSGHDR_SIZE..genl_hdr_end])
|
||||
.expect("unable to get GenlMsgHdr from slice")
|
||||
.into_mut();
|
||||
let (genl_hdr, nlattr) =
|
||||
GenlMsgHdr::mut_from_prefix(genl_hdr).expect("unable to get GenlMsgHdr from slice");
|
||||
genl_hdr.cmd = libc::CTRL_CMD_GETFAMILY as u8;
|
||||
genl_hdr.version = 0x1;
|
||||
|
||||
// Netlink attributes
|
||||
let nlattr_start = genl_hdr_end;
|
||||
let nlattr_end = nlattr_start + NLA_HDRLEN;
|
||||
let nl_attr = Ref::<_, NlAttr>::new(&mut data[nlattr_start..nlattr_end])
|
||||
.expect("unable to get NlAttr from slice")
|
||||
.into_mut();
|
||||
let (nl_attr, payload) =
|
||||
NlAttr::mut_from_prefix(nlattr).expect("unable to get NlAttr from slice");
|
||||
nl_attr._type = libc::CTRL_ATTR_FAMILY_NAME as u16;
|
||||
nl_attr.len = family_name.len() as u16 + 1 + NLA_HDRLEN as u16;
|
||||
|
||||
// Fill the message payload with the family name
|
||||
let payload_start = nlattr_end;
|
||||
let payload_end = payload_start + family_name.len();
|
||||
data[payload_start..payload_end].copy_from_slice(family_name.as_bytes());
|
||||
payload[..family_name.len()].copy_from_slice(family_name.as_bytes());
|
||||
|
||||
let len = NLMSGHDR_SIZE + GENL_HDRLEN + NLA_HDRLEN + family_name.len() + 1;
|
||||
|
||||
// SAFETY:
|
||||
// Safe because we pass a valid, owned socket fd and a valid pointer/size for the buffer.
|
||||
unsafe {
|
||||
let res = libc::send(
|
||||
self.sock.as_raw_fd(),
|
||||
allocation.as_ptr(),
|
||||
payload_end + 1,
|
||||
0,
|
||||
);
|
||||
let res = libc::send(self.sock.as_raw_fd(), allocation.as_ptr(), len, 0);
|
||||
if res < 0 {
|
||||
error!("failed to send get_family_cmd");
|
||||
return errno_result();
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@ use serde::de::DeserializeOwned;
|
|||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::descriptor::AsRawDescriptor;
|
||||
use crate::descriptor::FromRawDescriptor;
|
||||
|
|
@ -81,7 +82,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct MsgHeader {
|
||||
msg_json_size: usize,
|
||||
|
|
@ -308,7 +309,7 @@ pub fn deserialize_and_recv<T: DeserializeOwned, F: FnMut(&mut [u8]) -> io::Resu
|
|||
mut read_fn: F,
|
||||
) -> Result<T> {
|
||||
let mut header = MsgHeader::default();
|
||||
perform_read(&mut read_fn, header.as_bytes_mut()).map_err(Error::from_recv_io_error)?;
|
||||
perform_read(&mut read_fn, header.as_mut_bytes()).map_err(Error::from_recv_io_error)?;
|
||||
|
||||
let mut msg_json = vec![0u8; header.msg_json_size];
|
||||
perform_read(&mut read_fn, msg_json.as_mut_slice()).map_err(Error::from_recv_io_error)?;
|
||||
|
|
|
|||
|
|
@ -31,9 +31,8 @@ use std::slice;
|
|||
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Ref;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::IoBufMut;
|
||||
|
||||
|
|
@ -231,7 +230,7 @@ impl<'a> VolatileSlice<'a> {
|
|||
/// ```
|
||||
pub fn copy_to<T>(&self, buf: &mut [T])
|
||||
where
|
||||
T: FromBytes + AsBytes + Copy,
|
||||
T: FromBytes + IntoBytes + Copy,
|
||||
{
|
||||
let mut addr = self.as_mut_ptr() as *const u8;
|
||||
for v in buf.iter_mut().take(self.size() / size_of::<T>()) {
|
||||
|
|
@ -296,16 +295,13 @@ impl<'a> VolatileSlice<'a> {
|
|||
/// ```
|
||||
pub fn copy_from<T>(&self, buf: &[T])
|
||||
where
|
||||
T: FromBytes + AsBytes,
|
||||
T: IntoBytes + Copy,
|
||||
{
|
||||
let mut addr = self.as_mut_ptr();
|
||||
for v in buf.iter().take(self.size() / size_of::<T>()) {
|
||||
// SAFETY: Safe because buf is valid, aligned to type `T` and is mutable.
|
||||
unsafe {
|
||||
write_volatile(
|
||||
addr as *mut T,
|
||||
Ref::<_, T>::new(v.as_bytes()).unwrap().read(),
|
||||
);
|
||||
write_volatile(addr as *mut T, *v);
|
||||
addr = addr.add(size_of::<T>());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,4 +9,4 @@ license-file = "LICENSE"
|
|||
|
||||
[dependencies]
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -36,9 +36,10 @@ use serde::Deserialize;
|
|||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
macro_rules! endian_type {
|
||||
($old_type:ident, $new_type:ident, $to_new:ident, $from_new:ident) => {
|
||||
|
|
@ -46,7 +47,7 @@ macro_rules! endian_type {
|
|||
///
|
||||
/// See module level documentation for examples.
|
||||
#[repr(transparent)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct $new_type($old_type);
|
||||
|
||||
impl $new_type {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ virtio_sys = { path = "../virtio_sys" }
|
|||
virtio-media = { version = "0.0.7", optional = true }
|
||||
vm_control = { path = "../vm_control" }
|
||||
vm_memory = { path = "../vm_memory" }
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
||||
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
|
||||
android_audio = { path = "../android_audio" }
|
||||
|
|
|
|||
|
|
@ -64,9 +64,8 @@ use vm_control::VmMemoryDestination;
|
|||
use vm_control::VmMemorySource;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::pci::pci_configuration::PciBarConfiguration;
|
||||
use crate::pci::pci_configuration::PciBarPrefetchable;
|
||||
|
|
@ -270,7 +269,7 @@ fn vfio_unmap(vfio_container: &Arc<Mutex<VfioContainer>>, iova: u64, size: u64)
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromBytes, IntoBytes)]
|
||||
#[repr(C)]
|
||||
struct PinPageInfo {
|
||||
bdf: u16,
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ use base::Tube;
|
|||
use bit_field::*;
|
||||
use vm_control::VmIrqRequest;
|
||||
use vm_control::VmIrqResponse;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::pci::pci_configuration::PciCapConfig;
|
||||
use crate::pci::pci_configuration::PciCapConfigWriteResult;
|
||||
|
|
@ -265,7 +266,7 @@ impl MsiConfig {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct MsiCtrl {
|
||||
enable: B1,
|
||||
multi_msg_capable: B3,
|
||||
|
|
@ -279,7 +280,7 @@ pub struct MsiCtrl {
|
|||
|
||||
#[allow(dead_code)]
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
/// MSI Capability Structure
|
||||
pub struct MsiCap {
|
||||
// To make add_capability() happy
|
||||
|
|
|
|||
|
|
@ -21,9 +21,10 @@ use snapshot::AnySnapshot;
|
|||
use thiserror::Error;
|
||||
use vm_control::VmIrqRequest;
|
||||
use vm_control::VmIrqResponse;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::pci::pci_configuration::PciCapConfig;
|
||||
use crate::pci::pci_configuration::PciCapConfigWriteResult;
|
||||
|
|
@ -755,7 +756,7 @@ impl AsRawDescriptor for MsixConfig {
|
|||
// 15: Enable. Enable all MSI-X when set.
|
||||
// See <https://wiki.osdev.org/PCI#Enabling_MSI-X> for the details.
|
||||
#[bitfield]
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct MsixCtrl {
|
||||
table_size: B10,
|
||||
reserved: B4,
|
||||
|
|
@ -765,7 +766,7 @@ pub struct MsixCtrl {
|
|||
|
||||
#[allow(dead_code)]
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
/// MSI-X Capability Structure
|
||||
pub struct MsixCap {
|
||||
// To make add_capability() happy
|
||||
|
|
|
|||
|
|
@ -1097,12 +1097,15 @@ impl PciCapMapping {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone, Copy, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[allow(dead_code)]
|
||||
struct TestCap {
|
||||
_vndr: u8,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ use std::sync::Arc;
|
|||
|
||||
use resources::SystemAllocator;
|
||||
use sync::Mutex;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::pci::pci_configuration::PciCapConfig;
|
||||
use crate::pci::pci_configuration::PciCapConfigWriteResult;
|
||||
|
|
@ -52,7 +55,7 @@ pub trait PcieDevice: Send {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct PcieCap {
|
||||
_cap_vndr: u8,
|
||||
_cap_next: u8,
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ use vm_control::HotPlugDeviceInfo;
|
|||
use vm_control::HotPlugDeviceType;
|
||||
use vm_control::VmRequest;
|
||||
use vm_control::VmResponse;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::pci::pci_configuration::PciBridgeSubclass;
|
||||
use crate::pci::pci_configuration::CAPABILITY_LIST_HEAD_OFFSET;
|
||||
|
|
@ -66,7 +66,7 @@ impl PciHostConfig {
|
|||
}
|
||||
|
||||
// Read host pci device's config register
|
||||
fn read_config<T: AsBytes + FromBytes + Copy + Default>(&self, offset: u64) -> T {
|
||||
fn read_config<T: IntoBytes + FromBytes + Copy + Default>(&self, offset: u64) -> T {
|
||||
let length = std::mem::size_of::<T>();
|
||||
let mut val = T::default();
|
||||
if offset % length as u64 != 0 {
|
||||
|
|
@ -74,7 +74,7 @@ impl PciHostConfig {
|
|||
"read_config, offset {} isn't aligned to length {}",
|
||||
offset, length
|
||||
);
|
||||
} else if let Err(e) = self.config_file.read_exact_at(val.as_bytes_mut(), offset) {
|
||||
} else if let Err(e) = self.config_file.read_exact_at(val.as_mut_bytes(), offset) {
|
||||
error!("failed to read host sysfs config: {}", e);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
#![cfg_attr(windows, allow(dead_code))]
|
||||
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::pci::pci_configuration::PciCapConfig;
|
||||
use crate::pci::pci_configuration::PciCapConfigWriteResult;
|
||||
|
|
@ -35,7 +36,7 @@ pub enum PciDevicePower {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct PciPmCap {
|
||||
_cap_vndr: u8,
|
||||
_cap_next: u8,
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ use std::sync::MutexGuard;
|
|||
|
||||
use base::error;
|
||||
use sync::Mutex;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
/// Type of offset in the register space.
|
||||
pub type RegisterOffset = u64;
|
||||
|
|
@ -65,8 +65,8 @@ pub trait RegisterValue:
|
|||
'static
|
||||
+ Into<u64>
|
||||
+ Clone
|
||||
+ AsBytes
|
||||
+ FromBytes
|
||||
+ IntoBytes
|
||||
+ Send
|
||||
+ Sync
|
||||
+ Copy
|
||||
|
|
@ -269,7 +269,7 @@ impl<T: RegisterValue> RegisterInterface for Register<T> {
|
|||
let total_size = (overlap.to - overlap.from) as usize + 1;
|
||||
|
||||
let mut reg_value: T = self.lock().value;
|
||||
let value: &mut [u8] = reg_value.as_bytes_mut();
|
||||
let value: &mut [u8] = reg_value.as_mut_bytes();
|
||||
for i in 0..total_size {
|
||||
value[my_start_idx + i] = self.apply_write_masks_to_byte(
|
||||
value[my_start_idx + i],
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use usb_util::Transfer;
|
|||
use usb_util::TransferBuffer;
|
||||
use usb_util::TransferStatus;
|
||||
use usb_util::UsbRequestSetup;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::usb::backend::endpoint::ControlEndpointState;
|
||||
use crate::usb::backend::endpoint::UsbEndpoint;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use base::EventType;
|
|||
use base::RawDescriptor;
|
||||
use sync::Mutex;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
|
||||
use crate::usb::backend::fido_backend::constants;
|
||||
use crate::usb::backend::fido_backend::error::Error;
|
||||
|
|
@ -27,7 +26,7 @@ use crate::usb::backend::fido_backend::hid_utils::verify_is_fido_device;
|
|||
use crate::usb::backend::fido_backend::poll_thread::PollTimer;
|
||||
use crate::utils::EventLoop;
|
||||
|
||||
#[derive(FromZeroes, FromBytes, Debug)]
|
||||
#[derive(FromBytes, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct InitPacket {
|
||||
cid: [u8; constants::CID_SIZE],
|
||||
|
|
@ -52,7 +51,7 @@ impl InitPacket {
|
|||
return Err(Error::InvalidInitPacket);
|
||||
}
|
||||
|
||||
InitPacket::read_from(bytes).ok_or_else(|| Error::CannotConvertInitPacketFromBytes)
|
||||
InitPacket::read_from_bytes(bytes).map_err(|_| Error::CannotConvertInitPacketFromBytes)
|
||||
}
|
||||
|
||||
pub fn bcnt(&self) -> u16 {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ use usb_util::Error as UsbUtilError;
|
|||
use usb_util::TransferBuffer;
|
||||
use usb_util::TransferStatus;
|
||||
use usb_util::UsbRequestSetup;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::usb::backend::device::BackendDevice;
|
||||
use crate::usb::backend::device::DeviceState;
|
||||
|
|
@ -149,7 +149,9 @@ impl FidoPassthroughDevice {
|
|||
transfer.actual_length = 0;
|
||||
let request_setup = match &transfer.buffer {
|
||||
TransferBuffer::Vector(v) => {
|
||||
UsbRequestSetup::read_from_prefix(v).ok_or_else(|| Error::InvalidDataBufferSize)?
|
||||
UsbRequestSetup::read_from_prefix(v)
|
||||
.map_err(|_| Error::InvalidDataBufferSize)?
|
||||
.0
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::UnsupportedTransferBufferType);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use usb_util::TransferBuffer;
|
|||
use usb_util::TransferHandle;
|
||||
use usb_util::TransferStatus;
|
||||
use usb_util::UsbRequestSetup;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::usb::backend::device::BackendDevice;
|
||||
use crate::usb::backend::device::DeviceState;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use thiserror::Error;
|
|||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use vm_memory::GuestMemoryError;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::xhci_abi::EventRingSegmentTableEntry;
|
||||
use super::xhci_abi::Trb;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ use bit_field::*;
|
|||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
use vm_memory::GuestAddress;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
|
|
@ -118,7 +119,7 @@ impl DequeuePtr {
|
|||
|
||||
// Generic TRB struct containing only fields common to all types.
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct Trb {
|
||||
parameter: B64,
|
||||
status: B32,
|
||||
|
|
@ -295,7 +296,7 @@ impl Trb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NormalTrb {
|
||||
data_buffer: B64,
|
||||
trb_transfer_length: B17,
|
||||
|
|
@ -315,7 +316,7 @@ pub struct NormalTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct SetupStageTrb {
|
||||
request_type: B8,
|
||||
request: B8,
|
||||
|
|
@ -336,7 +337,7 @@ pub struct SetupStageTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct DataStageTrb {
|
||||
data_buffer_pointer: B64,
|
||||
trb_transfer_length: B17,
|
||||
|
|
@ -356,7 +357,7 @@ pub struct DataStageTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct StatusStageTrb {
|
||||
reserved0: B64,
|
||||
reserved1: B22,
|
||||
|
|
@ -373,7 +374,7 @@ pub struct StatusStageTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct IsochTrb {
|
||||
data_buffer_pointer: B64,
|
||||
trb_transfer_length: B17,
|
||||
|
|
@ -395,7 +396,7 @@ pub struct IsochTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct LinkTrb {
|
||||
ring_segment_pointer: B64,
|
||||
reserved0: B22,
|
||||
|
|
@ -411,7 +412,7 @@ pub struct LinkTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct EventDataTrb {
|
||||
event_data: B64,
|
||||
reserved0: B22,
|
||||
|
|
@ -428,7 +429,7 @@ pub struct EventDataTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NoopTrb {
|
||||
reserved0: B64,
|
||||
reserved1: B22,
|
||||
|
|
@ -444,7 +445,7 @@ pub struct NoopTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct DisableSlotCommandTrb {
|
||||
reserved0: B32,
|
||||
reserved1: B32,
|
||||
|
|
@ -457,7 +458,7 @@ pub struct DisableSlotCommandTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct AddressDeviceCommandTrb {
|
||||
input_context_pointer: B64,
|
||||
reserved: B32,
|
||||
|
|
@ -470,7 +471,7 @@ pub struct AddressDeviceCommandTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct ConfigureEndpointCommandTrb {
|
||||
input_context_pointer: B64,
|
||||
reserved0: B32,
|
||||
|
|
@ -483,7 +484,7 @@ pub struct ConfigureEndpointCommandTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct EvaluateContextCommandTrb {
|
||||
input_context_pointer: B64,
|
||||
reserved0: B32,
|
||||
|
|
@ -495,7 +496,7 @@ pub struct EvaluateContextCommandTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct ResetEndpointCommandTrb {
|
||||
reserved0: B32,
|
||||
reserved1: B32,
|
||||
|
|
@ -510,7 +511,7 @@ pub struct ResetEndpointCommandTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct StopEndpointCommandTrb {
|
||||
reserved0: B32,
|
||||
reserved1: B32,
|
||||
|
|
@ -525,7 +526,7 @@ pub struct StopEndpointCommandTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct SetTRDequeuePointerCommandTrb {
|
||||
dequeue_cycle_state: bool,
|
||||
stream_context_type: B3,
|
||||
|
|
@ -542,7 +543,7 @@ pub struct SetTRDequeuePointerCommandTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct ResetDeviceCommandTrb {
|
||||
reserved0: B32,
|
||||
reserved1: B32,
|
||||
|
|
@ -555,7 +556,7 @@ pub struct ResetDeviceCommandTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct TransferEventTrb {
|
||||
trb_pointer: B64,
|
||||
trb_transfer_length: B24,
|
||||
|
|
@ -571,7 +572,7 @@ pub struct TransferEventTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct CommandCompletionEventTrb {
|
||||
trb_pointer: B64,
|
||||
command_completion_parameter: B24,
|
||||
|
|
@ -584,7 +585,7 @@ pub struct CommandCompletionEventTrb {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct PortStatusChangeEventTrb {
|
||||
reserved0: B24,
|
||||
port_id: B8,
|
||||
|
|
@ -686,16 +687,18 @@ impl TypedTrb for PortStatusChangeEventTrb {
|
|||
///
|
||||
/// All trb structs have the same size. One trb could be safely casted to another, though the
|
||||
/// values might be invalid.
|
||||
pub unsafe trait TrbCast: FromBytes + AsBytes + TypedTrb {
|
||||
pub unsafe trait TrbCast:
|
||||
FromBytes + Immutable + IntoBytes + KnownLayout + TypedTrb
|
||||
{
|
||||
fn cast<T: TrbCast>(&self) -> Result<&T> {
|
||||
zerocopy::Ref::<_, T>::new(self.as_bytes())
|
||||
.ok_or(Error::CannotCastTrb)
|
||||
zerocopy::Ref::<_, T>::from_bytes(self.as_bytes())
|
||||
.map_err(|_| Error::CannotCastTrb)
|
||||
.map(zerocopy::Ref::into_ref)
|
||||
}
|
||||
|
||||
fn cast_mut<T: TrbCast>(&mut self) -> Result<&mut T> {
|
||||
zerocopy::Ref::<_, T>::new(self.as_bytes_mut())
|
||||
.ok_or(Error::CannotCastTrb)
|
||||
zerocopy::Ref::<_, T>::from_bytes(self.as_mut_bytes())
|
||||
.map_err(|_| Error::CannotCastTrb)
|
||||
.map(zerocopy::Ref::into_mut)
|
||||
}
|
||||
|
||||
|
|
@ -766,7 +769,7 @@ unsafe impl TrbCast for CommandCompletionEventTrb {}
|
|||
unsafe impl TrbCast for PortStatusChangeEventTrb {}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct EventRingSegmentTableEntry {
|
||||
ring_segment_base_address: B64,
|
||||
ring_segment_size: B16,
|
||||
|
|
@ -774,7 +777,7 @@ pub struct EventRingSegmentTableEntry {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct InputControlContext {
|
||||
// Xhci spec 6.2.5.1.
|
||||
drop_context_flags: B32,
|
||||
|
|
@ -806,7 +809,7 @@ impl InputControlContext {
|
|||
pub const DEVICE_CONTEXT_ENTRY_SIZE: usize = 32usize;
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct SlotContext {
|
||||
route_string: B20,
|
||||
speed: B4,
|
||||
|
|
@ -832,7 +835,7 @@ pub struct SlotContext {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct EndpointContext {
|
||||
endpoint_state: EndpointState,
|
||||
reserved1: B5,
|
||||
|
|
@ -859,7 +862,7 @@ pub struct EndpointContext {
|
|||
}
|
||||
|
||||
#[bitfield]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct StreamContext {
|
||||
dequeue_cycle_state: bool,
|
||||
stream_context_type: B3,
|
||||
|
|
@ -870,14 +873,14 @@ pub struct StreamContext {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct StreamContextArray {
|
||||
pub stream_contexts: [StreamContext; 16],
|
||||
}
|
||||
|
||||
/// Device context.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct DeviceContext {
|
||||
pub slot_context: SlotContext,
|
||||
pub endpoint_context: [EndpointContext; 31],
|
||||
|
|
|
|||
|
|
@ -48,8 +48,9 @@ use thiserror::Error;
|
|||
use vfio_sys::vfio::vfio_acpi_dsm;
|
||||
use vfio_sys::vfio::VFIO_IRQ_SET_DATA_BOOL;
|
||||
use vfio_sys::*;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::IommuDevType;
|
||||
|
||||
|
|
@ -318,7 +319,7 @@ fn extract_vfio_struct<T>(bytes: &[u8], offset: usize) -> Option<T>
|
|||
where
|
||||
T: FromBytes,
|
||||
{
|
||||
bytes.get(offset..).and_then(T::read_from_prefix)
|
||||
Some(T::read_from_prefix(bytes.get(offset..)?).ok()?.0)
|
||||
}
|
||||
|
||||
const VFIO_API_VERSION: u8 = 0;
|
||||
|
|
@ -1818,8 +1819,8 @@ impl VfioDevice {
|
|||
}
|
||||
|
||||
/// Writes data into the specified `VfioRegionAddr.addr` + `offset`.
|
||||
pub fn region_write_to_addr<T: AsBytes>(&self, val: &T, addr: &VfioRegionAddr, offset: u64) {
|
||||
self.region_write(addr.index, val.as_bytes(), addr.addr + offset);
|
||||
pub fn region_write_to_addr(&self, data: &[u8], addr: &VfioRegionAddr, offset: u64) {
|
||||
self.region_write(addr.index, data, addr.addr + offset);
|
||||
}
|
||||
|
||||
/// get vfio device's descriptors which are passed into minijail process
|
||||
|
|
@ -1898,17 +1899,17 @@ impl VfioPciConfig {
|
|||
VfioPciConfig { device }
|
||||
}
|
||||
|
||||
pub fn read_config<T: AsBytes + FromBytes>(&self, offset: u32) -> T {
|
||||
pub fn read_config<T: IntoBytes + FromBytes>(&self, offset: u32) -> T {
|
||||
let mut config = T::new_zeroed();
|
||||
self.device.region_read(
|
||||
VFIO_PCI_CONFIG_REGION_INDEX as usize,
|
||||
config.as_bytes_mut(),
|
||||
config.as_mut_bytes(),
|
||||
offset.into(),
|
||||
);
|
||||
config
|
||||
}
|
||||
|
||||
pub fn write_config<T: AsBytes>(&self, config: T, offset: u32) {
|
||||
pub fn write_config<T: Immutable + IntoBytes>(&self, config: T, offset: u32) {
|
||||
self.device.region_write(
|
||||
VFIO_PCI_CONFIG_REGION_INDEX as usize,
|
||||
config.as_bytes(),
|
||||
|
|
|
|||
|
|
@ -53,9 +53,10 @@ use vm_control::api::VmMemoryClient;
|
|||
use vm_control::RegisteredEventWithData;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::async_utils;
|
||||
use super::copy_config;
|
||||
|
|
@ -135,7 +136,7 @@ pub enum BalloonFeatures {
|
|||
}
|
||||
|
||||
// virtio_balloon_config is the balloon device configuration space defined by the virtio spec.
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct virtio_balloon_config {
|
||||
num_pages: Le32,
|
||||
|
|
@ -175,7 +176,7 @@ const VIRTIO_BALLOON_S_NONSTANDARD_SHMEM: u16 = 65534;
|
|||
const VIRTIO_BALLOON_S_NONSTANDARD_UNEVICTABLE: u16 = 65535;
|
||||
|
||||
// BalloonStat is used to deserialize stats from the stats_queue.
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C, packed)]
|
||||
struct BalloonStat {
|
||||
tag: Le16,
|
||||
|
|
@ -205,7 +206,7 @@ impl BalloonStat {
|
|||
|
||||
// virtio_balloon_ws is used to deserialize from the ws data vq.
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct virtio_balloon_ws {
|
||||
tag: Le16,
|
||||
node_id: Le16,
|
||||
|
|
@ -237,7 +238,7 @@ const _VIRTIO_BALLOON_WS_OP_DISCARD: u16 = 3;
|
|||
|
||||
// virtio_balloon_op is used to serialize to the ws cmd vq.
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct virtio_balloon_op {
|
||||
type_: Le16,
|
||||
}
|
||||
|
|
@ -1409,7 +1410,7 @@ impl VirtioDevice for Balloon {
|
|||
|
||||
fn write_config(&mut self, offset: u64, data: &[u8]) {
|
||||
let mut config = self.get_config();
|
||||
copy_config(config.as_bytes_mut(), offset, data, 0);
|
||||
copy_config(config.as_mut_bytes(), offset, data, 0);
|
||||
let mut state = block_on(self.state.lock());
|
||||
state.actual_pages = config.actual.to_native();
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ use virtio_sys::virtio_config::VIRTIO_F_RING_PACKED;
|
|||
use vm_control::DiskControlCommand;
|
||||
use vm_control::DiskControlResult;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::async_utils;
|
||||
use crate::virtio::block::sys::*;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use anyhow::anyhow;
|
|||
use anyhow::Context;
|
||||
use base::debug;
|
||||
use base::error;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::console::worker::WorkerPort;
|
||||
use crate::virtio::device_constants::console::virtio_console_control;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use data_model::Le32;
|
|||
use hypervisor::ProtectionType;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::base_features;
|
||||
use crate::virtio::console::port::ConsolePort;
|
||||
|
|
|
|||
|
|
@ -25,9 +25,10 @@ use disk::AsyncDisk;
|
|||
use smallvec::SmallVec;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::DescriptorChain;
|
||||
use crate::virtio::SplitDescriptorChain;
|
||||
|
|
@ -533,7 +534,7 @@ impl Writer {
|
|||
}
|
||||
|
||||
/// Writes an object to the descriptor chain buffer.
|
||||
pub fn write_obj<T: AsBytes>(&mut self, val: T) -> io::Result<()> {
|
||||
pub fn write_obj<T: Immutable + IntoBytes>(&mut self, val: T) -> io::Result<()> {
|
||||
self.write_all(val.as_bytes())
|
||||
}
|
||||
|
||||
|
|
@ -541,12 +542,18 @@ impl Writer {
|
|||
/// this doesn't require the values to be stored in an intermediate collection first. It also
|
||||
/// allows callers to choose which elements in a collection to write, for example by using the
|
||||
/// `filter` or `take` methods of the `Iterator` trait.
|
||||
pub fn write_iter<T: AsBytes, I: Iterator<Item = T>>(&mut self, mut iter: I) -> io::Result<()> {
|
||||
pub fn write_iter<T: Immutable + IntoBytes, I: Iterator<Item = T>>(
|
||||
&mut self,
|
||||
mut iter: I,
|
||||
) -> io::Result<()> {
|
||||
iter.try_for_each(|v| self.write_obj(v))
|
||||
}
|
||||
|
||||
/// Writes a collection of objects into the descriptor chain buffer.
|
||||
pub fn consume<T: AsBytes, C: IntoIterator<Item = T>>(&mut self, vals: C) -> io::Result<()> {
|
||||
pub fn consume<T: Immutable + IntoBytes, C: IntoIterator<Item = T>>(
|
||||
&mut self,
|
||||
vals: C,
|
||||
) -> io::Result<()> {
|
||||
self.write_iter(vals.into_iter())
|
||||
}
|
||||
|
||||
|
|
@ -766,7 +773,7 @@ pub enum DescriptorType {
|
|||
Writable,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct virtq_desc {
|
||||
addr: Le64,
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ use data_model::Le32;
|
|||
use data_model::Le64;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
/// Virtio feature bits that are specific to a device type.
|
||||
///
|
||||
|
|
@ -44,7 +45,7 @@ pub mod block {
|
|||
pub const VIRTIO_BLK_F_DISCARD: u32 = 13;
|
||||
pub const VIRTIO_BLK_F_WRITE_ZEROES: u32 = 14;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_blk_geometry {
|
||||
cylinders: Le16,
|
||||
|
|
@ -52,7 +53,7 @@ pub mod block {
|
|||
sectors: u8,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_blk_topology {
|
||||
physical_block_exp: u8,
|
||||
|
|
@ -61,7 +62,7 @@ pub mod block {
|
|||
opt_io_size: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C, packed)]
|
||||
pub struct virtio_blk_config {
|
||||
pub capacity: Le64,
|
||||
|
|
@ -82,7 +83,7 @@ pub mod block {
|
|||
pub unused1: [u8; 3],
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub(crate) struct virtio_blk_req_header {
|
||||
pub req_type: Le32,
|
||||
|
|
@ -90,7 +91,7 @@ pub mod block {
|
|||
pub sector: Le64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub(crate) struct virtio_blk_discard_write_zeroes {
|
||||
pub sector: Le64,
|
||||
|
|
@ -122,7 +123,7 @@ pub mod gpu {
|
|||
|
||||
pub const VIRTIO_GPU_SHM_ID_HOST_VISIBLE: u8 = 0x0001;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_config {
|
||||
pub events_read: Le32,
|
||||
|
|
@ -139,9 +140,10 @@ pub mod snd {
|
|||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
AsBytes,
|
||||
FromZeroes,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
PartialEq,
|
||||
|
|
@ -166,9 +168,10 @@ pub mod video {
|
|||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde_keyvalue::FromKeyValues;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
pub const CMD_QUEUE_INDEX: usize = 0;
|
||||
pub const EVENT_QUEUE_INDEX: usize = 1;
|
||||
|
|
@ -235,7 +238,7 @@ pub mod video {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_config {
|
||||
pub version: Le32,
|
||||
pub max_caps_length: Le32,
|
||||
|
|
@ -259,15 +262,16 @@ pub mod wl {
|
|||
pub mod console {
|
||||
use data_model::Le16;
|
||||
use data_model::Le32;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
pub const VIRTIO_CONSOLE_F_SIZE: u32 = 0;
|
||||
pub const VIRTIO_CONSOLE_F_MULTIPORT: u32 = 1;
|
||||
pub const VIRTIO_CONSOLE_F_EMERG_WRITE: u32 = 2;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_console_config {
|
||||
pub cols: Le16,
|
||||
|
|
@ -276,7 +280,7 @@ pub mod console {
|
|||
pub emerg_wr: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_console_control {
|
||||
pub id: Le32,
|
||||
|
|
@ -284,7 +288,7 @@ pub mod console {
|
|||
pub value: Le16,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_console_resize {
|
||||
pub cols: Le16,
|
||||
|
|
|
|||
|
|
@ -4,16 +4,17 @@
|
|||
|
||||
//! Data structures and logic for virtio-fs IOCTLs specific to ARCVM.
|
||||
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
pub const FS_IOCTL_PATH_MAX_LEN: usize = 128;
|
||||
pub const FS_IOCTL_XATTR_NAME_MAX_LEN: usize = 128;
|
||||
pub const FS_IOCTL_XATTR_VALUE_MAX_LEN: usize = 128;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub(crate) struct FsPermissionDataBuffer {
|
||||
pub guest_uid: u32,
|
||||
pub guest_gid: u32,
|
||||
|
|
@ -37,7 +38,7 @@ impl XattrData {
|
|||
}
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub(crate) struct FsPathXattrDataBuffer {
|
||||
pub path: [u8; FS_IOCTL_PATH_MAX_LEN],
|
||||
pub xattr_name: [u8; FS_IOCTL_XATTR_NAME_MAX_LEN],
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use virtio_sys::virtio_fs::VIRTIO_FS_SHMCAP_ID_CACHE;
|
|||
use vm_control::FsMappingRequest;
|
||||
use vm_control::VmResponse;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::pci::PciAddress;
|
||||
use crate::pci::PciBarConfiguration;
|
||||
|
|
|
|||
|
|
@ -76,9 +76,11 @@ use system_api::client::OrgChromiumSpaced;
|
|||
use system_api::spaced::SetProjectIdReply;
|
||||
#[cfg(feature = "arc_quota")]
|
||||
use system_api::spaced::SetProjectInheritanceFlagReply;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::FromZeros;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
#[cfg(feature = "arc_quota")]
|
||||
use crate::virtio::fs::arc_ioctl::FsPathXattrDataBuffer;
|
||||
|
|
@ -124,7 +126,7 @@ macro_rules! fs_trace {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct fscrypt_policy_v1 {
|
||||
_version: u8,
|
||||
_contents_encryption_mode: u8,
|
||||
|
|
@ -134,7 +136,7 @@ struct fscrypt_policy_v1 {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct fscrypt_policy_v2 {
|
||||
_version: u8,
|
||||
_contents_encryption_mode: u8,
|
||||
|
|
@ -145,7 +147,7 @@ struct fscrypt_policy_v2 {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, KnownLayout)]
|
||||
union fscrypt_policy {
|
||||
_version: u8,
|
||||
_v1: fscrypt_policy_v1,
|
||||
|
|
@ -153,7 +155,7 @@ union fscrypt_policy {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, KnownLayout)]
|
||||
struct fscrypt_get_policy_ex_arg {
|
||||
policy_size: u64, /* input/output */
|
||||
policy: fscrypt_policy, /* output */
|
||||
|
|
@ -176,7 +178,7 @@ impl From<&fscrypt_get_policy_ex_arg> for &[u8] {
|
|||
ioctl_iowr_nr!(FS_IOC_GET_ENCRYPTION_POLICY_EX, 'f' as u32, 22, [u8; 9]);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct fsxattr {
|
||||
fsx_xflags: u32, /* xflags field value (get/set) */
|
||||
fsx_extsize: u32, /* extsize field value (get/set) */
|
||||
|
|
@ -204,7 +206,7 @@ ioctl_iow_nr!(FS_IOC_SETPERMISSION, 'f' as u32, 1, FsPermissionDataBuffer);
|
|||
ioctl_iow_nr!(FS_IOC_SETPATHXATTR, 'f' as u32, 1, FsPathXattrDataBuffer);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct fsverity_enable_arg {
|
||||
_version: u32,
|
||||
_hash_algorithm: u32,
|
||||
|
|
@ -218,7 +220,7 @@ struct fsverity_enable_arg {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct fsverity_digest {
|
||||
_digest_algorithm: u16,
|
||||
digest_size: u16,
|
||||
|
|
@ -1358,7 +1360,7 @@ impl PassthroughFs {
|
|||
|
||||
// SAFETY: this struct only has integer fields and any value is valid.
|
||||
let mut arg = unsafe { MaybeUninit::<fscrypt_get_policy_ex_arg>::zeroed().assume_init() };
|
||||
r.read_exact(arg.policy_size.as_bytes_mut())?;
|
||||
r.read_exact(arg.policy_size.as_mut_bytes())?;
|
||||
|
||||
let policy_size = cmp::min(arg.policy_size, size_of::<fscrypt_policy>() as u64);
|
||||
arg.policy_size = policy_size;
|
||||
|
|
@ -1408,7 +1410,7 @@ impl PassthroughFs {
|
|||
};
|
||||
|
||||
let mut in_attr = fsxattr::new_zeroed();
|
||||
r.read_exact(in_attr.as_bytes_mut())?;
|
||||
r.read_exact(in_attr.as_mut_bytes())?;
|
||||
|
||||
#[cfg(feature = "arc_quota")]
|
||||
let st = stat(&*data)?;
|
||||
|
|
@ -1501,7 +1503,7 @@ impl PassthroughFs {
|
|||
|
||||
// The ioctl encoding is a long but the parameter is actually an int.
|
||||
let mut in_flags: c_int = 0;
|
||||
r.read_exact(in_flags.as_bytes_mut())?;
|
||||
r.read_exact(in_flags.as_mut_bytes())?;
|
||||
|
||||
#[cfg(feature = "arc_quota")]
|
||||
let st = stat(&*data)?;
|
||||
|
|
@ -1619,7 +1621,7 @@ impl PassthroughFs {
|
|||
};
|
||||
|
||||
let mut arg = fsverity_enable_arg::new_zeroed();
|
||||
r.read_exact(arg.as_bytes_mut())?;
|
||||
r.read_exact(arg.as_mut_bytes())?;
|
||||
|
||||
let mut salt;
|
||||
if arg.salt_size > 0 {
|
||||
|
|
@ -1672,7 +1674,7 @@ impl PassthroughFs {
|
|||
};
|
||||
|
||||
let mut digest = fsverity_digest::new_zeroed();
|
||||
r.read_exact(digest.as_bytes_mut())?;
|
||||
r.read_exact(digest.as_mut_bytes())?;
|
||||
|
||||
// Taken from fs/verity/fsverity_private.h.
|
||||
const FS_VERITY_MAX_DIGEST_SIZE: u16 = 64;
|
||||
|
|
@ -1877,7 +1879,7 @@ impl PassthroughFs {
|
|||
|
||||
fn read_permission_data<R: io::Read>(&self, mut r: R) -> io::Result<PermissionData> {
|
||||
let mut fs_permission_data = FsPermissionDataBuffer::new_zeroed();
|
||||
r.read_exact(fs_permission_data.as_bytes_mut())?;
|
||||
r.read_exact(fs_permission_data.as_mut_bytes())?;
|
||||
|
||||
let perm_path = self.string_from_u8_slice(&fs_permission_data.perm_path)?;
|
||||
if !perm_path.starts_with('/') {
|
||||
|
|
@ -1964,7 +1966,7 @@ impl PassthroughFs {
|
|||
|
||||
fn read_xattr_data<R: io::Read>(&self, mut r: R) -> io::Result<XattrData> {
|
||||
let mut fs_path_xattr_data = FsPathXattrDataBuffer::new_zeroed();
|
||||
r.read_exact(fs_path_xattr_data.as_bytes_mut())?;
|
||||
r.read_exact(fs_path_xattr_data.as_mut_bytes())?;
|
||||
|
||||
let xattr_path = self.string_from_u8_slice(&fs_path_xattr_data.path)?;
|
||||
if !xattr_path.starts_with('/') {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,13 @@ use std::ops::DerefMut;
|
|||
use base::AsRawDescriptor;
|
||||
use fuse::filesystem::DirEntry;
|
||||
use fuse::filesystem::DirectoryIterator;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct LinuxDirent64 {
|
||||
d_ino: libc::ino64_t,
|
||||
d_off: libc::off64_t,
|
||||
|
|
@ -76,17 +77,8 @@ impl<P: Deref<Target = [u8]>> DirectoryIterator for ReadDir<P> {
|
|||
return None;
|
||||
}
|
||||
|
||||
// We only use debug asserts here because these values are coming from the kernel and we
|
||||
// trust them implicitly.
|
||||
debug_assert!(
|
||||
rem.len() >= size_of::<LinuxDirent64>(),
|
||||
"not enough space left in `rem`"
|
||||
);
|
||||
|
||||
let (front, back) = rem.split_at(size_of::<LinuxDirent64>());
|
||||
|
||||
let dirent64 =
|
||||
LinuxDirent64::read_from(front).expect("unable to get LinuxDirent64 from slice");
|
||||
let (dirent64, back) =
|
||||
LinuxDirent64::read_from_prefix(rem).expect("unable to get LinuxDirent64 from slice");
|
||||
|
||||
let namelen = dirent64.d_reclen as usize - size_of::<LinuxDirent64>();
|
||||
debug_assert!(namelen <= back.len(), "back is smaller than `namelen`");
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ pub use vm_control::gpu::DEFAULT_REFRESH_RATE;
|
|||
use vm_control::ModifyWaitContext;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
pub use self::protocol::virtio_gpu_config;
|
||||
pub use self::protocol::VIRTIO_GPU_F_CONTEXT_INIT;
|
||||
|
|
@ -1842,7 +1842,7 @@ impl VirtioDevice for Gpu {
|
|||
|
||||
fn write_config(&mut self, offset: u64, data: &[u8]) {
|
||||
let mut cfg = self.get_config();
|
||||
copy_config(cfg.as_bytes_mut(), offset, data, 0);
|
||||
copy_config(cfg.as_mut_bytes(), offset, data, 0);
|
||||
if (cfg.events_clear.to_native() & VIRTIO_GPU_EVENT_DISPLAY) != 0 {
|
||||
self.display_event.store(false, Ordering::Relaxed);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,10 @@ use remain::sorted;
|
|||
use rutabaga_gfx::RutabagaError;
|
||||
use thiserror::Error;
|
||||
use vm_memory::udmabuf::UdmabufError;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
pub use super::super::device_constants::gpu::virtio_gpu_config;
|
||||
pub use super::super::device_constants::gpu::VIRTIO_GPU_F_CONTEXT_INIT;
|
||||
|
|
@ -157,7 +158,7 @@ pub const VIRTIO_GPU_FLAG_FENCE: u32 = 1 << 0;
|
|||
pub const VIRTIO_GPU_FLAG_INFO_RING_IDX: u32 = 1 << 1;
|
||||
pub const VIRTIO_GPU_FLAG_FENCE_HOST_SHAREABLE: u32 = 1 << 2;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_ctrl_hdr {
|
||||
pub type_: Le32,
|
||||
|
|
@ -170,7 +171,7 @@ pub struct virtio_gpu_ctrl_hdr {
|
|||
|
||||
/* data passed in the cursor vq */
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_cursor_pos {
|
||||
pub scanout_id: Le32,
|
||||
|
|
@ -180,7 +181,7 @@ pub struct virtio_gpu_cursor_pos {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_UPDATE_CURSOR, VIRTIO_GPU_CMD_MOVE_CURSOR */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_update_cursor {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -193,7 +194,7 @@ pub struct virtio_gpu_update_cursor {
|
|||
|
||||
/* data passed in the control vq, 2d related */
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_rect {
|
||||
pub x: Le32,
|
||||
|
|
@ -203,7 +204,7 @@ pub struct virtio_gpu_rect {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_RESOURCE_UNREF */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_unref {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -212,7 +213,7 @@ pub struct virtio_gpu_resource_unref {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: create a 2d resource with a format */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_create_2d {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -223,7 +224,7 @@ pub struct virtio_gpu_resource_create_2d {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_SET_SCANOUT */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_set_scanout {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -233,7 +234,7 @@ pub struct virtio_gpu_set_scanout {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_RESOURCE_FLUSH */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_flush {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -243,7 +244,7 @@ pub struct virtio_gpu_resource_flush {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: simple transfer to_host */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_transfer_to_host_2d {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -253,7 +254,7 @@ pub struct virtio_gpu_transfer_to_host_2d {
|
|||
pub padding: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_mem_entry {
|
||||
pub addr: Le64,
|
||||
|
|
@ -262,7 +263,7 @@ pub struct virtio_gpu_mem_entry {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_attach_backing {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -271,7 +272,7 @@ pub struct virtio_gpu_resource_attach_backing {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_detach_backing {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -279,7 +280,7 @@ pub struct virtio_gpu_resource_detach_backing {
|
|||
pub padding: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_display_one {
|
||||
pub r: virtio_gpu_rect,
|
||||
|
|
@ -289,7 +290,7 @@ pub struct virtio_gpu_display_one {
|
|||
|
||||
/* VIRTIO_GPU_RESP_OK_DISPLAY_INFO */
|
||||
pub const VIRTIO_GPU_MAX_SCANOUTS: usize = 16;
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resp_display_info {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -298,7 +299,7 @@ pub struct virtio_gpu_resp_display_info {
|
|||
|
||||
/* data passed in the control vq, 3d related */
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_box {
|
||||
pub x: Le32,
|
||||
|
|
@ -310,7 +311,7 @@ pub struct virtio_gpu_box {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_transfer_host_3d {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -324,7 +325,7 @@ pub struct virtio_gpu_transfer_host_3d {
|
|||
|
||||
/* VIRTIO_GPU_CMD_RESOURCE_CREATE_3D */
|
||||
pub const VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP: u32 = 1 << 0;
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_create_3d {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -344,7 +345,7 @@ pub struct virtio_gpu_resource_create_3d {
|
|||
|
||||
/* VIRTIO_GPU_CMD_CTX_CREATE */
|
||||
pub const VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK: u32 = 1 << 0;
|
||||
#[derive(Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_ctx_create {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -378,14 +379,14 @@ impl fmt::Debug for virtio_gpu_ctx_create {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_CTX_DESTROY */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_ctx_destroy {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE, VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_ctx_resource {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -394,7 +395,7 @@ pub struct virtio_gpu_ctx_resource {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_SUBMIT_3D */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_cmd_submit {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -422,7 +423,7 @@ pub const VIRTIO_GPU_CAPSET_VENUS: u32 = 4;
|
|||
pub const VIRTIO_GPU_CAPSET_CROSS_DOMAIN: u32 = 5;
|
||||
|
||||
/* VIRTIO_GPU_CMD_GET_CAPSET_INFO */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_get_capset_info {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -431,7 +432,7 @@ pub struct virtio_gpu_get_capset_info {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_RESP_OK_CAPSET_INFO */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resp_capset_info {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -442,7 +443,7 @@ pub struct virtio_gpu_resp_capset_info {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_GET_CAPSET */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_get_capset {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -459,7 +460,7 @@ pub struct virtio_gpu_resp_capset {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_GET_EDID */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_get_edid {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -468,7 +469,7 @@ pub struct virtio_gpu_get_edid {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_RESP_OK_EDID */
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resp_get_edid {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -478,7 +479,7 @@ pub struct virtio_gpu_resp_get_edid {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_RESP_OK_RESOURCE_PLANE_INFO */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resp_resource_plane_info {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -493,7 +494,7 @@ pub const PLANE_INFO_MAX_COUNT: usize = 4;
|
|||
|
||||
pub const VIRTIO_GPU_EVENT_DISPLAY: u32 = 1 << 0;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_create_blob {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -505,7 +506,7 @@ pub struct virtio_gpu_resource_create_blob {
|
|||
pub size: Le64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_map_blob {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -514,7 +515,7 @@ pub struct virtio_gpu_resource_map_blob {
|
|||
pub offset: Le64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_unmap_blob {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -522,7 +523,7 @@ pub struct virtio_gpu_resource_unmap_blob {
|
|||
pub padding: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resp_map_info {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -530,7 +531,7 @@ pub struct virtio_gpu_resp_map_info {
|
|||
pub padding: u32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resource_assign_uuid {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -538,7 +539,7 @@ pub struct virtio_gpu_resource_assign_uuid {
|
|||
pub padding: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_resp_resource_uuid {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
@ -546,7 +547,7 @@ pub struct virtio_gpu_resp_resource_uuid {
|
|||
}
|
||||
|
||||
/* VIRTIO_GPU_CMD_SET_SCANOUT_BLOB */
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_gpu_set_scanout_blob {
|
||||
pub hdr: virtio_gpu_ctrl_hdr,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use linux_input_sys::constants::*;
|
|||
use linux_input_sys::input_event;
|
||||
use linux_input_sys::virtio_input_event;
|
||||
use linux_input_sys::InputEventDecoder;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::evdev::grab_evdev;
|
||||
use super::evdev::ungrab_evdev;
|
||||
|
|
@ -253,7 +253,7 @@ mod tests {
|
|||
use data_model::Le16;
|
||||
use data_model::SLe32;
|
||||
use linux_input_sys::InputEventDecoder;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::input::event_source::input_event;
|
||||
use crate::virtio::input::event_source::virtio_input_event;
|
||||
|
|
|
|||
|
|
@ -38,9 +38,10 @@ use serde::Serialize;
|
|||
use snapshot::AnySnapshot;
|
||||
use thiserror::Error;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use self::event_source::EvdevEventSource;
|
||||
use self::event_source::EventSource;
|
||||
|
|
@ -105,7 +106,18 @@ pub enum InputError {
|
|||
|
||||
pub type Result<T> = std::result::Result<T, InputError>;
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, AsBytes, FromZeroes, FromBytes, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
Debug,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_input_device_ids {
|
||||
bustype: Le16,
|
||||
|
|
@ -126,7 +138,17 @@ impl virtio_input_device_ids {
|
|||
}
|
||||
|
||||
#[derive(
|
||||
Copy, Clone, Default, Debug, AsBytes, FromZeroes, FromBytes, PartialEq, Serialize, Deserialize,
|
||||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
Debug,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
PartialEq,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_input_absinfo {
|
||||
|
|
@ -147,7 +169,7 @@ impl virtio_input_absinfo {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct virtio_input_config {
|
||||
select: u8,
|
||||
|
|
@ -352,7 +374,7 @@ impl VirtioInputConfig {
|
|||
|
||||
fn write(&mut self, offset: usize, data: &[u8]) {
|
||||
let mut config = self.build_config_memory();
|
||||
copy_config(config.as_bytes_mut(), offset as u64, data, 0);
|
||||
copy_config(config.as_mut_bytes(), offset as u64, data, 0);
|
||||
self.select = config.select;
|
||||
self.subsel = config.subsel;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,11 +52,13 @@ use vm_control::VmMemoryRegionId;
|
|||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use vm_memory::GuestMemoryError;
|
||||
use zerocopy::AsBytes;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use zerocopy::FromBytes;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use crate::pci::PciAddress;
|
||||
|
|
@ -86,7 +88,7 @@ const VIRTIO_IOMMU_VIOT_NODE_PCI_RANGE: u8 = 1;
|
|||
#[cfg(target_arch = "x86_64")]
|
||||
const VIRTIO_IOMMU_VIOT_NODE_VIRTIO_IOMMU_PCI: u8 = 3;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C, packed)]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
struct VirtioIommuViotHeader {
|
||||
|
|
@ -95,7 +97,7 @@ struct VirtioIommuViotHeader {
|
|||
reserved: [u8; 8],
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C, packed)]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
struct VirtioIommuViotVirtioPciNode {
|
||||
|
|
@ -107,7 +109,7 @@ struct VirtioIommuViotVirtioPciNode {
|
|||
reserved2: [u8; 8],
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C, packed)]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
struct VirtioIommuViotPciRangeNode {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@ use smallvec::SmallVec;
|
|||
use sync::Mutex;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeros;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::memory_mapper::MemRegion;
|
||||
|
||||
|
|
@ -277,13 +279,13 @@ impl ExportedRegion {
|
|||
|
||||
/// Reads an object from the given iova. Fails if the specified iova range does
|
||||
/// not lie within this region, or if part of the region isn't readable.
|
||||
pub fn read_obj_from_addr<T: AsBytes + FromBytes>(
|
||||
pub fn read_obj_from_addr<T: IntoBytes + FromBytes + FromZeros>(
|
||||
&self,
|
||||
mem: &GuestMemory,
|
||||
iova: u64,
|
||||
) -> anyhow::Result<T> {
|
||||
let mut val = T::new_zeroed();
|
||||
let buf = val.as_bytes_mut();
|
||||
let buf = val.as_mut_bytes();
|
||||
self.do_copy(iova, buf.len(), Protection::read(), |offset, gpa, len| {
|
||||
mem.read_at_addr(&mut buf[offset..(offset + len)], gpa)
|
||||
.context("failed to read from gpa")
|
||||
|
|
@ -293,7 +295,7 @@ impl ExportedRegion {
|
|||
|
||||
/// Writes an object at a given iova. Fails if the specified iova range does
|
||||
/// not lie within this region, or if part of the region isn't writable.
|
||||
pub fn write_obj_at_addr<T: AsBytes>(
|
||||
pub fn write_obj_at_addr<T: Immutable + IntoBytes>(
|
||||
&self,
|
||||
mem: &GuestMemory,
|
||||
val: T,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
//! The main points of the manual modifications are as follows:
|
||||
//! * Removed `head` and `tail` from each command struct. Instead, we process
|
||||
//! them as separate payloads.
|
||||
//! * Derive implementations of zerocopy::{AsBytes, FromZeroes, FromBytes} as needed.
|
||||
//! * Derive implementations of zerocopy traits as needed.
|
||||
//! * Use of `packed` because removing `head` and `tail` introduces paddings
|
||||
//! * Remove `IncompleteArrayField`
|
||||
//! * Convert padding of [u8; 64usize] to [u64; 8usize]. According to the rust
|
||||
|
|
@ -30,9 +30,10 @@
|
|||
use data_model::Le16;
|
||||
use data_model::Le32;
|
||||
use data_model::Le64;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
pub const VIRTIO_IOMMU_F_INPUT_RANGE: u32 = 0;
|
||||
pub const VIRTIO_IOMMU_F_DOMAIN_RANGE: u32 = 1;
|
||||
|
|
@ -72,21 +73,21 @@ pub const VIRTIO_IOMMU_FAULT_F_EXEC: u32 = 4;
|
|||
pub const VIRTIO_IOMMU_FAULT_F_ADDRESS: u32 = 256;
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_range_64 {
|
||||
pub start: Le64,
|
||||
pub end: Le64,
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_range_32 {
|
||||
pub start: Le32,
|
||||
pub end: Le32,
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_config {
|
||||
pub page_size_mask: Le64,
|
||||
pub input_range: virtio_iommu_range_64,
|
||||
|
|
@ -95,21 +96,21 @@ pub struct virtio_iommu_config {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_req_head {
|
||||
pub type_: u8,
|
||||
pub reserved: [u8; 3usize],
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_req_tail {
|
||||
pub status: u8,
|
||||
pub reserved: [u8; 3usize],
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_req_attach {
|
||||
pub domain: Le32,
|
||||
pub endpoint: Le32,
|
||||
|
|
@ -117,7 +118,7 @@ pub struct virtio_iommu_req_attach {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_req_detach {
|
||||
pub domain: Le32,
|
||||
pub endpoint: Le32,
|
||||
|
|
@ -125,7 +126,7 @@ pub struct virtio_iommu_req_detach {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_req_map {
|
||||
pub domain: Le32,
|
||||
pub virt_start: Le64,
|
||||
|
|
@ -135,7 +136,7 @@ pub struct virtio_iommu_req_map {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_req_unmap {
|
||||
pub domain: Le32,
|
||||
pub virt_start: Le64,
|
||||
|
|
@ -144,14 +145,14 @@ pub struct virtio_iommu_req_unmap {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_probe_property {
|
||||
pub type_: Le16,
|
||||
pub length: Le16,
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_probe_resv_mem {
|
||||
pub head: virtio_iommu_probe_property,
|
||||
pub subtype: u8,
|
||||
|
|
@ -161,7 +162,7 @@ pub struct virtio_iommu_probe_resv_mem {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_iommu_req_probe {
|
||||
pub endpoint: Le32,
|
||||
pub reserved: [u64; 8usize],
|
||||
|
|
|
|||
|
|
@ -45,9 +45,10 @@ use virtio_sys::virtio_net::VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET;
|
|||
use virtio_sys::virtio_net::VIRTIO_NET_ERR;
|
||||
use virtio_sys::virtio_net::VIRTIO_NET_OK;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::copy_config;
|
||||
use super::DeviceType;
|
||||
|
|
@ -218,13 +219,13 @@ impl FromStr for NetParameters {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_net_ctrl_hdr {
|
||||
pub class: u8,
|
||||
pub cmd: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Clone, Copy, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct VirtioNetConfig {
|
||||
mac: [u8; 6],
|
||||
|
|
|
|||
|
|
@ -37,9 +37,10 @@ use vm_control::VmMemoryMappingRequest;
|
|||
use vm_control::VmMemoryMappingResponse;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::async_utils;
|
||||
use super::copy_config;
|
||||
|
|
@ -60,26 +61,26 @@ const VIRTIO_PMEM_REQ_TYPE_DISCARD: u32 = u32::MAX;
|
|||
const VIRTIO_PMEM_RESP_TYPE_OK: u32 = 0;
|
||||
const VIRTIO_PMEM_RESP_TYPE_EIO: u32 = 1;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct virtio_pmem_config {
|
||||
start_address: Le64,
|
||||
size: Le64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct virtio_pmem_resp {
|
||||
status_code: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct virtio_pmem_req {
|
||||
type_: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct virtio_pmem_range_req {
|
||||
type_: Le32,
|
||||
|
|
|
|||
|
|
@ -83,9 +83,10 @@ use vm_control::PvClockCommandResponse;
|
|||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use vm_memory::GuestMemoryError;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::copy_config;
|
||||
use super::DeviceType;
|
||||
|
|
@ -187,7 +188,7 @@ fn freq_scale_shift(scaled_hz: u64, base_hz: u64) -> (u32, i8) {
|
|||
|
||||
// The config structure being exposed to the guest to tell them how much suspend time should be
|
||||
// injected to the guest's CLOCK_BOOTTIME.
|
||||
#[derive(Debug, Clone, Copy, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Clone, Copy, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(C)]
|
||||
struct virtio_pvclock_config {
|
||||
|
|
@ -199,7 +200,7 @@ struct virtio_pvclock_config {
|
|||
padding: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Debug, Clone, Copy, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(C)]
|
||||
struct virtio_pvclock_set_pvclock_page_req {
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@ use data_model::Le32;
|
|||
use data_model::Le64;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::virtio::descriptor_chain::Descriptor;
|
||||
use crate::virtio::descriptor_chain::DescriptorAccess;
|
||||
|
|
@ -38,7 +39,7 @@ pub const RING_EVENT_FLAGS_DISABLE: u16 = 0x1;
|
|||
pub const RING_EVENT_FLAGS_DESC: u16 = 0x2;
|
||||
|
||||
/// A packed virtio packed queue descriptor (`struct pvirtq_desc` in the spec).
|
||||
#[derive(Copy, Clone, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct PackedDesc {
|
||||
/// Guest address of memory buffer address
|
||||
|
|
@ -83,7 +84,7 @@ impl PackedDesc {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct PackedDescEvent {
|
||||
pub desc: Le16,
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@ use data_model::Le32;
|
|||
use data_model::Le64;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::virtio::descriptor_chain::Descriptor;
|
||||
use crate::virtio::descriptor_chain::DescriptorAccess;
|
||||
|
|
@ -26,7 +27,7 @@ use crate::virtio::descriptor_chain::VIRTQ_DESC_F_NEXT;
|
|||
use crate::virtio::descriptor_chain::VIRTQ_DESC_F_WRITE;
|
||||
|
||||
/// A single virtio split queue descriptor (`struct virtq_desc` in the spec).
|
||||
#[derive(Copy, Clone, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct Desc {
|
||||
/// Guest address of memory described by this descriptor.
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@ use snapshot::AnySnapshot;
|
|||
use virtio_sys::virtio_ring::VIRTIO_RING_F_EVENT_IDX;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::virtio::DescriptorChain;
|
||||
use crate::virtio::Interrupt;
|
||||
|
|
@ -78,7 +79,7 @@ pub struct SplitQueueSnapshot {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct virtq_used_elem {
|
||||
id: Le32,
|
||||
len: Le32,
|
||||
|
|
@ -572,8 +573,10 @@ mod tests {
|
|||
use data_model::Le16;
|
||||
use data_model::Le32;
|
||||
use data_model::Le64;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::*;
|
||||
use crate::virtio::create_descriptor_chain;
|
||||
|
|
@ -589,7 +592,7 @@ mod tests {
|
|||
const BUFFER_OFFSET: u64 = 0x8000;
|
||||
const BUFFER_LEN: u32 = 0x400;
|
||||
|
||||
#[derive(Copy, Clone, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct Avail {
|
||||
flags: Le16,
|
||||
|
|
@ -609,7 +612,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
struct UsedElem {
|
||||
id: Le32,
|
||||
|
|
@ -625,7 +628,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C, packed)]
|
||||
struct Used {
|
||||
flags: Le16,
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ use base::warn;
|
|||
use data_model::Be16;
|
||||
use data_model::Be32;
|
||||
use data_model::Be64;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::virtio::scsi::constants::INQUIRY;
|
||||
use crate::virtio::scsi::constants::MAINTENANCE_IN;
|
||||
|
|
@ -83,7 +84,8 @@ impl Command {
|
|||
}
|
||||
|
||||
fn parse_command<T: FromBytes>(cdb: &[u8]) -> Result<T, ExecuteError> {
|
||||
T::read_from_prefix(cdb).ok_or(ExecuteError::ReadCommand)
|
||||
let (command, _) = T::read_from_prefix(cdb).map_err(|_| ExecuteError::ReadCommand)?;
|
||||
Ok(command)
|
||||
}
|
||||
|
||||
fn parse_maintenance_in(cdb: &[u8]) -> Result<Self, ExecuteError> {
|
||||
|
|
@ -148,7 +150,9 @@ impl Command {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct TestUnitReady {
|
||||
opcode: u8,
|
||||
|
|
@ -189,7 +193,9 @@ async fn read_from_disk(
|
|||
})
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct Read6 {
|
||||
opcode: u8,
|
||||
|
|
@ -230,7 +236,9 @@ impl Read6 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct Inquiry {
|
||||
opcode: u8,
|
||||
|
|
@ -433,7 +441,9 @@ fn fill_mode_page(
|
|||
|
||||
// According to the spec, devices that implement MODE SENSE(6) shall also implement MODE SELECT(6)
|
||||
// as well.
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct ModeSelect6 {
|
||||
opcode: u8,
|
||||
|
|
@ -450,7 +460,9 @@ impl ModeSelect6 {
|
|||
}
|
||||
|
||||
fn emulate(&self, reader: &mut Reader, dev: &AsyncLogicalUnit) -> Result<(), ExecuteError> {
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
struct BlockDescriptor {
|
||||
_density: u8,
|
||||
|
|
@ -502,14 +514,18 @@ impl ModeSelect6 {
|
|||
}
|
||||
|
||||
fn handle_mode_page(reader: &mut Reader) -> Result<(), ExecuteError> {
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
struct Page0Header {
|
||||
page_code: u8,
|
||||
page_len: u8,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
struct SubpageHeader {
|
||||
page_code: u8,
|
||||
|
|
@ -546,7 +562,9 @@ impl ModeSelect6 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct ModeSense6 {
|
||||
opcode: u8,
|
||||
|
|
@ -695,7 +713,9 @@ impl ModeSense6 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct ReadCapacity10 {
|
||||
opcode: u8,
|
||||
|
|
@ -718,7 +738,9 @@ impl ReadCapacity10 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct ReadCapacity16 {
|
||||
opcode: u8,
|
||||
|
|
@ -743,7 +765,9 @@ impl ReadCapacity16 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct Read10 {
|
||||
opcode: u8,
|
||||
|
|
@ -775,7 +799,9 @@ impl Read10 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct Write10 {
|
||||
opcode: u8,
|
||||
|
|
@ -830,7 +856,9 @@ async fn write_to_disk(
|
|||
})
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct SynchronizeCache10 {
|
||||
opcode: u8,
|
||||
|
|
@ -887,7 +915,9 @@ async fn write_same(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct WriteSame10 {
|
||||
opcode: u8,
|
||||
|
|
@ -942,7 +972,9 @@ impl WriteSame10 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct Unmap {
|
||||
opcode: u8,
|
||||
|
|
@ -1008,7 +1040,9 @@ impl Unmap {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct WriteSame16 {
|
||||
opcode: u8,
|
||||
|
|
@ -1060,7 +1094,9 @@ impl WriteSame16 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct ReportLuns {
|
||||
opcode: u8,
|
||||
|
|
@ -1097,7 +1133,9 @@ impl ReportLuns {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq,
|
||||
)]
|
||||
#[repr(C, packed)]
|
||||
pub struct ReportSupportedTMFs {
|
||||
opcode: u8,
|
||||
|
|
|
|||
|
|
@ -49,9 +49,10 @@ use virtio_sys::virtio_scsi::VIRTIO_SCSI_T_TMF;
|
|||
use virtio_sys::virtio_scsi::VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET;
|
||||
use virtio_sys::virtio_scsi::VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::virtio::async_utils;
|
||||
use crate::virtio::block::sys::get_seg_max;
|
||||
|
|
@ -98,7 +99,7 @@ const MAX_SECTORS: u32 = u32::MAX;
|
|||
const FIXED_FORMAT_SENSE_SIZE: u32 = 18;
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct VirtioScsiCmdReqHeader {
|
||||
lun: [u8; 8usize],
|
||||
tag: u64,
|
||||
|
|
@ -108,7 +109,7 @@ struct VirtioScsiCmdReqHeader {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct VirtioScsiCmdRespHeader {
|
||||
sense_len: u32,
|
||||
resid: u32,
|
||||
|
|
@ -612,7 +613,7 @@ impl VirtioDevice for Controller {
|
|||
|
||||
fn write_config(&mut self, offset: u64, data: &[u8]) {
|
||||
let mut config = self.build_config_space();
|
||||
copy_config(config.as_bytes_mut(), offset, data, 0);
|
||||
copy_config(config.as_mut_bytes(), offset, data, 0);
|
||||
// Only `sense_size` and `cdb_size` are modifiable by the driver.
|
||||
self.sense_size = config.sense_size;
|
||||
self.cdb_size = config.cdb_size;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ use futures::StreamExt;
|
|||
use thiserror::Error as ThisError;
|
||||
use vm_control::SndControlCommand;
|
||||
use vm_control::VmResponse;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::Error;
|
||||
use super::SndData;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ use serde::Serialize;
|
|||
use snapshot::AnySnapshot;
|
||||
use thiserror::Error as ThisError;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::async_utils;
|
||||
use crate::virtio::copy_config;
|
||||
|
|
|
|||
|
|
@ -6,34 +6,37 @@ use data_model::Le32;
|
|||
use data_model::Le64;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::virtio::snd::constants::StatusCode;
|
||||
use crate::virtio::snd::constants::VIRTIO_SND_CHMAP_MAX_SIZE;
|
||||
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize, Deserialize,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_hdr {
|
||||
pub code: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_jack_hdr {
|
||||
pub hdr: virtio_snd_hdr,
|
||||
pub jack_id: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_event {
|
||||
pub hdr: virtio_snd_hdr,
|
||||
pub data: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_query_info {
|
||||
pub hdr: virtio_snd_hdr,
|
||||
|
|
@ -46,9 +49,10 @@ pub struct virtio_snd_query_info {
|
|||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
AsBytes,
|
||||
FromZeroes,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
PartialEq,
|
||||
|
|
@ -64,9 +68,10 @@ pub struct virtio_snd_info {
|
|||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
AsBytes,
|
||||
FromZeroes,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
PartialEq,
|
||||
|
|
@ -86,14 +91,18 @@ pub struct virtio_snd_pcm_info {
|
|||
pub padding: [u8; 5],
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize, Deserialize,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_pcm_hdr {
|
||||
pub hdr: virtio_snd_hdr,
|
||||
pub stream_id: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize, Deserialize,
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_pcm_set_params {
|
||||
pub hdr: virtio_snd_pcm_hdr,
|
||||
|
|
@ -106,13 +115,13 @@ pub struct virtio_snd_pcm_set_params {
|
|||
pub padding: u8,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_pcm_xfer {
|
||||
pub stream_id: Le32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_pcm_status {
|
||||
pub status: Le32,
|
||||
|
|
@ -132,9 +141,10 @@ impl virtio_snd_pcm_status {
|
|||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
AsBytes,
|
||||
FromZeroes,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
PartialEq,
|
||||
|
|
@ -151,7 +161,7 @@ pub struct virtio_snd_jack_info {
|
|||
pub padding: [u8; 7],
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_snd_jack_remap {
|
||||
pub hdr: virtio_snd_jack_hdr, /* .code = VIRTIO_SND_R_JACK_REMAP */
|
||||
|
|
@ -163,9 +173,10 @@ pub struct virtio_snd_jack_remap {
|
|||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
AsBytes,
|
||||
FromZeroes,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
PartialEq,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ use sync::Mutex;
|
|||
use thiserror::Error as ThisError;
|
||||
use vm_memory::GuestMemory;
|
||||
use worker::*;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::copy_config;
|
||||
use crate::virtio::device_constants::snd::virtio_snd_config;
|
||||
|
|
|
|||
|
|
@ -41,9 +41,10 @@ use serde::Deserialize;
|
|||
use serde::Serialize;
|
||||
use sync::Mutex;
|
||||
use thiserror::Error as ThisError;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::virtio::snd::constants::*;
|
||||
use crate::virtio::snd::layout::*;
|
||||
|
|
@ -175,7 +176,7 @@ impl VioSClient {
|
|||
let mut config: VioSConfig = Default::default();
|
||||
const NUM_FDS: usize = 5;
|
||||
let (recv_size, mut safe_fds) = client_socket
|
||||
.recv_with_fds(config.as_bytes_mut(), NUM_FDS)
|
||||
.recv_with_fds(config.as_mut_bytes(), NUM_FDS)
|
||||
.map_err(Error::ServerError)?;
|
||||
|
||||
if recv_size != std::mem::size_of::<VioSConfig>() {
|
||||
|
|
@ -499,7 +500,7 @@ impl VioSClient {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn request_info<T: AsBytes + FromBytes + Default + Copy + Clone>(
|
||||
fn request_info<T: IntoBytes + FromBytes + Default + Copy + Clone>(
|
||||
&self,
|
||||
req_code: u32,
|
||||
count: usize,
|
||||
|
|
@ -515,13 +516,13 @@ impl VioSClient {
|
|||
size: (std::mem::size_of::<virtio_snd_query_info>() as u32).into(),
|
||||
};
|
||||
let control_socket_lock = self.control_socket.lock();
|
||||
seq_socket_send(&control_socket_lock, req)?;
|
||||
seq_socket_send(&control_socket_lock, req.as_bytes())?;
|
||||
let reply = control_socket_lock
|
||||
.recv_as_vec()
|
||||
.map_err(Error::ServerIOError)?;
|
||||
let mut status: virtio_snd_hdr = Default::default();
|
||||
status
|
||||
.as_bytes_mut()
|
||||
.as_mut_bytes()
|
||||
.copy_from_slice(&reply[0..status_size]);
|
||||
if status.code.to_native() != VIRTIO_SND_S_OK {
|
||||
return Err(Error::CommandFailed(status.code.to_native()));
|
||||
|
|
@ -533,7 +534,7 @@ impl VioSClient {
|
|||
}
|
||||
Ok(reply[status_size..]
|
||||
.chunks(info_size)
|
||||
.map(|info_buffer| T::read_from(info_buffer).unwrap())
|
||||
.map(|info_buffer| T::read_from_bytes(info_buffer).unwrap())
|
||||
.collect())
|
||||
}
|
||||
|
||||
|
|
@ -630,7 +631,7 @@ fn recv_buffer_status_msg(
|
|||
) -> Result<()> {
|
||||
let mut msg: IoStatusMsg = Default::default();
|
||||
let size = socket
|
||||
.recv(msg.as_bytes_mut())
|
||||
.recv(msg.as_mut_bytes())
|
||||
.map_err(Error::ServerIOError)?;
|
||||
if size != std::mem::size_of::<IoStatusMsg>() {
|
||||
return Err(Error::ProtocolError(
|
||||
|
|
@ -668,7 +669,7 @@ fn recv_buffer_status_msg(
|
|||
fn recv_event(socket: &UnixSeqpacket) -> Result<virtio_snd_event> {
|
||||
let mut msg: virtio_snd_event = Default::default();
|
||||
let size = socket
|
||||
.recv(msg.as_bytes_mut())
|
||||
.recv(msg.as_mut_bytes())
|
||||
.map_err(Error::ServerIOError)?;
|
||||
if size != std::mem::size_of::<virtio_snd_event>() {
|
||||
return Err(Error::ProtocolError(
|
||||
|
|
@ -794,7 +795,7 @@ impl IoBufferQueue {
|
|||
|
||||
fn send_buffer(&self, stream_id: u32, offset: usize, size: usize) -> Result<()> {
|
||||
let msg = IoTransferMsg::new(stream_id, offset, size);
|
||||
seq_socket_send(&self.socket, msg)
|
||||
seq_socket_send(&self.socket, msg.as_bytes())
|
||||
}
|
||||
|
||||
fn keep_rds(&self) -> Vec<RawDescriptor> {
|
||||
|
|
@ -835,15 +836,15 @@ impl From<(u32, VioSStreamParams)> for virtio_snd_pcm_set_params {
|
|||
}
|
||||
}
|
||||
|
||||
fn send_cmd<T: AsBytes>(control_socket: &UnixSeqpacket, data: T) -> Result<()> {
|
||||
seq_socket_send(control_socket, data)?;
|
||||
fn send_cmd<T: Immutable + IntoBytes>(control_socket: &UnixSeqpacket, data: T) -> Result<()> {
|
||||
seq_socket_send(control_socket, data.as_bytes())?;
|
||||
recv_cmd_status(control_socket)
|
||||
}
|
||||
|
||||
fn recv_cmd_status(control_socket: &UnixSeqpacket) -> Result<()> {
|
||||
let mut status: virtio_snd_hdr = Default::default();
|
||||
control_socket
|
||||
.recv(status.as_bytes_mut())
|
||||
.recv(status.as_mut_bytes())
|
||||
.map_err(Error::ServerIOError)?;
|
||||
if status.code.to_native() == VIRTIO_SND_S_OK {
|
||||
Ok(())
|
||||
|
|
@ -852,9 +853,9 @@ fn recv_cmd_status(control_socket: &UnixSeqpacket) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
fn seq_socket_send<T: AsBytes>(socket: &UnixSeqpacket, data: T) -> Result<()> {
|
||||
fn seq_socket_send(socket: &UnixSeqpacket, data: &[u8]) -> Result<()> {
|
||||
loop {
|
||||
let send_res = socket.send(data.as_bytes());
|
||||
let send_res = socket.send(data);
|
||||
if let Err(e) = send_res {
|
||||
match e.kind() {
|
||||
// Retry if interrupted
|
||||
|
|
@ -875,9 +876,10 @@ const VIOS_VERSION: u32 = 2;
|
|||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
AsBytes,
|
||||
FromZeroes,
|
||||
FromBytes,
|
||||
Immutable,
|
||||
IntoBytes,
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
PartialEq,
|
||||
|
|
@ -898,7 +900,7 @@ struct BufferReleaseMsg {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct IoTransferMsg {
|
||||
io_xfer: virtio_snd_pcm_xfer,
|
||||
buffer_offset: u32,
|
||||
|
|
@ -918,7 +920,7 @@ impl IoTransferMsg {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct IoStatusMsg {
|
||||
status: virtio_snd_pcm_status,
|
||||
buffer_offset: u32,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ use base::EventToken;
|
|||
use base::WaitContext;
|
||||
use data_model::Le32;
|
||||
use sync::Mutex;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::super::constants::*;
|
||||
use super::super::layout::*;
|
||||
|
|
@ -262,7 +263,7 @@ impl Worker {
|
|||
VIRTIO_SND_S_BAD_MSG
|
||||
} else {
|
||||
let mut request: virtio_snd_jack_remap = Default::default();
|
||||
request.as_bytes_mut().copy_from_slice(&read_buf);
|
||||
request.as_mut_bytes().copy_from_slice(&read_buf);
|
||||
let jack_id = request.hdr.jack_id.to_native();
|
||||
let association = request.association.to_native();
|
||||
let sequence = request.sequence.to_native();
|
||||
|
|
@ -404,7 +405,7 @@ impl Worker {
|
|||
return None;
|
||||
}
|
||||
let mut query: virtio_snd_query_info = Default::default();
|
||||
query.as_bytes_mut().copy_from_slice(read_buf);
|
||||
query.as_mut_bytes().copy_from_slice(read_buf);
|
||||
let start_id = query.start_id.to_native();
|
||||
let count = query.count.to_native();
|
||||
Some((start_id, count))
|
||||
|
|
@ -420,7 +421,7 @@ impl Worker {
|
|||
return reply_control_op_status(VIRTIO_SND_S_BAD_MSG, desc, &self.control_queue);
|
||||
}
|
||||
let mut params: virtio_snd_pcm_set_params = Default::default();
|
||||
params.as_bytes_mut().copy_from_slice(read_buf);
|
||||
params.as_mut_bytes().copy_from_slice(read_buf);
|
||||
let stream_id = params.hdr.stream_id.to_native();
|
||||
if stream_id < self.vios_client.lock().num_streams() {
|
||||
self.streams[stream_id as usize].send(StreamMsg::SetParams(desc, params))
|
||||
|
|
@ -453,7 +454,7 @@ impl Worker {
|
|||
);
|
||||
}
|
||||
let mut pcm_hdr: virtio_snd_pcm_hdr = Default::default();
|
||||
pcm_hdr.as_bytes_mut().copy_from_slice(read_buf);
|
||||
pcm_hdr.as_mut_bytes().copy_from_slice(read_buf);
|
||||
let stream_id = pcm_hdr.stream_id.to_native();
|
||||
if stream_id < self.vios_client.lock().num_streams() {
|
||||
self.streams[stream_id as usize].send(msg)
|
||||
|
|
@ -476,7 +477,7 @@ impl Worker {
|
|||
}
|
||||
}
|
||||
|
||||
fn send_info_reply<T: AsBytes>(
|
||||
fn send_info_reply<T: Immutable + IntoBytes>(
|
||||
&mut self,
|
||||
mut desc: DescriptorChain,
|
||||
code: u32,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use vhost::NetT as VhostNetT;
|
|||
use virtio_sys::virtio_config::VIRTIO_F_RING_PACKED;
|
||||
use virtio_sys::virtio_net;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::control_socket::*;
|
||||
use super::worker::Worker;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use virtio_sys::virtio_fs::virtio_fs_config;
|
|||
use vm_memory::GuestMemory;
|
||||
use vmm_vhost::message::VhostUserProtocolFeatures;
|
||||
use vmm_vhost::VHOST_USER_F_PROTOCOL_FEATURES;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio;
|
||||
use crate::virtio::copy_config;
|
||||
|
|
|
|||
|
|
@ -981,16 +981,18 @@ mod tests {
|
|||
use base::Event;
|
||||
use vmm_vhost::BackendServer;
|
||||
use vmm_vhost::FrontendReq;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::FromZeros;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use super::*;
|
||||
use crate::virtio::vhost_user_frontend::VhostUserFrontend;
|
||||
use crate::virtio::DeviceType;
|
||||
use crate::virtio::VirtioDevice;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C, packed(4))]
|
||||
struct FakeConfig {
|
||||
x: u32,
|
||||
|
|
@ -1135,10 +1137,9 @@ mod tests {
|
|||
.unwrap();
|
||||
|
||||
println!("read_config");
|
||||
let mut buf = vec![0; std::mem::size_of::<FakeConfig>()];
|
||||
vmm_device.read_config(0, &mut buf);
|
||||
let mut config = FakeConfig::new_zeroed();
|
||||
vmm_device.read_config(0, config.as_mut_bytes());
|
||||
// Check if the obtained config data is correct.
|
||||
let config = FakeConfig::read_from(buf.as_bytes()).unwrap();
|
||||
assert_eq!(config, FAKE_CONFIG_DATA);
|
||||
|
||||
let activate = |vmm_device: &mut VhostUserFrontend| {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ pub use sys::start_device as run_net_device;
|
|||
pub use sys::Options;
|
||||
use vm_memory::GuestMemory;
|
||||
use vmm_vhost::message::VhostUserProtocolFeatures;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio;
|
||||
use crate::virtio::net::build_config;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub use sys::Options;
|
|||
use vm_memory::GuestMemory;
|
||||
use vmm_vhost::message::VhostUserProtocolFeatures;
|
||||
use vmm_vhost::VHOST_USER_F_PROTOCOL_FEATURES;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio;
|
||||
use crate::virtio::copy_config;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ use vmm_vhost::message::VhostUserVringState;
|
|||
use vmm_vhost::Error;
|
||||
use vmm_vhost::Result;
|
||||
use vmm_vhost::VHOST_USER_F_PROTOCOL_FEATURES;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::BackendConnection;
|
||||
use crate::virtio::device_constants::vsock::NUM_QUEUES;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use snapshot::AnySnapshot;
|
|||
use vhost::Vhost;
|
||||
use vhost::Vsock as VhostVsockHandle;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use super::worker::VringBase;
|
||||
use super::worker::Worker;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use data_model::Le32;
|
||||
use virtio_sys::virtio_fs::virtio_fs_config;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::device_constants::fs::FS_MAX_TAG_LEN;
|
||||
use crate::virtio::vhost_user_frontend::Error;
|
||||
|
|
|
|||
|
|
@ -575,7 +575,7 @@ impl<D: DecoderBackend> Decoder<D> {
|
|||
// Safe because we confirmed the correct type for the resource.
|
||||
// unwrap() is also safe here because we just tested above that `entries` had
|
||||
// exactly one element.
|
||||
unsafe { entries.first().unwrap().object },
|
||||
entries.first().unwrap().object(),
|
||||
&self.resource_bridge,
|
||||
params,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -673,7 +673,7 @@ impl<T: Encoder> EncoderDevice<T> {
|
|||
// Safe because we confirmed the correct type for the resource.
|
||||
// unwrap() is also safe here because we just tested above that
|
||||
// `entries` had exactly one element.
|
||||
unsafe { entries.first().unwrap().object },
|
||||
entries.first().unwrap().object(),
|
||||
&self.resource_bridge,
|
||||
&stream.src_params,
|
||||
)
|
||||
|
|
@ -723,7 +723,7 @@ impl<T: Encoder> EncoderDevice<T> {
|
|||
// Safe because we confirmed the correct type for the resource.
|
||||
// unwrap() is also safe here because we just tested above that
|
||||
// `entries` had exactly one element.
|
||||
unsafe { entries.first().unwrap().object },
|
||||
entries.first().unwrap().object(),
|
||||
&self.resource_bridge,
|
||||
&stream.dst_params,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use data_model::Le32;
|
|||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::copy_config;
|
||||
use crate::virtio::virtio_device::VirtioDevice;
|
||||
|
|
@ -208,7 +208,7 @@ impl VirtioDevice for VideoDevice {
|
|||
|
||||
fn read_config(&self, offset: u64, data: &mut [u8]) {
|
||||
let mut cfg = build_config(self.backend);
|
||||
copy_config(data, 0, cfg.as_bytes_mut(), offset);
|
||||
copy_config(data, 0, cfg.as_mut_bytes(), offset);
|
||||
}
|
||||
|
||||
fn activate(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
//! The main points of the manual modifications are as follows:
|
||||
//! * Removed `hdr` from each command struct so that we can read the header and a command body
|
||||
//! separately. (cf. [related discussion](https://markmail.org/message/tr5g6axqq2zzq64y))
|
||||
//! * Derive implementations of AsBytes and FromBytes for each struct as needed.
|
||||
//! * Derive implementations of zerocopy traits for each struct as needed.
|
||||
//! * Added GET_PARAMS_EXT and SET_PARAMS_EXT to allow querying and changing the resource type
|
||||
//! dynamically.
|
||||
//! * Moved some definitions such as virtio_video_config to device_constants to make them visible to
|
||||
|
|
@ -28,9 +28,10 @@
|
|||
|
||||
use data_model::Le32;
|
||||
use data_model::Le64;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
pub const VIRTIO_VIDEO_MAX_PLANES: u32 = 8;
|
||||
pub const VIRTIO_VIDEO_FORMAT_RAW_MIN: virtio_video_format = 1;
|
||||
|
|
@ -131,7 +132,7 @@ pub const VIRTIO_VIDEO_RESP_ERR_INVALID_PARAMETER: virtio_video_cmd_type = 772;
|
|||
pub const VIRTIO_VIDEO_RESP_ERR_UNSUPPORTED_CONTROL: virtio_video_cmd_type = 773;
|
||||
pub type virtio_video_cmd_type = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_cmd_hdr {
|
||||
pub type_: Le32,
|
||||
pub stream_id: Le32,
|
||||
|
|
@ -141,7 +142,7 @@ pub const VIRTIO_VIDEO_QUEUE_TYPE_INPUT: virtio_video_queue_type = 256;
|
|||
pub const VIRTIO_VIDEO_QUEUE_TYPE_OUTPUT: virtio_video_queue_type = 257;
|
||||
pub type virtio_video_queue_type = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_query_capability {
|
||||
pub queue_type: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
|
|
@ -151,7 +152,7 @@ pub const VIRTIO_VIDEO_PLANES_LAYOUT_SINGLE_BUFFER: virtio_video_planes_layout_f
|
|||
pub const VIRTIO_VIDEO_PLANES_LAYOUT_PER_PLANE: virtio_video_planes_layout_flag = 2;
|
||||
pub type virtio_video_planes_layout_flag = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_format_range {
|
||||
pub min: Le32,
|
||||
pub max: Le32,
|
||||
|
|
@ -160,7 +161,7 @@ pub struct virtio_video_format_range {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_format_frame {
|
||||
pub width: virtio_video_format_range,
|
||||
pub height: virtio_video_format_range,
|
||||
|
|
@ -169,7 +170,7 @@ pub struct virtio_video_format_frame {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_format_desc {
|
||||
pub mask: Le64,
|
||||
pub format: Le32,
|
||||
|
|
@ -179,7 +180,7 @@ pub struct virtio_video_format_desc {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_query_capability_resp {
|
||||
pub hdr: virtio_video_cmd_hdr,
|
||||
pub num_descs: Le32,
|
||||
|
|
@ -190,7 +191,7 @@ pub const VIRTIO_VIDEO_MEM_TYPE_GUEST_PAGES: virtio_video_mem_type = 0;
|
|||
pub const VIRTIO_VIDEO_MEM_TYPE_VIRTIO_OBJECT: virtio_video_mem_type = 1;
|
||||
pub type virtio_video_mem_type = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_stream_create {
|
||||
pub in_mem_type: Le32,
|
||||
pub out_mem_type: Le32,
|
||||
|
|
@ -206,28 +207,28 @@ impl Default for virtio_video_stream_create {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_stream_destroy {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_stream_drain {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_mem_entry {
|
||||
pub addr: Le64,
|
||||
pub length: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_object_entry {
|
||||
pub uuid: [u8; 16usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_resource_create {
|
||||
pub queue_type: Le32,
|
||||
pub resource_id: Le32,
|
||||
|
|
@ -238,7 +239,7 @@ pub struct virtio_video_resource_create {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_resource_queue {
|
||||
pub queue_type: Le32,
|
||||
pub resource_id: Le32,
|
||||
|
|
@ -255,7 +256,7 @@ pub const VIRTIO_VIDEO_BUFFER_FLAG_PFRAME: virtio_video_buffer_flag = 8;
|
|||
pub const VIRTIO_VIDEO_BUFFER_FLAG_BFRAME: virtio_video_buffer_flag = 16;
|
||||
pub type virtio_video_buffer_flag = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_resource_queue_resp {
|
||||
pub hdr: virtio_video_cmd_hdr,
|
||||
pub timestamp: Le64,
|
||||
|
|
@ -264,27 +265,27 @@ pub struct virtio_video_resource_queue_resp {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_resource_destroy_all {
|
||||
pub queue_type: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_queue_clear {
|
||||
pub queue_type: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_plane_format {
|
||||
pub plane_size: Le32,
|
||||
pub stride: Le32,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_crop {
|
||||
pub left: Le32,
|
||||
pub top: Le32,
|
||||
|
|
@ -292,7 +293,7 @@ pub struct virtio_video_crop {
|
|||
pub height: Le32,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_params {
|
||||
pub queue_type: Le32,
|
||||
pub format: Le32,
|
||||
|
|
@ -306,21 +307,21 @@ pub struct virtio_video_params {
|
|||
pub plane_formats: [virtio_video_plane_format; 8usize],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_get_params {
|
||||
pub queue_type: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_get_params_resp {
|
||||
pub hdr: virtio_video_cmd_hdr,
|
||||
pub params: virtio_video_params,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_set_params {
|
||||
pub params: virtio_video_params,
|
||||
}
|
||||
|
|
@ -329,28 +330,28 @@ pub struct virtio_video_set_params {
|
|||
/// was an oversight and the {GET,SET}_PARAMS_EXT commands use this structure to fix it, while
|
||||
/// the older {GET,SET}_PARAMS commands are kept for backward compatibility.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_params_ext {
|
||||
pub base: virtio_video_params,
|
||||
pub resource_type: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_get_params_ext {
|
||||
pub queue_type: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_get_params_ext_resp {
|
||||
pub hdr: virtio_video_cmd_hdr,
|
||||
pub params: virtio_video_params_ext,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_set_params_ext {
|
||||
pub params: virtio_video_params_ext,
|
||||
}
|
||||
|
|
@ -364,110 +365,110 @@ pub const VIRTIO_VIDEO_CONTROL_BITRATE_PEAK: virtio_video_control_type = 6;
|
|||
pub const VIRTIO_VIDEO_CONTROL_PREPEND_SPSPPS_TO_IDR: virtio_video_control_type = 7;
|
||||
pub type virtio_video_control_type = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_query_control_profile {
|
||||
pub format: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_query_control_level {
|
||||
pub format: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_query_control {
|
||||
pub control: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_query_control_resp_profile {
|
||||
pub num: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_query_control_resp_level {
|
||||
pub num: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_query_control_resp {
|
||||
pub hdr: virtio_video_cmd_hdr,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_get_control {
|
||||
pub control: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_control_val_bitrate {
|
||||
pub bitrate: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_control_val_bitrate_peak {
|
||||
pub bitrate_peak: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_control_val_bitrate_mode {
|
||||
pub bitrate_mode: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_control_val_profile {
|
||||
pub profile: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_control_val_level {
|
||||
pub level: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_control_val_prepend_spspps_to_idr {
|
||||
pub prepend_spspps_to_idr: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_get_control_resp {
|
||||
pub hdr: virtio_video_cmd_hdr,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_set_control {
|
||||
pub control: Le32,
|
||||
pub padding: [u8; 4usize],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_set_control_resp {
|
||||
pub hdr: virtio_video_cmd_hdr,
|
||||
}
|
||||
|
|
@ -476,7 +477,7 @@ pub const VIRTIO_VIDEO_EVENT_ERROR: virtio_video_event_type = 256;
|
|||
pub const VIRTIO_VIDEO_EVENT_DECODER_RESOLUTION_CHANGED: virtio_video_event_type = 512;
|
||||
pub type virtio_video_event_type = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct virtio_video_event {
|
||||
pub event_type: Le32,
|
||||
pub stream_id: Le32,
|
||||
|
|
|
|||
|
|
@ -19,9 +19,10 @@ use thiserror::Error as ThisError;
|
|||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use vm_memory::GuestMemoryError;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::virtio::resource_bridge;
|
||||
use crate::virtio::resource_bridge::ResourceBridgeError;
|
||||
|
|
@ -44,27 +45,19 @@ pub enum ResourceType {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
/// A guest resource entry which type is not decided yet.
|
||||
pub union UnresolvedResourceEntry {
|
||||
pub object: virtio_video_object_entry,
|
||||
pub guest_mem: virtio_video_mem_entry,
|
||||
}
|
||||
pub struct UnresolvedResourceEntry([u8; 16]);
|
||||
|
||||
impl fmt::Debug for UnresolvedResourceEntry {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"unresolved {:?} or {:?}",
|
||||
// SAFETY:
|
||||
// Safe because `self.object` and `self.guest_mem` are the same size and both made of
|
||||
// integers, making it safe to display them no matter their value.
|
||||
unsafe { self.object },
|
||||
// SAFETY:
|
||||
// Safe because `self.object` and `self.guest_mem` are the same size and both made of
|
||||
// integers, making it safe to display them no matter their value.
|
||||
unsafe { self.guest_mem }
|
||||
)
|
||||
write!(f, "unresolved {:?}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl UnresolvedResourceEntry {
|
||||
pub fn object(&self) -> virtio_video_object_entry {
|
||||
virtio_video_object_entry::read_from_bytes(&self.0).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,9 +46,10 @@ use vm_control::VmMemoryDestination;
|
|||
use vm_control::VmMemoryRegionId;
|
||||
use vm_control::VmMemorySource;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use self::virtio_pci_common_config::VirtioPciCommonConfig;
|
||||
use super::*;
|
||||
|
|
@ -110,7 +111,7 @@ pub enum PciCapabilityType {
|
|||
|
||||
#[allow(dead_code)]
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct VirtioPciCap {
|
||||
// cap_vndr and cap_next are autofilled based on id() in pci configuration
|
||||
pub cap_vndr: u8, // Generic PCI field: PCI_CAP_ID_VNDR
|
||||
|
|
@ -160,7 +161,7 @@ impl VirtioPciCap {
|
|||
|
||||
#[allow(dead_code)]
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct VirtioPciNotifyCap {
|
||||
cap: VirtioPciCap,
|
||||
notify_off_multiplier: Le32,
|
||||
|
|
@ -206,7 +207,7 @@ impl VirtioPciNotifyCap {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct VirtioPciShmCap {
|
||||
cap: VirtioPciCap,
|
||||
offset_hi: Le32, // Most sig 32 bits of offset
|
||||
|
|
|
|||
|
|
@ -5,21 +5,22 @@
|
|||
use data_model::Le16;
|
||||
use data_model::Le32;
|
||||
use data_model::Le64;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
pub const TYPE_STREAM_SOCKET: u16 = 1;
|
||||
|
||||
/// virtio_vsock_config is the vsock device configuration space defined by the virtio spec.
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_vsock_config {
|
||||
pub guest_cid: Le64,
|
||||
}
|
||||
|
||||
/// The message header for data packets sent on the tx/rx queues
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C, packed)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct virtio_vsock_hdr {
|
||||
|
|
@ -28,7 +29,7 @@ pub struct virtio_vsock_hdr {
|
|||
pub src_port: Le32,
|
||||
pub dst_port: Le32,
|
||||
pub len: Le32,
|
||||
pub r#type: Le16,
|
||||
pub type_: Le16,
|
||||
pub op: Le16,
|
||||
pub flags: Le32,
|
||||
pub buf_alloc: Le32,
|
||||
|
|
@ -36,7 +37,7 @@ pub struct virtio_vsock_hdr {
|
|||
}
|
||||
|
||||
/// An event sent to the event queue
|
||||
#[derive(Copy, Clone, Debug, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Debug, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
pub struct virtio_vsock_event {
|
||||
// ID from the virtio_vsock_event_id struct in the virtio spec
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ use serde::Serialize;
|
|||
use snapshot::AnySnapshot;
|
||||
use thiserror::Error as ThisError;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::FromZeros;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::virtio::async_utils;
|
||||
use crate::virtio::copy_config;
|
||||
|
|
@ -610,7 +610,7 @@ impl Worker {
|
|||
src_port: Le32::from(port.host),
|
||||
dst_port: guest_port,
|
||||
len: Le32::from(data_size as u32),
|
||||
r#type: TYPE_STREAM_SOCKET.into(),
|
||||
type_: TYPE_STREAM_SOCKET.into(),
|
||||
op: vsock_op::VIRTIO_VSOCK_OP_RW.into(),
|
||||
buf_alloc: Le32::from(connection.buf_alloc as u32),
|
||||
fwd_cnt: Le32::from(connection.recv_cnt as u32),
|
||||
|
|
@ -1104,7 +1104,7 @@ impl Worker {
|
|||
src_port: { header.dst_port },
|
||||
dst_port: { header.src_port },
|
||||
len: 0.into(),
|
||||
r#type: TYPE_STREAM_SOCKET.into(),
|
||||
type_: TYPE_STREAM_SOCKET.into(),
|
||||
op: resp_op.into(),
|
||||
buf_alloc: Le32::from(buf_alloc),
|
||||
fwd_cnt: Le32::from(fwd_cnt),
|
||||
|
|
@ -1148,7 +1148,7 @@ impl Worker {
|
|||
src_port: { header.dst_port },
|
||||
dst_port: { header.src_port },
|
||||
len: 0.into(),
|
||||
r#type: TYPE_STREAM_SOCKET.into(),
|
||||
type_: TYPE_STREAM_SOCKET.into(),
|
||||
op: vsock_op::VIRTIO_VSOCK_OP_RST.into(),
|
||||
// There is no buffer on a closed connection
|
||||
buf_alloc: 0.into(),
|
||||
|
|
@ -1161,7 +1161,7 @@ impl Worker {
|
|||
self.write_bytes_to_queue(
|
||||
&mut *send_queue.lock().await,
|
||||
rx_queue_evt,
|
||||
response.as_bytes_mut(),
|
||||
response.as_mut_bytes(),
|
||||
)
|
||||
.await
|
||||
.expect("vsock: failed to write to queue");
|
||||
|
|
@ -1261,7 +1261,7 @@ impl Worker {
|
|||
src_port: { header.dst_port },
|
||||
dst_port: { header.src_port },
|
||||
len: 0.into(),
|
||||
r#type: TYPE_STREAM_SOCKET.into(),
|
||||
type_: TYPE_STREAM_SOCKET.into(),
|
||||
op: vsock_op::VIRTIO_VSOCK_OP_CREDIT_UPDATE.into(),
|
||||
buf_alloc: Le32::from(connection.buf_alloc as u32),
|
||||
fwd_cnt: Le32::from(connection.recv_cnt as u32),
|
||||
|
|
@ -1275,7 +1275,7 @@ impl Worker {
|
|||
self.write_bytes_to_queue(
|
||||
&mut *send_queue.lock().await,
|
||||
rx_queue_evt,
|
||||
response.as_bytes_mut(),
|
||||
response.as_mut_bytes(),
|
||||
)
|
||||
.await
|
||||
.unwrap_or_else(|_| panic!("vsock: port {}: failed to write to queue", port));
|
||||
|
|
@ -1302,7 +1302,7 @@ impl Worker {
|
|||
src_port: { header.dst_port },
|
||||
dst_port: { header.src_port },
|
||||
len: 0.into(),
|
||||
r#type: TYPE_STREAM_SOCKET.into(),
|
||||
type_: TYPE_STREAM_SOCKET.into(),
|
||||
op: vsock_op::VIRTIO_VSOCK_OP_RST.into(),
|
||||
buf_alloc: Le32::from(connection.buf_alloc as u32),
|
||||
fwd_cnt: Le32::from(connection.recv_cnt as u32),
|
||||
|
|
@ -1314,7 +1314,7 @@ impl Worker {
|
|||
self.write_bytes_to_queue(
|
||||
&mut *send_queue.lock().await,
|
||||
rx_queue_evt,
|
||||
response.as_bytes_mut(),
|
||||
response.as_mut_bytes(),
|
||||
)
|
||||
.await
|
||||
.expect("failed to write to queue");
|
||||
|
|
|
|||
|
|
@ -129,9 +129,10 @@ use thiserror::Error as ThisError;
|
|||
use vm_control::VmMemorySource;
|
||||
use vm_memory::GuestMemory;
|
||||
use vm_memory::GuestMemoryError;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
#[cfg(feature = "gpu")]
|
||||
use super::resource_bridge::get_resource_info;
|
||||
|
|
@ -621,14 +622,14 @@ impl VmRequester {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct CtrlHeader {
|
||||
type_: Le32,
|
||||
flags: Le32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct CtrlVfdNew {
|
||||
hdr: CtrlHeader,
|
||||
id: Le32,
|
||||
|
|
@ -639,7 +640,7 @@ struct CtrlVfdNew {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct CtrlVfdNewCtxNamed {
|
||||
hdr: CtrlHeader,
|
||||
id: Le32,
|
||||
|
|
@ -652,7 +653,7 @@ struct CtrlVfdNewCtxNamed {
|
|||
const_assert_eq!(size_of::<CtrlVfdNewCtxNamed>(), 64);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[cfg(feature = "minigbm")]
|
||||
struct CtrlVfdNewDmabuf {
|
||||
hdr: CtrlHeader,
|
||||
|
|
@ -673,7 +674,7 @@ struct CtrlVfdNewDmabuf {
|
|||
|
||||
#[cfg(feature = "minigbm")]
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct CtrlVfdDmabufSync {
|
||||
hdr: CtrlHeader,
|
||||
id: Le32,
|
||||
|
|
@ -681,7 +682,7 @@ struct CtrlVfdDmabufSync {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct CtrlVfdRecv {
|
||||
hdr: CtrlHeader,
|
||||
id: Le32,
|
||||
|
|
@ -689,14 +690,14 @@ struct CtrlVfdRecv {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct CtrlVfd {
|
||||
hdr: CtrlHeader,
|
||||
id: Le32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct CtrlVfdSend {
|
||||
hdr: CtrlHeader,
|
||||
id: Le32,
|
||||
|
|
@ -705,21 +706,21 @@ struct CtrlVfdSend {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct CtrlVfdSendVfd {
|
||||
kind: Le32,
|
||||
id: Le32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, KnownLayout)]
|
||||
union CtrlVfdSendVfdV2Payload {
|
||||
id: Le32,
|
||||
seqno: Le64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, KnownLayout)]
|
||||
struct CtrlVfdSendVfdV2 {
|
||||
kind: Le32,
|
||||
payload: CtrlVfdSendVfdV2Payload,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ sync = { path = "../common/sync" }
|
|||
thiserror = "1"
|
||||
uuid = { version = "1", features = ["v4"], optional = true }
|
||||
vm_memory = { path = "../vm_memory" }
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
zstd = { version = "0.13", optional = true }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
|
|
|
|||
|
|
@ -28,9 +28,11 @@ use data_model::Le16;
|
|||
use data_model::Le32;
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::FromZeros;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::AsyncDisk;
|
||||
use crate::DiskFile;
|
||||
|
|
@ -56,7 +58,7 @@ pub const SPARSE_HEADER_MAGIC: u32 = 0xed26ff3a;
|
|||
const MAJOR_VERSION: u16 = 1;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct SparseHeader {
|
||||
magic: Le32, // SPARSE_HEADER_MAGIC
|
||||
major_version: Le16, // (0x1) - reject images with higher major versions
|
||||
|
|
@ -77,7 +79,7 @@ const CHUNK_TYPE_DONT_CARE: u16 = 0xCAC3;
|
|||
const CHUNK_TYPE_CRC32: u16 = 0xCAC4;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Clone, Copy, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct ChunkHeader {
|
||||
chunk_type: Le16, /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */
|
||||
reserved1: u16,
|
||||
|
|
@ -117,7 +119,7 @@ fn parse_chunk<T: Read + Seek>(input: &mut T, blk_sz: u64) -> Result<Option<Chun
|
|||
.map_err(Error::ReadSpecificationError)?;
|
||||
let mut chunk_header = ChunkHeader::new_zeroed();
|
||||
input
|
||||
.read_exact(chunk_header.as_bytes_mut())
|
||||
.read_exact(chunk_header.as_mut_bytes())
|
||||
.map_err(Error::ReadSpecificationError)?;
|
||||
let chunk_body_size = (chunk_header.total_sz.to_native() as usize)
|
||||
.checked_sub(HEADER_SIZE)
|
||||
|
|
@ -168,7 +170,7 @@ impl AndroidSparse {
|
|||
file.seek(SeekFrom::Start(0))
|
||||
.map_err(Error::ReadSpecificationError)?;
|
||||
let mut sparse_header = SparseHeader::new_zeroed();
|
||||
file.read_exact(sparse_header.as_bytes_mut())
|
||||
file.read_exact(sparse_header.as_mut_bytes())
|
||||
.map_err(Error::ReadSpecificationError)?;
|
||||
if sparse_header.magic != SPARSE_HEADER_MAGIC {
|
||||
return Err(Error::InvalidSpecification(format!(
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use std::mem::size_of_val;
|
|||
use base::FileReadWriteAtVolatile;
|
||||
use base::VolatileSlice;
|
||||
use base::WriteZeroesAt;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
/// A qcow file. Allows reading/writing clusters and appending clusters.
|
||||
#[derive(Debug)]
|
||||
|
|
@ -49,7 +49,7 @@ impl QcowRawFile {
|
|||
) -> io::Result<Vec<u64>> {
|
||||
let mut table = vec![0; count as usize];
|
||||
self.file.seek(SeekFrom::Start(offset))?;
|
||||
self.file.read_exact(table.as_bytes_mut())?;
|
||||
self.file.read_exact(table.as_mut_bytes())?;
|
||||
let mask = mask.unwrap_or(u64::MAX);
|
||||
for ptr in &mut table {
|
||||
*ptr = u64::from_be(*ptr) & mask;
|
||||
|
|
@ -93,7 +93,7 @@ impl QcowRawFile {
|
|||
let count = self.cluster_size / size_of::<u16>() as u64;
|
||||
let mut table = vec![0; count as usize];
|
||||
self.file.seek(SeekFrom::Start(offset))?;
|
||||
self.file.read_exact(table.as_bytes_mut())?;
|
||||
self.file.read_exact(table.as_mut_bytes())?;
|
||||
for refcount in &mut table {
|
||||
*refcount = u16::from_be(*refcount);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ base = { path = "../base/" }
|
|||
enumn = "0.1"
|
||||
libc = "0.2"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
zerocopy = "0.7.29" # >=0.7.29 is required for our 'AsBytes'
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
||||
[[example]]
|
||||
name = "mkfs"
|
||||
|
|
|
|||
|
|
@ -14,8 +14,10 @@ use anyhow::Context;
|
|||
use anyhow::Result;
|
||||
use base::MappedRegion;
|
||||
use base::MemoryMapping;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
struct Region {
|
||||
|
|
@ -143,7 +145,7 @@ fn test_region_manager() {
|
|||
assert_eq!(rm.to_vec(), vec![&Region { start: 0, len: 30 },]);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, AsBytes)]
|
||||
#[derive(Debug, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[repr(C)]
|
||||
/// Represents a ID of a disk block.
|
||||
pub struct BlockId(u32);
|
||||
|
|
@ -262,16 +264,16 @@ impl<'a> Arena<'a> {
|
|||
}
|
||||
|
||||
/// Allocate a new region for a value with type `T`.
|
||||
pub fn allocate<T: AsBytes + FromBytes + Sized>(
|
||||
pub fn allocate<T: FromBytes + IntoBytes + KnownLayout>(
|
||||
&self,
|
||||
block: BlockId,
|
||||
block_offset: usize,
|
||||
) -> Result<&'a mut T> {
|
||||
let slice = self.allocate_slice(block, block_offset, std::mem::size_of::<T>())?;
|
||||
T::mut_from(slice).ok_or_else(|| anyhow!("failed to interpret"))
|
||||
T::mut_from_bytes(slice).map_err(|_| anyhow!("failed to interpret"))
|
||||
}
|
||||
|
||||
pub fn write_to_mem<T: AsBytes + FromBytes + Sized>(
|
||||
pub fn write_to_mem<T: IntoBytes + Immutable>(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
block_offset: usize,
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::arena::Arena;
|
||||
use crate::arena::BlockId;
|
||||
|
|
@ -26,7 +27,7 @@ pub const BLOCK_SIZE: usize = 4096;
|
|||
///
|
||||
/// See [the specification](https://www.nongnu.org/ext2-doc/ext2.html#block-group-descriptor-table) for the details.
|
||||
#[repr(C)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub(crate) struct BlockGroupDescriptor {
|
||||
/// Index of the first block of the block bitmap.
|
||||
pub block_bitmap: u32,
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@ use anyhow::bail;
|
|||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use base::info;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::arena::Arena;
|
||||
use crate::arena::BlockId;
|
||||
|
|
@ -37,7 +38,7 @@ use crate::superblock::SuperBlock;
|
|||
use crate::xattr::InlineXattrs;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, FromZeroes, FromBytes, AsBytes, Debug)]
|
||||
#[derive(Copy, Clone, Debug, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct DirEntryRaw {
|
||||
inode: u32,
|
||||
rec_len: u16,
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ use std::os::unix::fs::MetadataExt;
|
|||
use anyhow::bail;
|
||||
use anyhow::Result;
|
||||
use enumn::N;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::arena::Arena;
|
||||
use crate::arena::BlockId;
|
||||
|
|
@ -87,7 +88,7 @@ const INODE_BLOCK_LEN: usize = 60;
|
|||
///
|
||||
/// This is a wrapper of `[u8; 60]` to implement `Default` manually.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Debug, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub(crate) struct InodeBlock(pub [u8; INODE_BLOCK_LEN]);
|
||||
|
||||
impl Default for InodeBlock {
|
||||
|
|
@ -172,7 +173,7 @@ impl InodeBlock {
|
|||
///
|
||||
/// The field names are based on [the specification](https://www.nongnu.org/ext2-doc/ext2.html#inode-table).
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Debug, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub(crate) struct Inode {
|
||||
mode: u16,
|
||||
uid: u16,
|
||||
|
|
@ -221,7 +222,7 @@ impl Default for Inode {
|
|||
/// The block size '512' byte is fixed and not related to the actual block size of the file system.
|
||||
/// For more details, see notes for `i_blocks_lo` in the specification.
|
||||
#[repr(C)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct InodeBlocksCount(u32);
|
||||
|
||||
impl InodeBlocksCount {
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@
|
|||
//! Defines the superblock structure.
|
||||
|
||||
use anyhow::Result;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::arena::Arena;
|
||||
use crate::arena::BlockId;
|
||||
|
|
@ -21,7 +22,7 @@ use crate::inode::Inode;
|
|||
/// Note that this struct only holds the fields at the beginning of the superblock. All fields after
|
||||
/// the fields supported by this structure are filled with zeros.
|
||||
#[repr(C)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub(crate) struct SuperBlock {
|
||||
pub inodes_count: u32,
|
||||
pub blocks_count: u32,
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ use std::path::Path;
|
|||
use anyhow::bail;
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::inode::Inode;
|
||||
|
||||
|
|
@ -152,7 +153,7 @@ pub fn set_xattr(path: &Path, key: &str, value: &str) -> Result<()> {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromZeroes, FromBytes, AsBytes)]
|
||||
#[derive(Default, Debug, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub(crate) struct XattrEntry {
|
||||
name_len: u8,
|
||||
name_index: u8,
|
||||
|
|
|
|||
|
|
@ -16,4 +16,4 @@ enumn = "0.1.0"
|
|||
libc = { version = "0.2", features = ["extra_traits"] }
|
||||
remain = "0.2"
|
||||
thiserror = "1.0.20"
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ use std::time::Duration;
|
|||
use base::error;
|
||||
use base::pagesize;
|
||||
use base::Protection;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::filesystem::Context;
|
||||
use crate::filesystem::DirEntry;
|
||||
|
|
@ -39,9 +39,9 @@ const SELINUX_XATTR_CSTR: &[u8] = b"security.selinux\0";
|
|||
|
||||
/// A trait for reading from the underlying FUSE endpoint.
|
||||
pub trait Reader: io::Read {
|
||||
fn read_struct<T: AsBytes + FromBytes + FromZeroes>(&mut self) -> Result<T> {
|
||||
fn read_struct<T: IntoBytes + FromBytes>(&mut self) -> Result<T> {
|
||||
let mut out = T::new_zeroed();
|
||||
self.read_exact(out.as_bytes_mut())
|
||||
self.read_exact(out.as_mut_bytes())
|
||||
.map_err(Error::DecodeMessage)?;
|
||||
Ok(out)
|
||||
}
|
||||
|
|
@ -1813,7 +1813,7 @@ fn reply_readdir<W: Writer>(len: usize, unique: u64, mut w: W) -> Result<usize>
|
|||
Ok(out.len as usize)
|
||||
}
|
||||
|
||||
fn reply_ok<T: AsBytes, W: Writer>(
|
||||
fn reply_ok<T: IntoBytes + Immutable, W: Writer>(
|
||||
out: Option<T>,
|
||||
data: Option<&[u8]>,
|
||||
unique: u64,
|
||||
|
|
@ -1963,9 +1963,8 @@ fn parse_selinux_xattr(buf: &[u8]) -> Result<Option<&CStr>> {
|
|||
// Because the security context data block may have been preceded by variable-length strings,
|
||||
// `SecctxHeader` and the subsequent `Secctx` structs may not be correctly byte-aligned
|
||||
// within `buf`.
|
||||
let secctx_header = SecctxHeader::read_from_prefix(buf).ok_or(Error::DecodeMessage(
|
||||
io::Error::from_raw_os_error(libc::EINVAL),
|
||||
))?;
|
||||
let (secctx_header, _) = SecctxHeader::read_from_prefix(buf)
|
||||
.map_err(|_| Error::DecodeMessage(io::Error::from_raw_os_error(libc::EINVAL)))?;
|
||||
|
||||
// FUSE 7.38 introduced a generic request extension with the same structure as `SecctxHeader`.
|
||||
// A `nr_secctx` value above `MAX_NR_SECCTX` indicates that this data block does not contain
|
||||
|
|
@ -1986,9 +1985,8 @@ fn parse_selinux_xattr(buf: &[u8]) -> Result<Option<&CStr>> {
|
|||
}
|
||||
|
||||
let secctx =
|
||||
Secctx::read_from(&buf[cur_secctx_pos..(cur_secctx_pos + size_of::<Secctx>())]).ok_or(
|
||||
Error::DecodeMessage(io::Error::from_raw_os_error(libc::EINVAL)),
|
||||
)?;
|
||||
Secctx::read_from_bytes(&buf[cur_secctx_pos..(cur_secctx_pos + size_of::<Secctx>())])
|
||||
.map_err(|_| Error::DecodeMessage(io::Error::from_raw_os_error(libc::EINVAL)))?;
|
||||
|
||||
cur_secctx_pos += size_of::<Secctx>();
|
||||
|
||||
|
|
|
|||
134
fuse/src/sys.rs
134
fuse/src/sys.rs
|
|
@ -6,9 +6,11 @@ use std::mem;
|
|||
|
||||
use bitflags::bitflags;
|
||||
use enumn::N;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
use zerocopy::TryFromBytes;
|
||||
|
||||
/// Version number of this interface.
|
||||
pub const KERNEL_VERSION: u32 = 7;
|
||||
|
|
@ -501,7 +503,7 @@ bitflags! {
|
|||
pub const MAX_NR_SECCTX: u32 = 31;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct Attr {
|
||||
pub ino: u64,
|
||||
pub size: u64,
|
||||
|
|
@ -546,7 +548,7 @@ impl From<libc::stat64> for Attr {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct Kstatfs {
|
||||
pub blocks: u64,
|
||||
pub bfree: u64,
|
||||
|
|
@ -578,7 +580,7 @@ impl From<libc::statvfs64> for Kstatfs {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct FileLock {
|
||||
pub start: u64,
|
||||
pub end: u64,
|
||||
|
|
@ -587,7 +589,7 @@ pub struct FileLock {
|
|||
}
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(Debug, Copy, Clone, N, AsBytes)]
|
||||
#[derive(Debug, Copy, Clone, N, IntoBytes, Immutable, KnownLayout, TryFromBytes)]
|
||||
pub enum Opcode {
|
||||
Lookup = 1,
|
||||
Forget = 2, /* No Reply */
|
||||
|
|
@ -655,7 +657,7 @@ pub enum NotifyOpcode {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct EntryOut {
|
||||
pub nodeid: u64, /* Inode ID */
|
||||
pub generation: u64, /* Inode generation: nodeid:gen must be unique for the fs's lifetime */
|
||||
|
|
@ -667,27 +669,27 @@ pub struct EntryOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct ForgetIn {
|
||||
pub nlookup: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct ForgetOne {
|
||||
pub nodeid: u64,
|
||||
pub nlookup: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct BatchForgetIn {
|
||||
pub count: u32,
|
||||
pub dummy: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct GetattrIn {
|
||||
pub flags: u32,
|
||||
pub dummy: u32,
|
||||
|
|
@ -695,7 +697,7 @@ pub struct GetattrIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct AttrOut {
|
||||
pub attr_valid: u64, /* Cache timeout for the attributes */
|
||||
pub attr_valid_nsec: u32,
|
||||
|
|
@ -704,7 +706,7 @@ pub struct AttrOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct MknodIn {
|
||||
pub mode: u32,
|
||||
pub rdev: u32,
|
||||
|
|
@ -713,27 +715,27 @@ pub struct MknodIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct MkdirIn {
|
||||
pub mode: u32,
|
||||
pub umask: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct ChromeOsTmpfileIn {
|
||||
pub mode: u32,
|
||||
pub umask: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct RenameIn {
|
||||
pub newdir: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct Rename2In {
|
||||
pub newdir: u64,
|
||||
pub flags: u32,
|
||||
|
|
@ -741,13 +743,13 @@ pub struct Rename2In {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct LinkIn {
|
||||
pub oldnodeid: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct SetattrIn {
|
||||
pub valid: u32,
|
||||
pub padding: u32,
|
||||
|
|
@ -787,14 +789,14 @@ impl From<SetattrIn> for libc::stat64 {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct OpenIn {
|
||||
pub flags: u32,
|
||||
pub unused: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct CreateIn {
|
||||
pub flags: u32,
|
||||
pub mode: u32,
|
||||
|
|
@ -803,7 +805,7 @@ pub struct CreateIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct OpenOut {
|
||||
pub fh: u64,
|
||||
pub open_flags: u32,
|
||||
|
|
@ -811,7 +813,7 @@ pub struct OpenOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct ReleaseIn {
|
||||
pub fh: u64,
|
||||
pub flags: u32,
|
||||
|
|
@ -820,7 +822,7 @@ pub struct ReleaseIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct FlushIn {
|
||||
pub fh: u64,
|
||||
pub unused: u32,
|
||||
|
|
@ -829,7 +831,7 @@ pub struct FlushIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct ReadIn {
|
||||
pub fh: u64,
|
||||
pub offset: u64,
|
||||
|
|
@ -841,7 +843,7 @@ pub struct ReadIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct WriteIn {
|
||||
pub fh: u64,
|
||||
pub offset: u64,
|
||||
|
|
@ -853,20 +855,20 @@ pub struct WriteIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct WriteOut {
|
||||
pub size: u32,
|
||||
pub padding: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct StatfsOut {
|
||||
pub st: Kstatfs,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct FsyncIn {
|
||||
pub fh: u64,
|
||||
pub fsync_flags: u32,
|
||||
|
|
@ -874,28 +876,28 @@ pub struct FsyncIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct SetxattrIn {
|
||||
pub size: u32,
|
||||
pub flags: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct GetxattrIn {
|
||||
pub size: u32,
|
||||
pub padding: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct GetxattrOut {
|
||||
pub size: u32,
|
||||
pub padding: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct LkIn {
|
||||
pub fh: u64,
|
||||
pub owner: u64,
|
||||
|
|
@ -905,20 +907,20 @@ pub struct LkIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct LkOut {
|
||||
pub lk: FileLock,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct AccessIn {
|
||||
pub mask: u32,
|
||||
pub padding: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct InitIn {
|
||||
pub major: u32,
|
||||
pub minor: u32,
|
||||
|
|
@ -927,14 +929,14 @@ pub struct InitIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct InitInExt {
|
||||
pub flags2: u32,
|
||||
pub unused: [u32; 11],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct InitOut {
|
||||
pub major: u32,
|
||||
pub minor: u32,
|
||||
|
|
@ -951,13 +953,13 @@ pub struct InitOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct InterruptIn {
|
||||
pub unique: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct BmapIn {
|
||||
pub block: u64,
|
||||
pub blocksize: u32,
|
||||
|
|
@ -965,13 +967,13 @@ pub struct BmapIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct BmapOut {
|
||||
pub block: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct IoctlIn {
|
||||
pub fh: u64,
|
||||
pub flags: u32,
|
||||
|
|
@ -984,7 +986,7 @@ pub struct IoctlIn {
|
|||
/// Describes a region of memory in the address space of the process that made the ioctl syscall.
|
||||
/// Similar to `libc::iovec` but uses `u64`s for the address and the length.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct IoctlIovec {
|
||||
/// The start address of the memory region. This must be in the address space of the process
|
||||
/// that made the ioctl syscall.
|
||||
|
|
@ -995,7 +997,7 @@ pub struct IoctlIovec {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct IoctlOut {
|
||||
pub result: i32,
|
||||
pub flags: u32,
|
||||
|
|
@ -1004,7 +1006,7 @@ pub struct IoctlOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct PollIn {
|
||||
pub fh: u64,
|
||||
pub kh: u64,
|
||||
|
|
@ -1013,20 +1015,20 @@ pub struct PollIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct PollOut {
|
||||
pub revents: u32,
|
||||
pub padding: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NotifyPollWakeupOut {
|
||||
pub kh: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct FallocateIn {
|
||||
pub fh: u64,
|
||||
pub offset: u64,
|
||||
|
|
@ -1036,7 +1038,7 @@ pub struct FallocateIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct InHeader {
|
||||
pub len: u32,
|
||||
pub opcode: u32,
|
||||
|
|
@ -1049,7 +1051,7 @@ pub struct InHeader {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct OutHeader {
|
||||
pub len: u32,
|
||||
pub error: i32,
|
||||
|
|
@ -1057,7 +1059,7 @@ pub struct OutHeader {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct Dirent {
|
||||
pub ino: u64,
|
||||
pub off: u64,
|
||||
|
|
@ -1067,14 +1069,14 @@ pub struct Dirent {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct Direntplus {
|
||||
pub entry_out: EntryOut,
|
||||
pub dirent: Dirent,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NotifyInvalInodeOut {
|
||||
pub ino: u64,
|
||||
pub off: i64,
|
||||
|
|
@ -1082,7 +1084,7 @@ pub struct NotifyInvalInodeOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NotifyInvalEntryOut {
|
||||
pub parent: u64,
|
||||
pub namelen: u32,
|
||||
|
|
@ -1090,7 +1092,7 @@ pub struct NotifyInvalEntryOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NotifyDeleteOut {
|
||||
pub parent: u64,
|
||||
pub child: u64,
|
||||
|
|
@ -1099,7 +1101,7 @@ pub struct NotifyDeleteOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NotifyStoreOut {
|
||||
pub nodeid: u64,
|
||||
pub offset: u64,
|
||||
|
|
@ -1108,7 +1110,7 @@ pub struct NotifyStoreOut {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct Notify_Retrieve_Out {
|
||||
pub notify_unique: u64,
|
||||
pub nodeid: u64,
|
||||
|
|
@ -1119,7 +1121,7 @@ pub struct Notify_Retrieve_Out {
|
|||
|
||||
/* Matches the size of fuse_write_in */
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct NotifyRetrieveIn {
|
||||
pub dummy1: u64,
|
||||
pub offset: u64,
|
||||
|
|
@ -1130,7 +1132,7 @@ pub struct NotifyRetrieveIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct LseekIn {
|
||||
pub fh: u64,
|
||||
pub offset: u64,
|
||||
|
|
@ -1139,13 +1141,13 @@ pub struct LseekIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct LseekOut {
|
||||
pub offset: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct CopyFileRangeIn {
|
||||
pub fh_src: u64,
|
||||
pub off_src: u64,
|
||||
|
|
@ -1157,7 +1159,7 @@ pub struct CopyFileRangeIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct SetUpMappingIn {
|
||||
/* An already open handle */
|
||||
pub fh: u64,
|
||||
|
|
@ -1172,14 +1174,14 @@ pub struct SetUpMappingIn {
|
|||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct RemoveMappingIn {
|
||||
/* number of fuse_removemapping_one follows */
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct RemoveMappingOne {
|
||||
/* Offset into the dax window start the unmapping */
|
||||
pub moffset: u64,
|
||||
|
|
@ -1192,7 +1194,7 @@ pub struct RemoveMappingOne {
|
|||
/// will be followed by actual context label.
|
||||
/// fuse_secctx, name, context
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct Secctx {
|
||||
pub size: u32,
|
||||
pub padding: u32,
|
||||
|
|
@ -1202,7 +1204,7 @@ pub struct Secctx {
|
|||
/// sent and what's the total size of all security contexts (including
|
||||
/// size of fuse_secctx_header).
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Debug, Default, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
pub struct SecctxHeader {
|
||||
pub size: u32,
|
||||
pub nr_secctx: u32,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ thiserror = "1"
|
|||
cfg-if = "1"
|
||||
serde = { version = "1", features = [ "derive" ] }
|
||||
vm_control = { path = "../vm_control", features = ["gpu"] }
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
vulkano = { version = "0.31.1", optional = true }
|
||||
ash = { version = "0.37.0", optional = true }
|
||||
rand = { version = "0.8.5", optional = true }
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ use linux_input_sys::virtio_input_event;
|
|||
use linux_input_sys::InputEventDecoder;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::FromZeros;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
const EVENT_SIZE: usize = virtio_input_event::SIZE;
|
||||
const EVENT_BUFFER_LEN_MAX: usize = 64 * EVENT_SIZE;
|
||||
|
|
@ -150,7 +150,7 @@ impl EventDevice {
|
|||
|
||||
pub fn recv_event_encoded(&self) -> io::Result<virtio_input_event> {
|
||||
let mut event = virtio_input_event::new_zeroed();
|
||||
(&self.event_socket).read_exact(event.as_bytes_mut())?;
|
||||
(&self.event_socket).read_exact(event.as_mut_bytes())?;
|
||||
Ok(event)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ kvm_sys = { path = "../kvm_sys" }
|
|||
|
||||
[target.'cfg(target_arch = "x86_64")'.dev-dependencies]
|
||||
hypervisor_test_macro = { path = "hypervisor_test_macro" }
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
thiserror = "1"
|
||||
|
|
|
|||
|
|
@ -36,7 +36,10 @@ use vm_memory::GuestMemory;
|
|||
use windows::Win32::System::Memory::VirtualLock;
|
||||
#[cfg(windows)]
|
||||
use windows::Win32::System::Memory::VirtualUnlock;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
const FLAGS_IF_BIT: u64 = 0x200;
|
||||
|
||||
|
|
@ -49,7 +52,7 @@ pub enum HypervisorType {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(AsBytes)]
|
||||
#[derive(FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
/// Define IDTR value used in real mode or 32bit protected mode.
|
||||
struct Idtr32 {
|
||||
// The lower 2 bytes are limit.
|
||||
|
|
@ -59,7 +62,7 @@ struct Idtr32 {
|
|||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(AsBytes, Debug, Copy, Clone)]
|
||||
#[derive(Debug, Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
/// IDT entries for long mode.
|
||||
struct IdtEntry64 {
|
||||
address_low: u16,
|
||||
|
|
@ -503,7 +506,7 @@ impl ModeConfig {
|
|||
if long_mode && s == 0 {
|
||||
// 64 bit system segment descriptor.
|
||||
#[repr(C, packed)]
|
||||
#[derive(AsBytes)]
|
||||
#[derive(FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct Descriptor {
|
||||
limit_lo: u16,
|
||||
base_lo: u16,
|
||||
|
|
@ -529,7 +532,7 @@ impl ModeConfig {
|
|||
.to_owned()
|
||||
} else {
|
||||
#[repr(C, packed)]
|
||||
#[derive(AsBytes)]
|
||||
#[derive(FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
struct Descriptor {
|
||||
limit_lo: u16,
|
||||
base_lo: u16,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ once_cell = "1.7"
|
|||
serde = "1"
|
||||
serde_keyvalue = { path = "../serde_keyvalue", features = ["argh_derive"] }
|
||||
static_assertions = "1.1"
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
||||
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
|
||||
minijail = "*"
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ use once_cell::sync::Lazy;
|
|||
#[cfg(feature = "seccomp_trace")]
|
||||
use static_assertions::const_assert;
|
||||
#[cfg(feature = "seccomp_trace")]
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::Immutable;
|
||||
#[cfg(feature = "seccomp_trace")]
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
use crate::config::JailConfig;
|
||||
|
||||
|
|
@ -260,7 +262,7 @@ pub fn create_sandbox_minijail(
|
|||
#[cfg(feature = "seccomp_trace")]
|
||||
{
|
||||
#[repr(C)]
|
||||
#[derive(AsBytes)]
|
||||
#[derive(Immutable, IntoBytes)]
|
||||
struct sock_filter {
|
||||
/* Filter block */
|
||||
code: u16, /* Actual filter code */
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ remain = "0.2"
|
|||
resources = { path = "../resources" }
|
||||
thiserror = "1"
|
||||
vm_memory = { path = "../vm_memory" }
|
||||
zerocopy = { version = "0.7", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.13", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3"
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|||
source tools/impl/bindgen-common.sh
|
||||
|
||||
KERNEL_LOADER_EXTRA="// Added by kernel_loader/bindgen.sh
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;"
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;"
|
||||
|
||||
bindgen_generate \
|
||||
--raw-line "${KERNEL_LOADER_EXTRA}" \
|
||||
|
|
@ -25,10 +26,10 @@ bindgen_generate \
|
|||
--allowlist-type='Elf64_Ehdr' \
|
||||
--allowlist-type='Elf64_Phdr' \
|
||||
--allowlist-var='.+' \
|
||||
--with-derive-custom "elf32_hdr=FromZeroes,FromBytes,AsBytes" \
|
||||
--with-derive-custom "elf64_hdr=FromZeroes,FromBytes,AsBytes" \
|
||||
--with-derive-custom "elf32_phdr=FromZeroes,FromBytes,AsBytes" \
|
||||
--with-derive-custom "elf64_phdr=FromZeroes,FromBytes,AsBytes" \
|
||||
--with-derive-custom "elf32_hdr=FromBytes,Immutable,IntoBytes,KnownLayout" \
|
||||
--with-derive-custom "elf64_hdr=FromBytes,Immutable,IntoBytes,KnownLayout" \
|
||||
--with-derive-custom "elf32_phdr=FromBytes,Immutable,IntoBytes,KnownLayout" \
|
||||
--with-derive-custom "elf64_phdr=FromBytes,Immutable,IntoBytes,KnownLayout" \
|
||||
"${BINDGEN_LINUX}/include/uapi/linux/elf.h" \
|
||||
-- \
|
||||
-isystem "${BINDGEN_LINUX}/include" \
|
||||
|
|
|
|||
|
|
@ -23,15 +23,17 @@ use lz4_flex::frame::FrameDecoder as Lz4FrameDecoder;
|
|||
use resources::AddressRange;
|
||||
use vm_memory::GuestAddress;
|
||||
use vm_memory::GuestMemory;
|
||||
use zerocopy::AsBytes;
|
||||
use zerocopy::FromBytes;
|
||||
use zerocopy::FromZeroes;
|
||||
use zerocopy::FromZeros;
|
||||
use zerocopy::Immutable;
|
||||
use zerocopy::IntoBytes;
|
||||
use zerocopy::KnownLayout;
|
||||
|
||||
use crate::Error;
|
||||
use crate::LoadedKernel;
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Copy, Clone, AsBytes, FromZeroes, FromBytes)]
|
||||
#[derive(Copy, Clone, FromBytes, Immutable, IntoBytes, KnownLayout)]
|
||||
#[allow(unused)]
|
||||
#[repr(C)]
|
||||
struct Arm64ImageHeader {
|
||||
|
|
@ -92,7 +94,7 @@ where
|
|||
{
|
||||
let mut header = Arm64ImageHeader::new_zeroed();
|
||||
kernel_image
|
||||
.read_exact_at_volatile(VolatileSlice::new(header.as_bytes_mut()), 0)
|
||||
.read_exact_at_volatile(VolatileSlice::new(header.as_mut_bytes()), 0)
|
||||
.map_err(|_| Error::ReadHeader)?;
|
||||
let load_addr = header.parse_load_addr(kernel_start)?;
|
||||
|
||||
|
|
@ -125,7 +127,7 @@ fn load_arm64_kernel_from_reader<F: BufRead>(
|
|||
|
||||
// Read and parse the kernel header.
|
||||
kernel_image
|
||||
.read_exact(header.as_bytes_mut())
|
||||
.read_exact(header.as_mut_bytes())
|
||||
.map_err(|_| Error::ReadHeader)?;
|
||||
let load_addr = header.parse_load_addr(kernel_start)?;
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue