Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use &raw rather than addr_of macros #173

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn align_up(size: usize) -> usize {

/// The number of pages required to store `size` bytes, rounded up to a whole number of pages.
fn pages(size: usize) -> usize {
(size + PAGE_SIZE - 1) / PAGE_SIZE
size.div_ceil(PAGE_SIZE)
}

// TODO: Use NonNull::slice_from_raw_parts once it is stable.
Expand Down
2 changes: 1 addition & 1 deletion src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
pub fn new<T: Transport>(
transport: &mut T,
idx: u16,
indirect: bool,

Check warning on line 80 in src/queue.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `indirect`

Check warning on line 80 in src/queue.rs

View workflow job for this annotation

GitHub Actions / build

unused variable: `indirect`
event_idx: bool,
) -> Result<Self> {
#[allow(clippy::let_unit_value)]
Expand Down Expand Up @@ -811,7 +811,7 @@
}
}

impl<'a, 'b> Iterator for InputOutputIter<'a, 'b> {
impl Iterator for InputOutputIter<'_, '_> {
type Item = (NonNull<[u8]>, BufferDirection);

fn next(&mut self) -> Option<Self::Item> {
Expand Down
9 changes: 9 additions & 0 deletions src/transport/fake.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! A fake implementation of `Transport` for unit tests.

use super::{DeviceStatus, DeviceType, Transport};
use crate::{
queue::{fake_read_write_queue, Descriptor},
Expand Down Expand Up @@ -173,6 +175,7 @@ impl<C> Debug for State<C> {
}

impl<C> State<C> {
/// Creates a state for a fake transport, with the given queues and VirtIO configuration space.
pub const fn new(queues: Vec<QueueStatus>, config_space: C) -> Self {
Self {
status: DeviceStatus::empty(),
Expand Down Expand Up @@ -266,11 +269,17 @@ impl<C> State<C> {
}
}

/// The status of a fake virtqueue.
#[derive(Debug, Default)]
pub struct QueueStatus {
/// The size of the fake virtqueue.
pub size: u32,
/// The physical address set for the queue's descriptors.
pub descriptors: PhysAddr,
/// The physical address set for the queue's driver area.
pub driver_area: PhysAddr,
/// The physical address set for the queue's device area.
pub device_area: PhysAddr,
/// Whether the queue has been notified by the driver since last we checked.
pub notified: AtomicBool,
}
4 changes: 2 additions & 2 deletions src/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
};
use core::{
mem::{align_of, size_of},
ptr::{addr_of_mut, NonNull},
ptr::NonNull,
};
use zerocopy::{FromBytes, Immutable, IntoBytes};

Expand Down Expand Up @@ -256,7 +256,7 @@ impl Transport for PciTransport {

let offset_bytes = usize::from(queue_notify_off) * self.notify_off_multiplier as usize;
let index = offset_bytes / size_of::<u16>();
addr_of_mut!((*self.notify_region.as_ptr())[index]).vwrite(queue);
(&raw mut (*self.notify_region.as_ptr())[index]).vwrite(queue);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/transport/pci/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ pub struct CapabilityIterator<'a, C: ConfigurationAccess> {
next_capability_offset: Option<u8>,
}

impl<'a, C: ConfigurationAccess> Iterator for CapabilityIterator<'a, C> {
impl<C: ConfigurationAccess> Iterator for CapabilityIterator<'_, C> {
type Item = CapabilityInfo;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
7 changes: 2 additions & 5 deletions src/volatile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<T: Copy> VolatileWritable<T> for *mut Volatile<T> {
/// ```
macro_rules! volread {
($nonnull:expr, $field:ident) => {
$crate::volatile::VolatileReadable::vread(core::ptr::addr_of!((*$nonnull.as_ptr()).$field))
$crate::volatile::VolatileReadable::vread((&raw const (*$nonnull.as_ptr()).$field))
};
}

Expand All @@ -97,10 +97,7 @@ macro_rules! volread {
/// ```
macro_rules! volwrite {
($nonnull:expr, $field:ident, $value:expr) => {
$crate::volatile::VolatileWritable::vwrite(
core::ptr::addr_of_mut!((*$nonnull.as_ptr()).$field),
$value,
)
$crate::volatile::VolatileWritable::vwrite((&raw mut (*$nonnull.as_ptr()).$field), $value)
};
}

Expand Down
Loading