[−][src]Trait sunrise_kernel::paging::hierarchical_table::InactiveHierarchyTrait
A trait implemented by inactive table hierarchies.
Extends the TableHierarchy trait by adding functions to switch to this hierarchy, when process-switching.
Drop
When a process dies, the InactiveHierarchy stored in its ProcessMemory is dropped. The pages used by this process have already been freed by the bookkeeping, but the implementer of this trait is responsible for freeing the tables owned by this hierarchy.
However, it must not free the tables pointing to KernelLand memory, as they are shared with other processes, and are still in use.
Required methods
fn new() -> Self
Creates a hierarchy. Allocates at least a top level directory, makes all its entries unmapped, and makes its last entry recursive.
fn switch_to(&mut self)
Switches to this hierarchy.
Since all process are supposed to have the same view of kernelspace, this function will copy the part of the active directory that is mapping kernel space tables to the directory being switched to, and then performs the switch.
fn copy_active_kernel_space(&mut self)
Performs a shallow copy of the top level-directory section that maps KernelLand tables.
Used when about to switch to a hierarchy, to update it before switching to it.
fn is_currently_active(&self) -> bool
Checks if this inactive hierarchy is actually the currently active one.
Generally this means comparing the current MMU register pointer to top-level table with the address of the top-level table of this hierarchy.
unsafe fn from_currently_active() -> Self
Returns the currently active hierarchy as an inactive hierarchy.
Used only when becoming the first process to get a hold on the page tables created by the bootstrap before us, so we can free them.
Dropping it will not free the pages owned by this InactiveHierarchy. This is fine, because they used to belong to the bootstrap, and are already considered free by the FrameAllocator, so we must leak them.
However, it will free the tables (including directory) of this InactiveHierarchy,
except the ones mapping KernelLand memory, as for any other regular process.
These frames were marked as occupied when initialising the FrameAllocator
,
we're making them available again.
Safety
Having multiple InactiveHierarchy pointing to the same table hierarchy is unsafe. Should not be used for any other purpose, it is only guaranteed to be safe to drop.
Make sure you switch to a new table hierarchy before dropping it.