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

add from_slice to VirtAddr #442

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use crate::structures::paging::{PageOffset, PageTableIndex};
use bit_field::BitField;

const ADDRESS_SPACE_SIZE: u64 = 0x1_0000_0000_0000;

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

constant `ADDRESS_SPACE_SIZE` is never used

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

constant `ADDRESS_SPACE_SIZE` is never used

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

constant is never used: `ADDRESS_SPACE_SIZE`

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

constant is never used: `ADDRESS_SPACE_SIZE`

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

constant is never used: `ADDRESS_SPACE_SIZE`

Check warning on line 13 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

constant is never used: `ADDRESS_SPACE_SIZE`

/// A canonical 64-bit virtual memory address.
///
Expand Down Expand Up @@ -129,8 +129,8 @@
// doesn't truncate.
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
#[inline]
pub fn from_ptr<T>(ptr: *const T) -> Self {
Self::new(ptr as u64)
pub fn from_ptr<T: ?Sized>(ptr: *const T) -> Self {
Self::new(ptr as *const () as u64)
}

/// Converts the address to a raw pointer.
Expand Down Expand Up @@ -226,7 +226,7 @@
}

// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
pub(crate) fn steps_between_impl(start: &Self, end: &Self) -> Option<usize> {

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

associated functions `steps_between_impl` and `forward_checked_impl` are never used

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (nightly)

associated functions `steps_between_impl` and `forward_checked_impl` are never used

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `steps_between_impl`

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `steps_between_impl`

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `steps_between_impl`

Check warning on line 229 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `steps_between_impl`
let mut steps = end.0.checked_sub(start.0)?;

// Check if we jumped the gap.
Expand All @@ -238,7 +238,7 @@
}

// FIXME: Move this into the `Step` impl, once `Step` is stabilized.
pub(crate) fn forward_checked_impl(start: Self, count: usize) -> Option<Self> {

Check warning on line 241 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `forward_checked_impl`

Check warning on line 241 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.59)

associated function is never used: `forward_checked_impl`

Check warning on line 241 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `forward_checked_impl`

Check warning on line 241 in src/addr.rs

View workflow job for this annotation

GitHub Actions / Test MSRV and Stable Features (1.57)

associated function is never used: `forward_checked_impl`
let offset = u64::try_from(count).ok()?;
if offset > ADDRESS_SPACE_SIZE {
return None;
Expand Down Expand Up @@ -844,4 +844,11 @@
fn test_phys_addr_align_up_overflow() {
PhysAddr::new(0x000f_ffff_ffff_ffff).align_up(2u64);
}

#[test]
fn test_from_ptr_array() {
let slice = &[1, 2, 3, 4, 5];
// Make sure that from_ptr(slice) is the address of the first element
assert_eq!(VirtAddr::from_ptr(slice), VirtAddr::from_ptr(&slice[0]));
}
}