diff --git a/Changelog.md b/Changelog.md index cc926ce0..d0281685 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ - `OffsetPageTable`'s `PageTableFrameMapping` implementation is now public as `PhysOffset`. - [make range types `!Copy`](https://github.com/rust-osdev/x86_64/pull/581) - To migrate, use `.clone()` if necessary. +- [make page types `repr(transparent)` and range types `repr(Rust)`](https://github.com/rust-osdev/x86_64/pull/584) # 0.15.4 – 2025-11-24 diff --git a/src/addr.rs b/src/addr.rs index bd6692e5..1ba01420 100644 --- a/src/addr.rs +++ b/src/addr.rs @@ -28,6 +28,10 @@ const ADDRESS_SPACE_SIZE: u64 = 0x1_0000_0000_0000; /// On `x86_64`, only the 48 lower bits of a virtual address can be used. The top 16 bits need /// to be copies of bit 47, i.e. the most significant bit. Addresses that fulfil this criterion /// are called “canonical”. This type guarantees that it always represents a canonical address. +/// +/// # Representation +/// +/// This struct has the same representation as a [`u64`]. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct VirtAddr(u64); @@ -41,6 +45,10 @@ pub struct VirtAddr(u64); /// /// On `x86_64`, only the 52 lower bits of a physical address can be used. The top 12 bits need /// to be zero. This type guarantees that it always represents a valid physical address. +/// +/// # Representation +/// +/// This struct has the same representation as a [`u64`]. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct PhysAddr(u64); diff --git a/src/structures/paging/frame.rs b/src/structures/paging/frame.rs index 2961e977..f512bb01 100644 --- a/src/structures/paging/frame.rs +++ b/src/structures/paging/frame.rs @@ -8,8 +8,12 @@ use core::marker::PhantomData; use core::ops::{Add, AddAssign, Sub, SubAssign}; /// A physical memory frame. +/// +/// # Representation +/// +/// This struct has the same representation as a [`u64`]. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[repr(C)] +#[repr(transparent)] pub struct PhysFrame { // TODO: Make private when our minimum supported stable Rust version is 1.61 pub(crate) start_address: PhysAddr, @@ -134,7 +138,6 @@ impl Sub> for PhysFrame { /// An range of physical memory frames, exclusive the upper bound. #[derive(Clone, PartialEq, Eq, Hash)] -#[repr(C)] pub struct PhysFrameRange { /// The start of the range, inclusive. pub start: PhysFrame, @@ -192,7 +195,6 @@ impl fmt::Debug for PhysFrameRange { /// An range of physical memory frames, inclusive the upper bound. #[derive(Clone, PartialEq, Eq, Hash)] -#[repr(C)] pub struct PhysFrameRangeInclusive { /// The start of the range, inclusive. pub start: PhysFrame, diff --git a/src/structures/paging/page.rs b/src/structures/paging/page.rs index d0e19b4c..75f26632 100644 --- a/src/structures/paging/page.rs +++ b/src/structures/paging/page.rs @@ -62,8 +62,12 @@ impl PageSize for Size1GiB { impl Sealed for super::Size1GiB {} /// A virtual memory page. +/// +/// # Representation +/// +/// This struct has the same representation as a [`u64`]. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[repr(C)] +#[repr(transparent)] pub struct Page { start_address: VirtAddr, size: PhantomData, @@ -326,7 +330,6 @@ impl Step for Page { /// A range of pages with exclusive upper bound. #[derive(Clone, PartialEq, Eq, Hash)] -#[repr(C)] pub struct PageRange { /// The start of the range, inclusive. pub start: Page, @@ -395,7 +398,6 @@ impl fmt::Debug for PageRange { /// A range of pages with inclusive upper bound. #[derive(Clone, PartialEq, Eq, Hash)] -#[repr(C)] pub struct PageRangeInclusive { /// The start of the range, inclusive. pub start: Page,