Skip to content

Commit 7d9cbcf

Browse files
committed
docs: add repr guarantees for address types, pages, and frames
1 parent 0561548 commit 7d9cbcf

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/addr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const ADDRESS_SPACE_SIZE: u64 = 0x1_0000_0000_0000;
2828
/// On `x86_64`, only the 48 lower bits of a virtual address can be used. The top 16 bits need
2929
/// to be copies of bit 47, i.e. the most significant bit. Addresses that fulfil this criterion
3030
/// are called “canonical”. This type guarantees that it always represents a canonical address.
31+
///
32+
/// # Representation
33+
///
34+
/// This struct has the same representation as a [`u64`].
3135
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3236
#[repr(transparent)]
3337
pub struct VirtAddr(u64);
@@ -41,6 +45,10 @@ pub struct VirtAddr(u64);
4145
///
4246
/// On `x86_64`, only the 52 lower bits of a physical address can be used. The top 12 bits need
4347
/// to be zero. This type guarantees that it always represents a valid physical address.
48+
///
49+
/// # Representation
50+
///
51+
/// This struct has the same representation as a [`u64`].
4452
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4553
#[repr(transparent)]
4654
pub struct PhysAddr(u64);

src/structures/paging/frame.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ use core::marker::PhantomData;
88
use core::ops::{Add, AddAssign, Sub, SubAssign};
99

1010
/// A physical memory frame.
11+
///
12+
/// # Representation
13+
///
14+
/// This struct has the same representation as a [`u64`].
1115
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1216
#[repr(transparent)]
1317
pub struct PhysFrame<S: PageSize = Size4KiB> {

src/structures/paging/page.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ impl PageSize for Size1GiB {
6262
impl Sealed for super::Size1GiB {}
6363

6464
/// A virtual memory page.
65+
///
66+
/// # Representation
67+
///
68+
/// This struct has the same representation as a [`u64`].
6569
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6670
#[repr(transparent)]
6771
pub struct Page<S: PageSize = Size4KiB> {

0 commit comments

Comments
 (0)