Skip to content

Commit

Permalink
Add {PhysFrame,Page}::from_start_address_unsafe.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Apr 11, 2020
1 parent 2442fd9 commit 10608a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/structures/paging/frame.rs
Expand Up @@ -26,6 +26,21 @@ impl<S: PageSize> PhysFrame<S> {
Ok(PhysFrame::containing_address(address))
}

const_fn! {
/// Returns the frame that starts at the given virtual address.
///
/// ## Safety
///
/// The address must be correctly aligned.
#[inline]
pub unsafe fn from_start_address_unsafe(start_address: PhysAddr) -> Self {
PhysFrame {
start_address,
size: PhantomData,
}
}
}

/// Returns the frame that contains the given physical address.
#[inline]
pub fn containing_address(address: PhysAddr) -> Self {
Expand Down
15 changes: 15 additions & 0 deletions src/structures/paging/page.rs
Expand Up @@ -75,6 +75,21 @@ impl<S: PageSize> Page<S> {
Ok(Page::containing_address(address))
}

const_fn! {
/// Returns the page that starts at the given virtual address.
///
/// ## Safety
///
/// The address must be correctly aligned.
#[inline]
pub unsafe fn from_start_address_unsafe(start_address: VirtAddr) -> Self {
Page {
start_address,
size: PhantomData,
}
}
}

/// Returns the page that contains the given virtual address.
#[inline]
pub fn containing_address(address: VirtAddr) -> Self {
Expand Down

0 comments on commit 10608a3

Please sign in to comment.