Pde

Struct Pde 

Source
#[repr(transparent)]
pub struct Pde(pub usize);
Expand description

Page Directory Entry (PDE).

This struct represents a Page Directory Entry (PDE), entry of third-level table, in the 4-level page table system for x86_64 architecture. A page directory entry typically holds the information about the physical address of a page directory or a page table, along with various flags. In a paging system, a PDE points to a page table, which in turn contains the actual page table entries (PTEs) that map virtual addresses to physical addresses.

The Pde struct in this code provides access to these fields and operations on them. Each entry corresponds to a page directory in the virtual memory hierarchy and is used by the kernel to map higher-level virtual addresses to lower-level page table entries.

Tuple Fields§

§0: usize

Implementations§

Source§

impl Pde

Source

pub const fn pa(&self) -> Option<Pa>

Get the physical address pointed to by this entry.

This function checks whether the page directory entry is present (i.e., if the “P” flag is set in the entry). If the page directory entry is present, it extracts the physical address by clearing the flags from the entry.

§Returns
  • Some(Pa) if the page directory entry is present, containing the physical address.
  • None if the page directory entry is not present (i.e., the “P” flag is not set).
Source

pub const fn flags(&self) -> PdeFlags

Get the flags associated with this entry.

This function extracts the flags from the page directory entry, which may indicate whether the page directory is present, writable, user-accessible, etc.

§Returns

A PdeFlags value representing the flags associated with this entry.

Source

pub fn set_pa(&mut self, pa: Pa) -> Result<&mut Self, PageTableMappingError>

Set the physical address for this entry.

This method updates the physical address of the page directory entry while preserving the current flags (e.g., read/write permissions). It checks that the provided physical address is aligned to a 4K boundary (the page size), as required by the architecture.

§Parameters
  • pa: The new physical address to set for the entry.
§Returns
  • Ok(&mut Self) if the address is valid and the update is successful.
  • Err(PageTableMappingError::Unaligned) if the provided physical address is not aligned.
§Warning

This operation does not modify the flags of the entry.

Source

pub fn set_flags(&mut self, perm: PdeFlags) -> &mut Self

Set the flags for this entry.

This method allows you to update the flags associated with the page directory entry without modifying the physical address. It combines the current physical address with the new flags and sets the updated value back into the entry.

§Parameters
  • perm: The new set of flags to assign to the entry.
§Returns

A mutable reference to self, allowing for method chaining.

Source

pub fn clear(&mut self) -> Option<Pa>

Clears the entry.

This method removes any previously set physical address and flags from the entry. If the entry contained a valid physical address before being cleared, that address is returned.

§Returns
  • Some(Pa): The physical address that was previously stored in the entry, if it existed.
  • None: If the entry did not contain a valid physical address.
Source

pub fn into_pt_mut(&mut self) -> Result<&mut [Pte], PageTableMappingError>

Get a mutable reference to the page table pointed to by this entry.

This method retrieves a mutable reference to the page table that this page directory entry points to, assuming that the entry is present (i.e., the “P” flag is set).

§Returns
  • Ok(&mut [Pte]) if the page table is valid, represented as a mutable slice of Pte (page table entries).
  • Err(PageTableMappingError::NotExist) if the page directory entry is not present or invalid.
§Safety

This operation assumes that the physical address of the page table is valid and properly aligned.

Source

pub fn into_pt(&self) -> Result<&[Pte], PageTableMappingError>

Get a reference to the page table pointed to by this entry.

This method retrieves an immutable reference to the page table that this page directory entry points to, assuming that the entry is present (i.e., the “P” flag is set).

§Returns
  • Ok(&[Pte]) if the page table is valid, represented as an immutable slice of Pte (page table entries).
  • Err(PageTableMappingError::NotExist) if the page directory entry is not present or invalid.
§Safety

This operation assumes that the physical address of the page table is valid and properly aligned.

Trait Implementations§

Source§

impl Clone for Pde

Source§

fn clone(&self) -> Pde

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Pde

Auto Trait Implementations§

§

impl Freeze for Pde

§

impl RefUnwindSafe for Pde

§

impl Send for Pde

§

impl Sync for Pde

§

impl Unpin for Pde

§

impl UnwindSafe for Pde

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.