page_table/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Methods to construct page tables.
5
6#![cfg_attr(not(any(feature = "std", test)), no_std)]
7//TODO docs are missing on pub page table functions for aarch64
8#![expect(missing_docs)]
9#![forbid(unsafe_code)]
10
11pub mod aarch64;
12pub mod x64;
13
14use thiserror::Error;
15
16/// Errors returned by the Page Table Builder
17#[derive(Debug, PartialEq, Eq, Error)]
18pub enum Error {
19    /// The PageTableBuilder bytes buffer does not match the size of the struct buffer
20    #[error(
21        "PageTableBuilder bytes buffer size {bytes_buf} does not match the struct buffer size [{struct_buf}]"
22    )]
23    BadBufferSize { bytes_buf: usize, struct_buf: usize },
24
25    /// The constructed page tables are larger than the amount memory given for construction by the caller
26    #[error(
27        "constructed page tables are larger than the amount memory given for construction by the caller"
28    )]
29    NotEnoughMemory,
30
31    /// The page table builder mapping ranges are not sorted
32    #[error("the page table builder was invoked with unsorted mapping ranges")]
33    UnsortedMappings,
34
35    /// The page table builder was given an invalid range
36    #[error("page table builder range.end() < range.start()")]
37    InvalidRange,
38
39    /// The page table builder is generating overlapping mappings
40    #[error("the page table builder was invoked with overlapping mappings")]
41    OverlappingMappings,
42
43    /// The page table builder tried to overwrite a leaf mapping
44    #[error("the page table builder attempted to overwite a leaf mapping")]
45    AttemptedEntryOverwrite,
46}
47
48/// Size of the initial identity map
49#[derive(Debug, Copy, Clone)]
50pub enum IdentityMapSize {
51    /// Identity-map the bottom 4GB
52    Size4Gb,
53    /// Identity-map the bottom 8GB
54    Size8Gb,
55}