Skip to content

Commit

Permalink
Merge pull request #173 from rcore-os/addr_of
Browse files Browse the repository at this point in the history
Use &raw rather than addr_of macros
  • Loading branch information
qwandor authored Dec 6, 2024
2 parents b2eb08b + 8f37811 commit 3e40330
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
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 @@ -811,7 +811,7 @@ impl<'a, 'b> InputOutputIter<'a, 'b> {
}
}

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

0 comments on commit 3e40330

Please sign in to comment.