Crate memory

source ·
Expand description

This crate implements the main memory management subsystem for Theseus.

The primary type of interest is MappedPages, which offers a robust interface that unifies the usage of arbitrary memory regions with that of Rust’s safe type system and lifetimes.

Acknowledgments

Some of the internal page table management code was based on Philipp Oppermann’s blog_os, but has since changed significantly.

Macros

  • A macro for applying the same field/method accessors to all variants in an enum based on the three possible PageSizes.

Structs

  • Represents a range of allocated VirtualAddresses, specified in Pages.
  • A borrowed MappedPages object that derefs to &T and optionally also &mut T.
  • A borrowed MappedPages object that derefs to a slice &[T] and optionally also &mut [T].
  • The set of identity mappings that should be dropped before starting the first application.
  • A Frame is a chunk of physical memory aligned to a page boundary (default 4KiB) given by the P parameter.
  • A range of Frames that are contiguous in physical memory.
  • A marker type used to indicate that a BorrowedMappedPages or BorrowedSliceMappedPages is borrowed immutably.
  • Information returned after initialising the memory subsystem.
  • Represents a contiguous range of virtual memory pages that are currently mapped. A MappedPages object can only have a single range of contiguous pages, not multiple disjoint ranges. This does not guarantee that its pages are mapped to frames that are contiguous in physical memory.
  • This holds all the information for a Task’s memory mappings and address space (this is basically the equivalent of Linux’s mm_struct)
  • A marker type used to indicate that a BorrowedMappedPages or BorrowedSliceMappedPages is borrowed mutably.
  • A Page is a chunk of virtual memory aligned to a page boundary (default 4KiB) given by the P parameter.
  • Marker struct used to indicate a page size of 1GiB.
  • Marker struct used to indicate a page size of 2MiB.
  • Marker struct used to indicate the default page size of 4KiB.
  • A range of Pages that are contiguous in virtual memory.
  • A top-level root (P4) page table.
  • A physical memory address, which is a usize under the hood.
  • Common, architecture-independent flags for a page table entry (PTE) that define how a page is mapped.
  • Page table entry (PTE) flags on x86_64.
  • Page table entry (PTE) flags on x86_64.
  • A virtual memory address, which is a usize under the hood.

Enums

  • Possible options when requesting pages from the page allocator.
  • Enum used to indicate the size of a page or frame.
  • The possible states that a range of exclusively-owned pages or frames can be in.

Constants

  • Mapping flags that can be used to map DMA (Direct Memory Access) memory.
  • Mapping flags that can be used to map MMIO registers.
  • Page size is 4096 bytes, 4KiB pages.
  • A mask for the bits of a page table entry that contain the physical frame address.

Traits

Functions

  • Allocates the given number of frames with no constraints on the starting physical address.
  • Allocates the given number of frames starting at (inclusive of) the frame containing the given PhysicalAddress.
  • Allocates frames with no constraints on the starting physical address, with a size given by the number of bytes.
  • Allocates frames starting at the given PhysicalAddress with a size given in number of bytes.
  • Similar to allocated_frames_deferred(), but accepts a size value for the allocated frames in number of bytes instead of number of frames.
  • The core frame allocation routine that allocates the given number of physical frames, optionally at the requested starting PhysicalAddress.
  • Allocates the given number of pages with no constraints on the starting virtual address.
  • Allocates the given number of pages starting at (inclusive of) the page containing the given VirtualAddress.
  • Allocates pages with no constraints on the starting virtual address, with a size given by the number of bytes.
  • Allocates pages starting at the given VirtualAddress with a size given in number of bytes.
  • Similar to allocated_pages_deferred(), but accepts a size value for the allocated pages in number of bytes instead of number of pages.
  • Allocates pages with a size given in number of bytes with the constraint that they must be within the given inclusive range of pages.
  • The core page allocation routine that allocates the given number of virtual pages, optionally at the requested starting VirtualAddress.
  • Allocates the given number of pages with the constraint that they must be within the given inclusive range of pages.
  • A convenience function that creates a new memory mapping by allocating frames that are contiguous in physical memory. If contiguous frames are not required, then see create_mapping(). Returns a tuple containing the new MappedPages and the starting PhysicalAddress of the first frame, which is a convenient way to get the physical address without walking the page tables.
  • Creates an identity mapping at a random available virtual and physical address.
  • A convenience function that creates a new memory mapping. The pages allocated are contiguous in memory but there’s no guarantee that the frames they are mapped to are also contiguous in memory. If contiguous frames are required then see create_contiguous_mapping(). Returns the new MappedPages.
  • Returns a reference to the kernel’s MemoryManagementInfo, if initialized. If not, it returns None.
  • Initializes the virtual memory management system. Consumes the given BootInformation, because after the memory system is initialized, the original BootInformation will be unmapped and inaccessible.
  • Finishes initializing the memory management system after the heap is ready.
  • A convenience function that maps randomly-allocated pages to the given range of frames.
  • Set the function callback that will be invoked every time a TLB shootdown is necessary, i.e., during page table remapping and unmapping operations.
  • A convenience function to translate the given virtual address into a physical address using the currently-active page table.

Type Aliases

  • A type alias for Frames in the Allocated state.
  • A shareable reference to a MemoryManagementInfo struct wrapper in a lock.
  • A type alias for Frames in the Unmapped state.