#[repr(transparent)]pub struct Pte(pub usize);Expand description
Page Table Entry (PTE).
This struct represents a Page Table Entry (PTE), the entry of last-level table, in the 4-level page table system for x86_64 architecture. A page table entry typically holds the information about the physical address of a page and various control bits, such as flags indicating whether the page is present, read/write, etc.
The Pte struct in this code provides access to these fields and
operations on them. Each entry corresponds to a single page in memory and is
used by the kernel to map virtual addresses to physical addresses in the
page table.
Tuple Fields§
§0: usizeImplementations§
Source§impl Pte
impl Pte
Sourcepub const fn pa(&self) -> Option<Pa>
pub const fn pa(&self) -> Option<Pa>
Get the physical address pointed to by this entry.
This function checks whether the page is present (i.e., if the “P” flag is set in the entry). If the page is present, it extracts the physical address from the entry by clearing the flags bits.
§Returns
Some(Pa)if the page is present, containing the physical address.Noneif the page is not present (i.e., the “P” flag is not set).
Sourcepub const fn flags(&self) -> PteFlags
pub const fn flags(&self) -> PteFlags
Get the flags associated with this page table entry.
This function extracts the flags from the entry. The flags represent various properties of the page, such as whether the page is present, read-only, user-accessible, etc.
§Returns
A PteFlags value representing the flags associated with this entry.
Sourcepub fn set_pa(&mut self, pa: Pa) -> Result<&mut Self, PageTableMappingError>
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 entry, preserving the current flags (e.g., read/write permissions). It checks that the physical address is aligned to a 4K boundary (the page size), as required by the architecture.
§Safety
You must invalidate the corresponding TLB Entry.
§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.
Sourcepub unsafe fn set_flags(&mut self, perm: PteFlags) -> &mut Self
pub unsafe fn set_flags(&mut self, perm: PteFlags) -> &mut Self
Set the flags for this entry.
This method allows you to update the flags associated with the page. The physical address remains unchanged, but the permission settings (e.g., read/write, user/kernel) can be updated.
§Parameters
perm: The new set of flags to assign to the entry.
§Returns
A mutable reference to self, allowing for method chaining.
§Safety
You must invalidate the corresponding TLB Entry.
Sourcepub unsafe fn clear(&mut self) -> Option<Pa>
pub unsafe 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.
§Safety
You must invalidate the corresponding TLB Entry.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Pte
impl RefUnwindSafe for Pte
impl Send for Pte
impl Sync for Pte
impl Unpin for Pte
impl UnwindSafe for Pte
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)