Skip to content

Commit

Permalink
prevent address construction without new, so that platform guarantees…
Browse files Browse the repository at this point in the history
… can be enforced

fixes #4
  • Loading branch information
jounathaen committed Oct 30, 2024
1 parent aa69d5e commit 409f282
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use align_address::Align;
/// that are not encoded in this type.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct VirtAddr(pub u64);
pub struct VirtAddr(u64);

impl_address!(VirtAddr, u64);

Expand Down Expand Up @@ -126,7 +126,7 @@ impl From<usize> for PhysAddr {
/// not larger than 56 bits. This type enforces this limit.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct PhysAddr(pub u64);
pub struct PhysAddr(u64);

impl_address!(PhysAddr, u64);

Expand Down
4 changes: 2 additions & 2 deletions src/arch/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use align_address::Align;
/// A virtual memory address.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct VirtAddr(pub usize);
pub struct VirtAddr(usize);

impl_address!(VirtAddr, usize);

/// A physical memory address.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct PhysAddr(pub usize);
pub struct PhysAddr(usize);

impl_address!(PhysAddr, usize);

Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use x86_64::structures::paging::{PageOffset, PageTableIndex};
/// are called “canonical”. This type guarantees that it always represents a canonical address.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct VirtAddr(pub u64);
pub struct VirtAddr(u64);

impl_address!(VirtAddr, u64);

Expand All @@ -37,7 +37,7 @@ impl_address!(VirtAddr, u64);
/// to be zero. This type guarantees that it always represents a valid physical address.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct PhysAddr(pub u64);
pub struct PhysAddr(u64);

impl_address!(PhysAddr, u64);

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ mod tests {

#[test]
pub fn virtaddr_new_truncate() {
assert_eq!(VirtAddr::new_truncate(0), VirtAddr(0));
assert_eq!(VirtAddr::new_truncate(123), VirtAddr(123));
assert_eq!(VirtAddr::new_truncate(0), VirtAddr::new(0));
assert_eq!(VirtAddr::new_truncate(123), VirtAddr::new(123));
}

#[test]
Expand Down

0 comments on commit 409f282

Please sign in to comment.