1
1
//! Abstractions for default-sized and huge virtual memory pages.
2
2
3
+ use crate :: sealed:: Sealed ;
3
4
use crate :: structures:: paging:: page_table:: PageTableLevel ;
4
5
use crate :: structures:: paging:: PageTableIndex ;
5
6
use crate :: VirtAddr ;
@@ -10,12 +11,9 @@ use core::marker::PhantomData;
10
11
use core:: ops:: { Add , AddAssign , Sub , SubAssign } ;
11
12
12
13
/// Trait for abstracting over the three possible page sizes on x86_64, 4KiB, 2MiB, 1GiB.
13
- pub trait PageSize : Copy + Eq + PartialOrd + Ord {
14
+ pub trait PageSize : Copy + Eq + PartialOrd + Ord + Sealed {
14
15
/// The page size in bytes.
15
16
const SIZE : u64 ;
16
-
17
- /// A string representation of the page size for debug output.
18
- const SIZE_AS_DEBUG_STR : & ' static str ;
19
17
}
20
18
21
19
/// This trait is implemented for 4KiB and 2MiB pages, but not for 1GiB pages.
@@ -37,21 +35,30 @@ pub enum Size1GiB {}
37
35
38
36
impl PageSize for Size4KiB {
39
37
const SIZE : u64 = 4096 ;
40
- const SIZE_AS_DEBUG_STR : & ' static str = "4KiB" ;
41
38
}
42
39
43
40
impl NotGiantPageSize for Size4KiB { }
44
41
42
+ impl Sealed for super :: Size4KiB {
43
+ const DEBUG_STR : & ' static str = "4KiB" ;
44
+ }
45
+
45
46
impl PageSize for Size2MiB {
46
47
const SIZE : u64 = Size4KiB :: SIZE * 512 ;
47
- const SIZE_AS_DEBUG_STR : & ' static str = "2MiB" ;
48
48
}
49
49
50
50
impl NotGiantPageSize for Size2MiB { }
51
51
52
+ impl Sealed for super :: Size2MiB {
53
+ const DEBUG_STR : & ' static str = "2MiB" ;
54
+ }
55
+
52
56
impl PageSize for Size1GiB {
53
57
const SIZE : u64 = Size2MiB :: SIZE * 512 ;
54
- const SIZE_AS_DEBUG_STR : & ' static str = "1GiB" ;
58
+ }
59
+
60
+ impl Sealed for super :: Size1GiB {
61
+ const DEBUG_STR : & ' static str = "1GiB" ;
55
62
}
56
63
57
64
/// A virtual memory page.
@@ -223,7 +230,7 @@ impl<S: PageSize> fmt::Debug for Page<S> {
223
230
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
224
231
f. write_fmt ( format_args ! (
225
232
"Page[{}]({:#x})" ,
226
- S :: SIZE_AS_DEBUG_STR ,
233
+ S :: DEBUG_STR ,
227
234
self . start_address( ) . as_u64( )
228
235
) )
229
236
}
0 commit comments